Sunday, 19 January 2020

ADF Security - How to get logged in user name and roles information

In ADF Security object and role information can be found out using the below code anytime using the java code 

User Name Information

     ADFContext adfCtx = ADFContext.getCurrent();  
     SecurityContext secCntx = adfCtx.getSecurityContext();  
     String user = secCntx.getUserPrincipal().getName();  
     String loggedInUserName = secCntx.getUserName();  


Role Information 
With the same set of logic you can find the role information.

  ADFContext adfCtx = ADFContext.getCurrent();  
  SecurityContext secCntx = adfCtx.getSecurityContext();   
    String[] Roles = secCntx.getUserRoles()


Role Information check
You can use below logic to check if user have a role which you want to check, like if you want to enable a button if user have have manager Role.


public boolean checkIsUserInRole(String roleName){
        return 
(FacesContext.getCurrentInstance().getExternalContext().isUserInRole(roleName));
}

No comments:

Post a Comment

Feature Selection in AI

In artifical intelegance/machine learning, everything start and end with data and in current world everyday by using facebook, insta we all ...