public ActionForward onExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
// Get the property profile selected
User user = getSessionInfo(request).getUser();
ProfileSelectionForm profileSelectionForm = (ProfileSelectionForm) form;
PropertyProfile profile = ProfilesFactory.getInstance().getPropertyProfile(
profileSelectionForm.getSelectedPropertyProfile());
if (profile == null) {
profile = ProfilesFactory.getInstance().getPropertyProfile(user.getPrincipalName(), "Default",
user.getRealm().getResourceId());
if (profile == null) {
throw new Exception("No default profile.");
}
}
// Make the selected profile the one in use for this session
if (log.isInfoEnabled())
log.info("Switching user " + user.getPrincipalName() + " to profile " + profile.getResourceName());
request.getSession().setAttribute(Constants.SELECTED_PROFILE, profile);
String originalRequest = (String) request.getSession().getAttribute(Constants.ORIGINAL_REQUEST);
// Optionally set the users default property profile
if (profileSelectionForm.getMakeDefault()) {
Property.setProperty(new UserAttributeKey(user, User.USER_STARTUP_PROFILE), String.valueOf(profile.getResourceId()), getSessionInfo(request));
}
// Reset the navigation and timeouts, they may be different in this new
// profile
CoreUtil.resetMainNavigation(request.getSession());
LogonControllerFactory.getInstance().resetSessionTimeout(user, profile, request.getSession());
// The new profile may have 'Automatically launch VPN client' enabled so
// launch the VPN client
if (!DefaultAgentManager.getInstance().hasActiveAgent(LogonControllerFactory.getInstance().getSessionInfo(request))
&& Property.getPropertyBoolean(new ProfilePropertyKey(profile.getResourceId(), user.getPrincipalName(),
"client.autoStart", user.getRealm().getResourceId()))) {
request.getSession().removeAttribute(Constants.ORIGINAL_REQUEST);
request.getSession().setAttribute(Constants.REQ_ATTR_LAUNCH_AGENT_REFERER, originalRequest);
return mapping.findForward("launchAgent");
}