1 19 20 package com.sslexplorer.navigation.actions; 21 22 import javax.servlet.http.HttpServletRequest ; 23 import javax.servlet.http.HttpServletResponse ; 24 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 import org.apache.struts.action.ActionForm; 28 import org.apache.struts.action.ActionForward; 29 import org.apache.struts.action.ActionMapping; 30 31 import com.sslexplorer.agent.DefaultAgentManager; 32 import com.sslexplorer.core.CoreUtil; 33 import com.sslexplorer.core.actions.AuthenticatedAction; 34 import com.sslexplorer.navigation.forms.ProfileSelectionForm; 35 import com.sslexplorer.properties.ProfilesFactory; 36 import com.sslexplorer.properties.Property; 37 import com.sslexplorer.properties.PropertyProfile; 38 import com.sslexplorer.properties.impl.profile.ProfilePropertyKey; 39 import com.sslexplorer.properties.impl.userattributes.UserAttributeKey; 40 import com.sslexplorer.security.Constants; 41 import com.sslexplorer.security.LogonControllerFactory; 42 import com.sslexplorer.security.SessionInfo; 43 import com.sslexplorer.security.User; 44 45 54 55 public class SelectPropertyProfileAction extends AuthenticatedAction { 56 57 final static Log log = LogFactory.getLog(SelectPropertyProfileAction.class); 58 59 67 public ActionForward onExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 68 throws Exception { 69 User user = getSessionInfo(request).getUser(); 71 ProfileSelectionForm profileSelectionForm = (ProfileSelectionForm) form; 72 PropertyProfile profile = ProfilesFactory.getInstance().getPropertyProfile( 73 profileSelectionForm.getSelectedPropertyProfile()); 74 if (profile == null) { 75 profile = ProfilesFactory.getInstance().getPropertyProfile(user.getPrincipalName(), "Default", 76 user.getRealm().getResourceId()); 77 if (profile == null) { 78 throw new Exception ("No default profile."); 79 } 80 } 81 82 if (log.isInfoEnabled()) 84 log.info("Switching user " + user.getPrincipalName() + " to profile " + profile.getResourceName()); 85 request.getSession().setAttribute(Constants.SELECTED_PROFILE, profile); 86 String originalRequest = (String ) request.getSession().getAttribute(Constants.ORIGINAL_REQUEST); 87 88 if (profileSelectionForm.getMakeDefault()) { 90 Property.setProperty(new UserAttributeKey(user, User.USER_STARTUP_PROFILE), String.valueOf(profile.getResourceId()), getSessionInfo(request)); 91 } 92 93 CoreUtil.resetMainNavigation(request.getSession()); 96 LogonControllerFactory.getInstance().resetSessionTimeout(user, profile, request.getSession()); 97 98 if (!DefaultAgentManager.getInstance().hasActiveAgent(LogonControllerFactory.getInstance().getSessionInfo(request)) 101 && Property.getPropertyBoolean(new ProfilePropertyKey(profile.getResourceId(), user.getPrincipalName(), 102 "client.autoStart", user.getRealm().getResourceId()))) { 103 request.getSession().removeAttribute(Constants.ORIGINAL_REQUEST); 104 request.getSession().setAttribute(Constants.REQ_ATTR_LAUNCH_AGENT_REFERER, originalRequest); 105 return mapping.findForward("launchAgent"); 106 } 107 108 114 else if (originalRequest != null) { 115 request.getSession().removeAttribute(Constants.ORIGINAL_REQUEST); 116 return new ActionForward(originalRequest, true); 117 } else { 118 if (profileSelectionForm.getReferer() != null) { 119 ActionForward fwd = new ActionForward(profileSelectionForm.getReferer(), true); 120 return fwd; 121 } else { 122 String referer = CoreUtil.getReferer(request); 123 return referer == null ? mapping.findForward("home") : new ActionForward(referer, true); 124 } 125 } 126 } 127 128 133 public boolean requiresProfile() { 134 return false; 136 } 137 138 139 @Override 140 public ActionForward checkIntercept(ActionMapping mapping, HttpServletRequest request, HttpServletResponse response) throws Exception { 141 return null; 142 } 143 144 152 public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { 153 return SessionInfo.ALL_CONTEXTS; 154 } 155 156 } | Popular Tags |