KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > security > actions > ShowSelectAuthenticationSchemeAction


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.security.actions;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27 import javax.servlet.http.HttpServletResponse JavaDoc;
28
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.apache.struts.Globals;
32 import org.apache.struts.action.ActionForm;
33 import org.apache.struts.action.ActionForward;
34 import org.apache.struts.action.ActionMapping;
35 import org.apache.struts.action.ActionMessage;
36 import org.apache.struts.action.ActionMessages;
37 import org.apache.struts.util.LabelValueBean;
38
39 import com.sslexplorer.core.actions.DefaultAction;
40 import com.sslexplorer.security.AuthenticationScheme;
41 import com.sslexplorer.security.Constants;
42 import com.sslexplorer.security.DefaultAuthenticationScheme;
43 import com.sslexplorer.security.LogonStateAndCache;
44 import com.sslexplorer.security.SessionInfo;
45 import com.sslexplorer.security.forms.SchemeSelectionForm;
46
47 /**
48  * Action to allow a new visitor to select the <i>Authentication Scheme</i>
49  * they wish to use.
50  *
51  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
52  */

53 public class ShowSelectAuthenticationSchemeAction extends DefaultAction {
54
55     final static Log log = LogFactory.getLog(ShowSelectAuthenticationSchemeAction.class);
56
57     /*
58      * (non-Javadoc)
59      *
60      * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping,
61      * org.apache.struts.action.ActionForm,
62      * javax.servlet.http.HttpServletRequest,
63      * javax.servlet.http.HttpServletResponse)
64      */

65     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
66                     throws Exception JavaDoc {
67         ActionForward fwd = super.execute(mapping, form, request, response);
68         if (fwd != null) {
69             return fwd;
70         }
71         if (request.getSession().getAttribute(Constants.SESSION_LOCKED) != null) {
72             ActionMessages messages = new ActionMessages();
73             messages.add(Globals.MESSAGE_KEY, new ActionMessage("login.sessionLocked"));
74             saveMessages(request, messages);
75         }
76
77         LogonStateAndCache logonStateMachine = (LogonStateAndCache) request.getSession().getAttribute(
78                         LogonStateAndCache.LOGON_STATE_MACHINE);
79         if (logonStateMachine == null) {
80             // there is no state machine so go back to the logonpage.
81
return new ActionForward("/showLogon.do");
82         } else {
83             List JavaDoc<LabelValueBean> l = new ArrayList JavaDoc<LabelValueBean>();
84             for (Iterator JavaDoc i = logonStateMachine.getAuthSchemes().iterator(); i.hasNext();) {
85                 AuthenticationScheme seq = (DefaultAuthenticationScheme) i.next();
86                 LabelValueBean lvb = new LabelValueBean(seq.getResourceName(), String.valueOf(seq.getResourceId()));
87                 l.add(lvb);
88             }
89             logonStateMachine.setState(LogonStateAndCache.STATE_KNOWN_USERNAME_MULTIPLE_SCHEMES_SELECT);
90             ((SchemeSelectionForm) form).setAuthenticationSchemes(l);
91             return mapping.findForward("success");
92         }
93     }
94
95     /*
96      * (non-Javadoc)
97      *
98      * @see com.sslexplorer.core.actions.CoreAction#getNavigationContext(org.apache.struts.action.ActionMapping,
99      * org.apache.struts.action.ActionForm,
100      * javax.servlet.http.HttpServletRequest,
101      * javax.servlet.http.HttpServletResponse)
102      */

103     public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
104         return SessionInfo.ALL_CONTEXTS;
105     }
106 }
Popular Tags