In many situations we need to get the current logged in username in managed beans.
It is easy to get the username through EL by putting #{securityContext.username},but what about to get the same thing in managed beans/ java code.
I have found couple of methods to find the same results.I will share it with you soon.......
import javax.faces.context.FacesContext;
import oracle.adf.share.ADFContext;
public class UtilityBean {
public UtilityBean() {
super();
}
public String getUserNameMethod1(){
FacesContext fc=FacesContext.getCurrentInstance();
String userName=fc.getExternalContext().getRemoteUser();
return userName;
}
public String getUserNameMethod2(){
ADFContext afc=ADFContext.getCurrent();
String userName=afc.getSecurityContext().getUserName();
return userName;
}
}
For getting the username in portlet ,you can also see Yannick's Blog.
It is easy to get the username through EL by putting #{securityContext.username},but what about to get the same thing in managed beans/ java code.
I have found couple of methods to find the same results.I will share it with you soon.......
import javax.faces.context.FacesContext;
import oracle.adf.share.ADFContext;
public class UtilityBean {
public UtilityBean() {
super();
}
public String getUserNameMethod1(){
FacesContext fc=FacesContext.getCurrentInstance();
String userName=fc.getExternalContext().getRemoteUser();
return userName;
}
public String getUserNameMethod2(){
ADFContext afc=ADFContext.getCurrent();
String userName=afc.getSecurityContext().getUserName();
return userName;
}
}
For getting the username in portlet ,you can also see Yannick's Blog.
No comments :
Post a Comment