Map userInfo = (Map) portletRequest.getAttribute(PortletRequest.USER_INFO);
username = (userInfo!=null) ? (String) userInfo.get("user.name") : null;
if (username == null) {
username = portletRequest.getRemoteUser();
}
ApplicationGlobalContext context = new ApplicationGlobalContext();
Application application = facesContext.getApplication();
if(ProxyManager.getDefaultProxy(username) == null){
HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
PrintWriter out = response.getWriter();
out.println("<h3>Login to My Proxy server using your credentials!</h3><br>");
out.close();
throw new Exception("Login to My Proxy server using your credentials!");
}
GSSCredential gssCredential = ProxyManager.getDefaultProxy(username);
context.setGssCredential(gssCredential);
if(context.getXmcCatTestUser() == null ){
context.setXmcCatTestUser(gssCredential.getName().toString());
}
context.setPortalUserName(username);
System.out.println("Getting Grid credential form Proxy worked for " + username);
// to create RegistryService instance
ValueBinding binding = application.createValueBinding("#{applicationGlobalContext}");
binding.setValue(facesContext, context);
this.setContext(context);
checkStatus = true;
}else{
UserInfo userInfo = (UserInfo) facesContext.getExternalContext().getSessionMap().get("userInfo");
String userName = userInfo.getUserName();
GSSCredential credential = ProxyManager.getDefaultProxy(userName);
if(credential != null){
context = new ApplicationGlobalContext();
context.setGssCredential(credential);
context.load();
facesContext.getExternalContext().getSessionMap().put("applicationGlobalContext", context);
this.setContext(context);
checkStatus = true;
}else{
FacesContext.getCurrentInstance().getExternalContext().redirect("proxyconfigure.jsf");