3 Replies Latest reply on Mar 30, 2012 10:05 PM by 452071

    Getting custom property of User

    Tapas Bose
      In my application I have few custom property of the user. In the documentation, there is an example to extract all properties.

      So what I did is:

      JpsContext jpsCtx = JpsContextFactory.getContextFactory().getContext();
      IdentityStoreService service = jpsCtx.getServiceInstance(IdentityStoreService.class);
      String authUserName = secCntx.getUserName();
      IdentityStore idStore = service.getIdmStore();
      List<User> users = new ArrayList<User>();
      SimpleSearchFilter ssfilter = idStore.getSimpleSearchFilter("cn",SimpleSearchFilter.TYPE_EQUAL,authUserName);
      SearchParameters sp = new SearchParameters(ssfilter,SearchParameters.SEARCH_USERS_ONLY);
      sp.setCountLimit(SEARCH_COUNT_LIMIT);
      sp.setTimeLimit(SEARCH_TIME_LIMIT_MS);
      SearchResponse sr = idStore.searchUsers(sp);
      while (sr.hasNext()) {
           User user = (User) sr.next();
           users.add(user);
      }
      User authUser = users.get(0);
      UserProfile authUserProfile = authUser.getUserProfile();
      List list = idStore.getUserPropertyNames();
      String[] proparr = (String[])list.toArray(new String[list.size()]);
      PropertySet pset = userProfile.getProperties(proparr);
      Iterator itr = pset.getAll();
      while(itr.hasNext()) {
           Property prop = (Property)itr.next();
           System.out.println(prop.getName());
      }

      Now I am getting:
      // Output
      ////////////////////////////////////////////
      // DISPLAY_NAME
      // NAME
      // USER_ID
      // ORGANIZATIONAL_UNIT
      // BUSINESS_PHONE
      // BUSINESS_STREET
      // LAST_NAME
      // MANAGER
      // FIRST_NAME
      // ORGANIZATION
      // USER_NAME
      // BUSINESS_EMAIL
      // BUSINESS_POSTAL_CODE
      // BUSINESS_CITY
      // PASSWORD
      // DEPARTMENT
      // BUSINESS_PAGER
      // BUSINESS_STATE
      // BUSINESS_FAX

      But I also have custom property like ASSISTANT.

      How can I get that property and its value?

      Regards.