001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/user/tags/sakai_2-4-1/user-impl/impl/src/java/org/sakaiproject/user/impl/OpenAuthnComponent.java $
003: * $Id: OpenAuthnComponent.java 7194 2006-03-29 02:18:22Z ggolden@umich.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.user.impl;
021:
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024: import org.sakaiproject.user.api.Authentication;
025: import org.sakaiproject.user.api.AuthenticationException;
026: import org.sakaiproject.user.api.AuthenticationManager;
027: import org.sakaiproject.user.api.AuthenticationUnknownException;
028: import org.sakaiproject.user.api.Evidence;
029: import org.sakaiproject.user.api.ExternalTrustedEvidence;
030: import org.sakaiproject.user.api.IdPwEvidence;
031:
032: /**
033: * <p>
034: * A placeholder wide open Authentication - returns the password as the authentication user (UUID) id.
035: * </p>
036: */
037: public class OpenAuthnComponent implements AuthenticationManager {
038: /** Our log (commons). */
039: private static Log M_log = LogFactory
040: .getLog(OpenAuthnComponent.class);
041:
042: /**********************************************************************************************************************************************************************************************************************************************************
043: * Dependencies and their setter methods
044: *********************************************************************************************************************************************************************************************************************************************************/
045:
046: /**********************************************************************************************************************************************************************************************************************************************************
047: * Init and Destroy
048: *********************************************************************************************************************************************************************************************************************************************************/
049:
050: /**
051: * Final initialization, once all dependencies are set.
052: */
053: public void init() {
054: M_log.info("init()");
055: }
056:
057: /**
058: * Final cleanup.
059: */
060: public void destroy() {
061: M_log.info("destroy()");
062: }
063:
064: /**********************************************************************************************************************************************************************************************************************************************************
065: * Work interface methods: AuthenticationManager
066: *********************************************************************************************************************************************************************************************************************************************************/
067:
068: /**
069: * @inheritDoc
070: */
071: public Authentication authenticate(Evidence e)
072: throws AuthenticationException {
073: if (e instanceof IdPwEvidence) {
074: IdPwEvidence evidence = (IdPwEvidence) e;
075:
076: // reject null or blank
077: if ((evidence.getPassword() == null)
078: || (evidence.getPassword().trim().length() == 0)
079: || (evidence.getIdentifier() == null)
080: || (evidence.getIdentifier().trim().length() == 0)) {
081: throw new AuthenticationException("invalid login");
082: }
083:
084: // we always pass the authentication
085:
086: // use the password as the uid, the name as the eid
087: Authentication rv = new org.sakaiproject.util.Authentication(
088: evidence.getPassword(), evidence.getIdentifier());
089: return rv;
090: } else if (e instanceof ExternalTrustedEvidence) {
091: ExternalTrustedEvidence evidence = (ExternalTrustedEvidence) e;
092:
093: // reject null or blank
094: if ((evidence.getIdentifier() == null)
095: || (evidence.getIdentifier().trim().length() == 0)) {
096: throw new AuthenticationException("invalid login");
097: }
098:
099: // accept, but we need to lookup the user in our database to get a uuid.
100:
101: Authentication rv = new org.sakaiproject.util.Authentication(
102: "000-00-0000", evidence.getIdentifier());
103: return rv;
104: } else {
105: throw new AuthenticationUnknownException(e.toString());
106: }
107: }
108: }
|