1 19 20 package com.sslexplorer.policyframework.actions; 21 22 import java.util.Arrays ; 23 24 import javax.servlet.http.HttpServletRequest ; 25 import javax.servlet.http.HttpServletResponse ; 26 27 import org.apache.commons.logging.Log; 28 import org.apache.commons.logging.LogFactory; 29 import org.apache.struts.action.ActionForm; 30 import org.apache.struts.action.ActionForward; 31 import org.apache.struts.action.ActionMapping; 32 33 import com.sslexplorer.core.UserDatabaseManager; 34 import com.sslexplorer.core.actions.AuthenticatedDispatchAction; 35 import com.sslexplorer.policyframework.Principal; 36 import com.sslexplorer.policyframework.forms.PrincipalInformationForm; 37 import com.sslexplorer.security.Constants; 38 import com.sslexplorer.security.LogonControllerFactory; 39 import com.sslexplorer.security.Role; 40 import com.sslexplorer.security.SessionInfo; 41 42 47 public class PrincipalInformationAction extends AuthenticatedDispatchAction { 48 49 final static Log log = LogFactory.getLog(PrincipalInformationAction.class); 50 51 54 public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 55 try { 56 String principalType = request.getParameter("principalType"); 57 String principalName = request.getParameter("principalName"); 58 Principal principal; 59 if("account".equals(principalType)) { 60 principal = UserDatabaseManager.getInstance().getUserDatabase(LogonControllerFactory.getInstance().getUser(request).getRealm()).getAccount(principalName); 61 } else if("role".equals(principalType)) { 62 principal = UserDatabaseManager.getInstance().getUserDatabase(LogonControllerFactory.getInstance().getUser(request).getRealm()).getRole(principalName); 63 } else { 64 throw new Exception (); 65 } 66 request.setAttribute(Constants.REQ_ATTR_INFO_RESOURCE, principal); 67 return principalInformation(mapping, form, request, response); 68 } catch (Exception e) { 69 log.error("Failed to get principal information. ", e); 70 response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); 71 } 72 return null; 73 } 74 75 83 public ActionForward principalInformation(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 84 PrincipalInformationForm informationForm = (PrincipalInformationForm) form; 85 Principal principal = (Principal) request.getAttribute(Constants.REQ_ATTR_INFO_RESOURCE); 86 informationForm.initialise(principal); 87 String principalType = request.getParameter("principalType"); 88 if("role".equals(principalType)) { 89 informationForm.setAccounts(Arrays.asList(UserDatabaseManager.getInstance().getUserDatabase(LogonControllerFactory.getInstance().getUser(request).getRealm()).getUsersInRole((Role)principal))); 90 } 91 return mapping.findForward("display"); 92 } 93 94 97 public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { 98 return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT; 99 } 100 } | Popular Tags |