KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > navigation > actions > SelectPropertyProfileAction


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.navigation.actions;
21
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23 import javax.servlet.http.HttpServletResponse JavaDoc;
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 /**
46  * Action to deal with the form submission from 'selectPropertyProfile'. This
47  * places the selected profile into the session so that any user scoped
48  * properties come from the newly selected profile. Optionally, it will also set
49  * the profile as the users default automatically selected upon next logon. This
50  * information is stored as a user attribute.
51  *
52  * @author Brett Smith <brett@3sp.com>
53  */

54
55 public class SelectPropertyProfileAction extends AuthenticatedAction {
56
57     final static Log log = LogFactory.getLog(SelectPropertyProfileAction.class);
58
59     /*
60      * (non-Javadoc)
61      *
62      * @see com.sslexplorer.core.actions.AuthenticatedAction#onExecute(org.apache.struts.action.ActionMapping,
63      * org.apache.struts.action.ActionForm,
64      * javax.servlet.http.HttpServletRequest,
65      * javax.servlet.http.HttpServletResponse)
66      */

67     public ActionForward onExecute(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
68                     throws Exception JavaDoc {
69         // Get the property profile selected
70
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 JavaDoc("No default profile.");
79             }
80         }
81
82         // Make the selected profile the one in use for this session
83
if (log.isInfoEnabled())
84             log.info("Switching user " + user.getPrincipalName() + " to profile " + profile.getResourceName());
85         request.getSession().setAttribute(Constants.SELECTED_PROFILE, profile);
86         String JavaDoc originalRequest = (String JavaDoc) request.getSession().getAttribute(Constants.ORIGINAL_REQUEST);
87
88         // Optionally set the users default property profile
89
if (profileSelectionForm.getMakeDefault()) {
90             Property.setProperty(new UserAttributeKey(user, User.USER_STARTUP_PROFILE), String.valueOf(profile.getResourceId()), getSessionInfo(request));
91         }
92
93         // Reset the navigation and timeouts, they may be different in this new
94
// profile
95
CoreUtil.resetMainNavigation(request.getSession());
96         LogonControllerFactory.getInstance().resetSessionTimeout(user, profile, request.getSession());
97
98         // The new profile may have 'Automatically launch VPN client' enabled so
99
// launch the VPN client
100
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         /*
109          * Its possible the profile selection page is being displayed as the
110          * result of the 'Select profile on logon' option. If so we will have
111          * the original request URL that we should forward to, otherwise just
112          * return to the referer.
113          */

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 JavaDoc referer = CoreUtil.getReferer(request);
123                 return referer == null ? mapping.findForward("home") : new ActionForward(referer, true);
124             }
125         }
126     }
127
128     /*
129      * (non-Javadoc)
130      *
131      * @see com.sslexplorer.core.actions.AuthenticatedAction#requiresProfile()
132      */

133     public boolean requiresProfile() {
134         // Profile is not required because this is where one might be set!
135
return false;
136     }
137     
138     
139     @Override JavaDoc
140     public ActionForward checkIntercept(ActionMapping mapping, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
141         return null;
142     }
143
144     /*
145      * (non-Javadoc)
146      *
147      * @see com.sslexplorer.core.actions.CoreAction#getNavigationContext(org.apache.struts.action.ActionMapping,
148      * org.apache.struts.action.ActionForm,
149      * javax.servlet.http.HttpServletRequest,
150      * javax.servlet.http.HttpServletResponse)
151      */

152     public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
153         return SessionInfo.ALL_CONTEXTS;
154     }
155
156 }
Popular Tags