Java · Oracle ADF · Oracle Webcenter · Technology

Setup ADF Session UserData in Application Module’s Prepare Session – HowTo


Here’s a useful bit of code that uses the information in the security context and populate the ADF App Module Session’s user data. This snippet is used in your ADF Fusion project’s Application Module’s “prepareSession” method, as shown below, and it uses the “session.getUserData()”  to get a handle to the session to populate the user info.

Here’s the code:

    protected void prepareSession(Session session) {
        .....
        .... 
        java.security.AccessControlContext context = java.security.AccessController.getContext();
        javax.security.auth.Subject subject = javax.security.auth.Subject.getSubject(context);

        if (subject != null && subject.getPrincipals() != null) {
            Iterator iteratorOverPrincipals =  subject.getPrincipals().iterator();
            String user = null;
            if (iteratorOverPrincipals.hasNext())  
                user = ((Principal)iteratorOverPrincipals.next()).getName();
         
            if (user != null)  
                log.log(Level.INFO, "PrepareSession:" + user);
        
            Hashtable userData = session.getUserData();
            userData.put(UserSession.USER_SESSION_KEY, new UserSession(user));
        } else {
            Hashtable userData = session.getUserData();
            userData.put(UserSession.USER_SESSION_KEY, new UserSession(null));
            ....
            ...
        }
      ....
      ....
    }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s