KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > security > authwizard > forms > AthenticationSchemeSelectionForm


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.authwizard.forms;
21
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.struts.Globals;
27 import org.apache.struts.action.ActionErrors;
28 import org.apache.struts.action.ActionMapping;
29 import org.apache.struts.action.ActionMessage;
30
31 import com.sslexplorer.boot.PropertyList;
32 import com.sslexplorer.input.MultiSelectDataSource;
33 import com.sslexplorer.input.MultiSelectSelectionModel;
34 import com.sslexplorer.security.AuthenticationModuleDefinition;
35 import com.sslexplorer.security.AuthenticationModuleManager;
36 import com.sslexplorer.security.LogonControllerFactory;
37 import com.sslexplorer.security.ModulesDataSource;
38 import com.sslexplorer.security.SessionInfo;
39 import com.sslexplorer.wizard.AbstractWizardSequence;
40 import com.sslexplorer.wizard.forms.DefaultWizardForm;
41
42 public class AthenticationSchemeSelectionForm extends DefaultWizardForm {
43
44     final static Log log = LogFactory.getLog(AthenticationSchemeSelectionForm.class);
45
46     public static final String JavaDoc ATTR_SELECTED_MODULES = "selectedModules";
47
48     // TODO sampleAttributes attributes should be defined here.
49
protected MultiSelectSelectionModel moduleModel;
50     protected PropertyList selectedModules;
51
52     /**
53      * Constructor
54      */

55     public AthenticationSchemeSelectionForm() {
56         super(true, true, "/WEB-INF/jsp/content/security/authwizard/athenticationSchemeSelection.jspf", "resourceName", true,
57                         false, "athenticationSchemeSelection", "security", "authwizard.athenticationSchemeSelection", 2);
58     }
59
60     /*
61      * (non-Javadoc)
62      *
63      * @see com.sslexplorer.wizard.forms.AbstractWizardForm#init(com.sslexplorer.wizard.AbstractWizardSequence,
64      * javax.servlet.http.HttpServletRequest)
65      */

66     public void init(AbstractWizardSequence sequence, HttpServletRequest JavaDoc request) throws Exception JavaDoc {
67         super.init(sequence, request);
68         this.selectedModules = ((PropertyList) sequence.getAttribute(ATTR_SELECTED_MODULES, new PropertyList()));
69         MultiSelectDataSource modules = new ModulesDataSource("security");
70         SessionInfo session = LogonControllerFactory.getInstance().getSessionInfo(request);
71         this.moduleModel = new MultiSelectSelectionModel(session, modules, selectedModules);
72     }
73
74     /*
75      * (non-Javadoc)
76      *
77      * @see com.sslexplorer.wizard.forms.AbstractWizardForm#apply(com.sslexplorer.wizard.AbstractWizardSequence)
78      */

79     public void apply(AbstractWizardSequence sequence) throws Exception JavaDoc {
80         super.apply(sequence);
81         sequence.putAttribute(ATTR_SELECTED_MODULES, this.selectedModules);
82     }
83
84     /**
85      * Get the module model
86      *
87      * @return the module model.
88      */

89     public MultiSelectSelectionModel getModuleModel() {
90         return moduleModel;
91     }
92
93     /**
94      * Set the module model
95      *
96      * @param moduleModel model to set.
97      */

98     public void setModuleModel(MultiSelectSelectionModel moduleModel) {
99         this.moduleModel = moduleModel;
100     }
101
102     /**
103      * Get the selected modules as a list
104      *
105      * @return selected modules list
106      */

107     public PropertyList getSelectedModulesList() {
108         return selectedModules;
109     }
110
111     /**
112      * Get the selected modules as a string suitable for the multi select
113      * components
114      *
115      * @return selected modules as string
116      */

117     public String JavaDoc getSelectedModules() {
118         return selectedModules.getAsTextFieldText();
119     }
120
121     /**
122      * Set the selected modules as a string from the multi select components
123      *
124      * @param selectedModules selected modules as string
125      */

126     public void setSelectedModules(String JavaDoc selectedModules) {
127         this.selectedModules.setAsTextFieldText(selectedModules);
128     }
129
130     /**
131      * Set the selected modules list
132      *
133      * @param selectedModules selected modules list
134      */

135     public void setSelectedModulesList(PropertyList selectedModules) {
136         this.selectedModules = selectedModules;
137     }
138
139     public ActionErrors validate(ActionMapping mapping, HttpServletRequest JavaDoc request) {
140         ActionErrors errs = new ActionErrors();
141         if (this.isCommiting()) {
142             PropertyList l = this.getSelectedModulesList();
143             if (l.size() < 1) {
144                 errs.add(Globals.ERROR_KEY, new ActionMessage("editAuthenticationScheme.error.noModulesSelected"));
145             } else {
146                 AuthenticationModuleDefinition def = AuthenticationModuleManager.getInstance().getModuleDefinition(
147                                 l.get(0).toString());
148                 
149                 if (!def.getPrimary() && (!def.getPrimaryIfSecondardExists() && l.size() > 1)) {
150                         errs.add(Globals.ERROR_KEY, new ActionMessage("editAuthenticationScheme.error.firstModuleNotPrimary"));
151                 }
152             }
153         }
154         return errs;
155     }
156
157 }
158
Popular Tags