Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
5 replies Latest Post - ‏2012-09-17T02:01:19Z by SystemAdmin
SystemAdmin
SystemAdmin
2327 Posts
ACCEPTED ANSWER

Pinned topic How to Access UserIdentity in MyCustomAuthenticator.changeResponseOnSuccess

‏2012-09-13T17:36:21Z |
The getRequestToProceed(HttpServletRequest request, HttpServletResponse response, UserIdentity userIdentity) is deprecated since Worklight V5.0.0.3. But how to access UserIdentity in new API changeResponseOnSuccess(HttpServletRequest request, HttpServletResponse response)?

I need to construct new response but the updated information is in UserIdentity's customAttributes. Please help.
  • christianIBM
    christianIBM
    78 Posts
    ACCEPTED ANSWER

    Re: How to Access UserIdentity in MyCustomAuthenticator.changeResponseOnSuccess

    ‏2012-09-13T19:00:05Z  in response to SystemAdmin
    To get User Identity custom attributes you can use : WL.Server.getActiveUser().attributes;
    -Worklight Development Team, iOS-Christian Linares
    • SystemAdmin
      SystemAdmin
      2327 Posts
      ACCEPTED ANSWER

      Re: How to Access UserIdentity in MyCustomAuthenticator.changeResponseOnSuccess

      ‏2012-09-13T19:21:24Z  in response to christianIBM
      You could not use JavaScript APIs (such as WL.Server.getActiveUser().attributes) in Java code. MyCustomAuthenticator is a Java class. This is original from MyCustomAuthticator.java:

      @Override
      public boolean changeResponseOnSuccess(HttpServletRequest request, HttpServletResponse response) throws IOException {
      if (request.getRequestURI().contains("my_custom_auth_request_url")){
      response.setContentType("application/json; charset=UTF-8");
      response.setHeader("Cache-Control", "no-cache, must-revalidate");
      response.getWriter().print("{\"authStatus\":\"complete\"}");
      return true;
      }
      return false;
      }

      Jerry
      • SystemAdmin
        SystemAdmin
        2327 Posts
        ACCEPTED ANSWER

        Re: How to Access UserIdentity in MyCustomAuthenticator.changeResponseOnSuccess

        ‏2012-09-14T15:36:38Z  in response to SystemAdmin
        Context:
        • Security data are passed in through HTTP request header. Don't find a way access them in adapter. But in Custom Authenticator and Login Module of Module_22_-_Custom_Authenticator_and_Login_Module.pdf we could access them in processRequest(
        final HttpServletRequest request,
        final HttpServletResponse response,
        final boolean isAccessToProtectedResource) throws IOException,
        ServletException;
        • For multiple steps authentication, before fixpack 5.0.0.3, could use getRequestToProceed(
        final HttpServletRequest request,
        final HttpServletResponse response, final UserIdentity userIdentity)
        throws IOException; to access userIdentity object and add data to the response after the authentication is successful

        Problem:
        • getRequestToProceed is deprecated and in 5.0.0.3 it is not invoked after the Login Module successfully validates the credentials collected by an authenticator
        • New API public boolean changeResponseOnSuccess(final HttpServletRequest request,
        final HttpServletResponse response) throws IOException; doesn't expose a way to access userIdentity object.

        Question:
        How to access userIdentity object in Custom Authenticator? Especially in changeResponseOnSuccess?

        Any help is appreciated!

        Jerry
        • MrWidget
          MrWidget
          8 Posts
          ACCEPTED ANSWER

          Re: How to Access UserIdentity in MyCustomAuthenticator.changeResponseOnSuccess

          ‏2012-09-16T07:25:16Z  in response to SystemAdmin
          The following technique can be used to to access the user identity from the authenticator. In the implementation of WorklightAuthenticator.getAuthenticationData() add the authenticator instance (this) to the returned table. This will allow the login module to pass the user identity to the authenticator as shown in an example below:

          public class MyLoginModule implements WorklightLoginModule {
          private MyAuthenticator authenticator;

          boolean login(Map<String, Object> authenticationData) {
          authenticator = (MyAuthenticator) authenticationData.get("myAuthenticator");
          ...
          }

          UserIdentity createIdenity(String realm) {
          UserIdentity identity = ....
          authenticator.setUser(identity);
          return identity;
          }
          }
          • SystemAdmin
            SystemAdmin
            2327 Posts
            ACCEPTED ANSWER

            Re: How to Access UserIdentity in MyCustomAuthenticator.changeResponseOnSuccess

            ‏2012-09-17T02:01:19Z  in response to MrWidget
            Looks great to solve authenticate successfully problem. Thanks!

            Jerry