7 Replies Latest reply: Nov 19, 2012 2:46 PM by 926363 RSS

    want to refer user first name and lastname in OIM notification template

    926363
      Hello OIM experts, can you please help me. I want to add user first name and last name and other attributes into the standard notifiation template.

      Currently I can only see $$userLogin, $password. When I add $lastName, $firstName it is coming blank.

      No idea. Can you please guide me about how to insert user's first name, last name and if possible other attributes in the standard template. Acutally I am under the impression that basic user information should be available out of box in the standard template. For example, Reset Password template is showing $firstName and $lastName but they are not added in "Forgotten Username Notification" template. So, I thought I just have to refer these attributes in the "Forgotten username Notification" template. How will achieve this without adding much effort ?

      thank you. Appreciate your time.

      Edited by: 923360 on Nov 19, 2012 8:27 AM
        • 1. Re: want to refer user first name and lastname in OIM notification template
          Kevin Pinsky
          Default data is only available when coded for it. If there is not a drop down labeled as "Available Data", then it won't contain the whole set of values. If you decompile the oimclient.jar file, the following code is used for the Forgotten Username Notification:

          >
          package oracle.iam.selfservice.notification;

          import java.util.ArrayList;
          import java.util.HashMap;
          import java.util.List;
          import java.util.Map;
          import oracle.iam.identity.usermgmt.api.UserManagerConstants.AttributeName;
          import oracle.iam.notification.impl.NotificationEventResolver;
          import oracle.iam.notification.vo.NotificationAttribute;
          import oracle.iam.platform.utils.OIMEnv;

          public class ForgottenUsernameResolver
          implements NotificationEventResolver
          {
          public List<NotificationAttribute> getAvailableData(String eventType, Map<String, Object> params)
          throws Exception
          {
          return new ArrayList();
          }

          public HashMap<String, Object> getReplacedData(String eventType, Map<String, Object> params) throws Exception
          {
          HashMap resolvedData = new HashMap();

          resolvedData.put("tenantName", "");
          if (OIMEnv.isMTFriendly()) {
          String tenantName = (String)params.get(UserManagerConstants.AttributeName.TENANT_NAME.getId());
          if (tenantName != null) {
          resolvedData.put("tenantName", tenantName);
          }
          }

          List userLoginList = (List)params.get("userLoginId");
          if ((userLoginList != null) && (userLoginList.size() == 1)) {
          String userLoginId = String.valueOf(userLoginList.get(0));
          resolvedData.put("userLoginId", userLoginId);
          }
          else
          {
          String userLoginCsv = String.valueOf(userLoginList);
          if (userLoginCsv.startsWith("[")) {
          userLoginCsv = userLoginCsv.substring(1);
          }
          if (userLoginCsv.endsWith("]")) {
          int len = userLoginCsv.length();
          userLoginCsv = userLoginCsv.substring(0, len - 1);
          }
          resolvedData.put("userLoginId", userLoginCsv);
          }

          return resolvedData;
          }
          }
          >

          Your only option to include more values is to write your own resolver class and update the xml file located in the mds repository here /metadata/iam-features-selfservice/notification/ForgottenUsername.xml. In your code, you will use the same input listed above in the code, but from there, you can return any attributes you want back into the resolvedData hash.

          -Kevin
          • 2. Re: want to refer user first name and lastname in OIM notification template
            926363
            Thank you Kevin. What I understood is, I can take same code mentioned above and first name and last name to the resolvedData. I am naming my custom class as :

            public class CustomForgottenUsernameResolver implements NotificationEventResolver

            Now, I am not sure how to retrive first name and last name from the parameter Map<String, Object> params. Is it like this ?

            String firstName=params.get("firstName");

            resolvedData.put("firstName", firstName);


            Sorry if my code did not make any sense. Appreciate if you can help me.

            thanks

            Edited by: 923360 on Nov 19, 2012 10:17 AM
            • 3. Re: want to refer user first name and lastname in OIM notification template
              Kevin Pinsky
              Your first step can be this code:

              System.out.println("Parameters:" + params);

              This will output everything that is provided into the resolver class. It looks like there will at least be "userLoginId" which is the user login. Here is a link to a blog about notifications in 11g: http://fusionsecurity.blogspot.com/2011/07/oim-11g-notifications.html I will use that code as the example of what should be in your function. It takes the user login, and then searches for the user and returns the entire user's attributes back into the data. You could limit if you want and only retrieve the attributes you want and then return them as well. Whatever values you populate back into the hash that is returned, you use that value with a $ before it to resolve it in the notification body:

              >
              HashMap<String, Object> resolvedNotificationData = new HashMap<String, Object>();
              UserManager usrMgr = Platform.getService(UserManager.class);

              //getting the notfication parameter
              String userLogin = (String) eventParams.get("userLoginId");
              // Mapping token with their actual value for user attributes.
              if (userLogin != null) {

              NotificationService notificationService = Platform.getService(NotificationService.class);
              //getting the list of all possible notification attributes
              List<NotificationAttribute> notificationAttributes = notificationService.getStaticData(eventType);

              //seting the attributes for user search based on the notification attributes
              Set<String> userRetAttrs = new HashSet<String>();
              for (NotificationAttribute notificationAttribute : notificationAttributes.get(0).getSubtree()) {
              userRetAttrs.add(notificationAttribute.getName());
              }

              //searching the user
              Identity user = usrMgr.getDetails(userLogin, userRetAttrs ,true);
              HashMap<String, Object> userAttributes = user.getAttributes();

              //setting the values in the resolved notification data Map
              String key = null;
              for (Map.Entry<String, Object> entry : userAttributes.entrySet()) {

              key = entry.getKey();

              if (key != null) {
              if ((entry.getValue() instanceof java.util.Map) && (key.equalsIgnoreCase(""))) {
              key = key.replace(' ', '_');
              resolvedNotificationData.put(key, ((HashMap)entry.getValue()).get(""));
              }
              else {
              key = key.replace(' ', '_');
              resolvedNotificationData.put(key, entry.getValue());
              }
              }
              }
              }
              //returning the resolved data with all user information
              return resolvedNotificationData;
              >

              -Kevin
              • 4. Re: want to refer user first name and lastname in OIM notification template
                926363
                Thanks a lot Kevin. Let me go ahead and try this out. I may need you help later...

                thanks again. Appreciate your time.
                • 5. Re: want to refer user first name and lastname in OIM notification template
                  926363
                  Hi Kevin, I have my custom class CustomForgottenUsernameResolver ready. It implements NotificationEventResolver.

                  Where will I put this class ? Should I make as zip and put it under ..../server/plugins ?



                  Here is my ForgottenUsername.xml . Can you please let me know if anything is mentioned incorrectly:

                  ?xml version='1.0' encoding='UTF-8'?>
                  <Events xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../notification/metadata/NotificationEvent.xsd" xmlns="http://xmlns.oracle.com/oim/notificationevent">
                  <EventType name="ForgottenUsername">
                  <Resolver class="com.myproject.notification.*CustomForgottenUsernameResolver*">
                  <Param Name="ForgottenUsername" DataType="X2-Entity" EntityName="ForgottenUsername"/>
                  </Resolver>
                  </EventType>
                  </Events>

                  thank you.
                  • 6. Re: want to refer user first name and lastname in OIM notification template
                    Kevin Pinsky
                    Change this:

                    <Resolver class="com.myproject.notification.CustomForgottenUsernameResolver">
                    <Param Name="ForgottenUsername" DataType="X2-Entity" EntityName="ForgottenUsername"/>
                    </Resolver>

                    To this:

                    <Resolver class="com.myproject.notification.CustomForgottenUsernameResolver"/>

                    -Kevin
                    • 7. Re: want to refer user first name and lastname in OIM notification template
                      926363
                      thank you. can you please tell me where should I keep my custom resolver class. I have written now plugin xml and will proceed with zip file containing the jar for my custom class.


                      thank you.

                      Edited by: 923360 on Nov 19, 2012 12:45 PM