001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.jetspeed.sso.impl;
019:
020: import java.util.Collection;
021: import java.util.Iterator;
022: import java.util.Vector;
023:
024: import org.apache.jetspeed.sso.SSOException;
025: import org.apache.jetspeed.sso.SSOSite;
026: import org.apache.jetspeed.sso.SSOPrincipal;
027:
028: /**
029: * SSOSiteImpl
030: * Class holding information about the Site and credentials for Single Sign on SSO.
031: * OJB will map the database entries into this class
032: *
033: * @author <a href="mailto:rogerrut@apache.org">Roger Ruttimann</a>
034: * @version $Id: SSOSiteImpl.java 516448 2007-03-09 16:25:47Z ate $
035: */
036:
037: public class SSOSiteImpl implements SSOSite {
038:
039: // Private member for OJB mapping
040: private int siteId;
041: private String name;
042: private String siteURL;
043: private boolean isAllowUserSet;
044: private boolean isCertificateRequired;
045:
046: private boolean isChallangeResponseAuthentication;
047:
048: /* Realm used to do ChallengeResponse Authentication */
049: private String realm;
050:
051: private boolean isFormAuthentication;
052:
053: /* Names of fields for User and Password values. The names are up to the
054: * application developer and therefore it must be configurable for SSO*/
055: private String formUserField;
056: private String formPwdField;
057:
058: private Collection principals = new Vector();
059: private Collection remotePrincipals = new Vector();
060:
061: /**
062: *
063: */
064: public SSOSiteImpl() {
065: super ();
066:
067: }
068:
069: /*
070: * Setters and getters for member variables
071: */
072:
073: /**
074: * @return Returns the isAllowUserSet.
075: */
076: public boolean isAllowUserSet() {
077: return isAllowUserSet;
078: }
079:
080: /**
081: * @param isAllowUserSet The isAllowUserSet to set.
082: */
083: public void setAllowUserSet(boolean isAllowUserSet) {
084: this .isAllowUserSet = isAllowUserSet;
085: }
086:
087: /**
088: * @return Returns the isCertificateRequired.
089: */
090: public boolean isCertificateRequired() {
091: return isCertificateRequired;
092: }
093:
094: /**
095: * @param isCertificateRequired The isCertificateRequired to set.
096: */
097: public void setCertificateRequired(boolean isCertificateRequired) {
098: this .isCertificateRequired = isCertificateRequired;
099: }
100:
101: /**
102: * @return Returns the name.
103: */
104: public String getName() {
105: return name;
106: }
107:
108: /**
109: * @param name The name to set.
110: */
111: public void setName(String name) {
112: this .name = name;
113: }
114:
115: /**
116: * @return Returns the principals.
117: */
118: public Collection getPrincipals() {
119: return this .principals;
120: }
121:
122: /**
123: * @param principals The principals to set.
124: */
125: public void setPrincipals(Collection principals) {
126: this .principals.addAll(principals);
127: }
128:
129: /**
130: * @return Returns the siteId.
131: */
132: public int getSiteId() {
133: return siteId;
134: }
135:
136: /**
137: * @param siteId The siteId to set.
138: */
139: public void setSiteId(int siteId) {
140: this .siteId = siteId;
141: }
142:
143: /**
144: * @return Returns the siteURL.
145: */
146: public String getSiteURL() {
147: return siteURL;
148: }
149:
150: /**
151: * @param siteURL The siteURL to set.
152: */
153: public void setSiteURL(String siteURL) {
154: this .siteURL = siteURL;
155: }
156:
157: /**
158: * Utility functions
159: * addCredential()
160: * Adds the credentail to the credentials collection
161: *
162: */
163:
164: /**
165: * addPrincipal
166: * Adds the SSOPrincipal to the principals collection
167: *
168: */
169: public void addPrincipal(SSOPrincipal principal)
170: throws SSOException {
171: boolean bStatus = false;
172:
173: try {
174: bStatus = principals.add(principal);
175: } catch (Exception e) {
176: // Adding credentail to coollection failed -- notify caller with SSOException
177: throw new SSOException(
178: SSOException.FAILED_ADDING_PRINCIPAL_TO_MAPPING_TABLE_FOR_SITE
179: + e.getMessage());
180: }
181:
182: if (bStatus == false)
183: throw new SSOException(
184: SSOException.FAILED_ADDING_PRINCIPAL_TO_MAPPING_TABLE_FOR_SITE);
185: }
186:
187: /**
188: * removePrincipal()
189: * removes a principal from the principals collection
190: *
191: */
192: public void removePrincipal(long principalId) throws SSOException {
193: boolean bStatus = false;
194: SSOPrincipal principalObj = null;
195: Iterator itSitePrincipals = principals.iterator();
196:
197: while (itSitePrincipals.hasNext()) {
198: principalObj = (SSOPrincipal) itSitePrincipals.next();
199: if (principalObj.getPrincipalId() == principalId) {
200:
201: try {
202: bStatus = principals.remove(principalObj);
203: } catch (Exception e) {
204: // Adding credentail to coollection failed -- notify caller with SSOException
205: throw new SSOException(
206: SSOException.FAILED_REMOVING_PRINCIPAL_FROM_MAPPING_TABLE_FOR_SITE
207: + e.getMessage());
208: }
209:
210: if (bStatus == false)
211: throw new SSOException(
212: SSOException.FAILED_REMOVING_PRINCIPAL_FROM_MAPPING_TABLE_FOR_SITE);
213: }
214:
215: }
216: }
217:
218: /**
219: * @return Returns the remotePrincipals.
220: */
221: public Collection getRemotePrincipals() {
222: return remotePrincipals;
223: }
224:
225: /**
226: * @param remotePrincipals The remotePrincipals to set.
227: */
228: public void setRemotePrincipals(Collection remotePrincipals) {
229: this .remotePrincipals = remotePrincipals;
230: }
231:
232: /**
233: * Define the Authentication methods.
234: * Supported are: Challenge Response and From based
235: */
236: /**
237: * Form authentication requires two fields that hold the credential
238: * information for the request.
239: */
240: public void setFormAuthentication(String formUserField,
241: String formPwdField) {
242: // Set the fields for Form Authentication and clear other authentication methods
243:
244: }
245:
246: /*
247: * Uses Challenge Response mechanism for authentication
248: */
249: public void setChallengeResponseAuthentication() {
250: // Set the fields for ChallengeResponse and clear other authentication methods
251:
252: }
253:
254: /* Setters/Getters for Authentication settings */
255: public String getFormPwdField() {
256: return formPwdField;
257: }
258:
259: public void setFormPwdField(String formPwdField) {
260: this .formPwdField = formPwdField;
261: }
262:
263: public String getFormUserField() {
264: return formUserField;
265: }
266:
267: public void setFormUserField(String formUserField) {
268: this .formUserField = formUserField;
269: }
270:
271: public boolean isChallangeResponseAuthentication() {
272: return isChallangeResponseAuthentication;
273: }
274:
275: public void setChallengeResponseAuthentication(
276: boolean isChallangeResponseAuthentication) {
277: this .isChallangeResponseAuthentication = isChallangeResponseAuthentication;
278: }
279:
280: public boolean isFormAuthentication() {
281: return isFormAuthentication;
282: }
283:
284: public void setFormAuthentication(boolean isFormAuthentication) {
285: this .isFormAuthentication = isFormAuthentication;
286: }
287:
288: public void configFormAuthentication(String formUserField,
289: String formPwdField) {
290: this .isFormAuthentication = true;
291: this .setChallengeResponseAuthentication(false);
292:
293: this .formPwdField = formPwdField;
294: this .formUserField = formUserField;
295: }
296:
297: /*
298: * (non-Javadoc)
299: * @see org.apache.jetspeed.sso.SSOSite#setRealm(java.lang.String)
300: */
301: public void setRealm(String realm) {
302: this .realm = realm;
303: }
304:
305: /*
306: * (non-Javadoc)
307: * @see org.apache.jetspeed.sso.SSOSite#getRealm()
308: */
309: public String getRealm() {
310: return this.realm;
311: }
312: }
|