Search code examples
oracle-adfweblogic12c

Getting users and groups form WLS to Custom Page


I have configured users and groups in security realm using SQL Authenticator in WLS 12c.

Eg: ADMIN is a user and MANAGER is group in WLS and I have mapped ADMIN user to MANAGER group.

when I login using the wls user (ie.ADMIN), it gets navigate to corresponding custom page and I can get user using following EL #{securityContext.userName} or java code:

ADFContext adfCtx = ADFContext.getCurrent();  
SecurityContext secCntx = adfCtx.getSecurityContext();  
String user = secCntx.getUserPrincipal().getName();  
String userName = secCntx.getUserName();
String[]  Roles = secCntx.getUserRoles();

Similarly I want capture the group for the currently logging user ie. ADMIN and output should be MANAGER.

I used EL as #{securityContext.userRoles} for getting the role and kindly help me to get the user group during login time.

Expected OUTPUT should be MANAGER and my output is NULL.


Solution

  • You're getting a NULL output because the securityContext doesnt contain an object called "userRoles" in ADF Bindings.

    The securityContext el expression contains the following value :

    • Authenticated
    • regionViewable
    • taskflowViewable
    • userGrantedPermission
    • userGrantedRessource
    • userInAllRoles
    • userInRole
    • userName

    Since you seems to know all the expected roles you can display MANAGER doing something like :

    <af:outputText value="{securityContext.userInAllRoles[‘MANAGER’]?'MANAGER':'NOT MANAGER'}" id="ot_1"/>
    

    or using the rendered attribute :

    <af:outputText rendered="{securityContext.userInAllRoles[‘MANAGER’]}" value="MANAGER" id="ot_1"/>
    <af:outputText rendered="{securityContext.userInAllRoles[‘EMPLOYEE’]}" value="EMPLOYEE" id="ot_2"/>
    
    ...
    

    Side note :

    • userInAllRoles['ROLE1','ROLE2'] return true if the user have ROLE1 and ROLE2
    • userInRole['ROLE1','ROLE2'] return true if the user have ROLE1 or ROLE2