001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/dav/tags/sakai_2-4-1/dav-server/src/java/org/sakaiproject/dav/DavRealm.java $
003: * $Id: DavRealm.java 8482 2006-04-28 20:28:09Z ggolden@umich.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 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.dav;
021:
022: import java.security.Principal;
023:
024: import org.apache.catalina.LifecycleException;
025: import org.apache.catalina.realm.RealmBase;
026:
027: /**
028: * Simple implementation of <b>Realm</b> that consults the Sakai user directory service to provide container security equivalent to then application security in CHEF.
029: * <p>
030: * <strong>IMPLEMENTATION NOTE</strong>: The user is assumed to have all "roles" because servlets and teamlets will enforce roles within Sakai - so in this realm, we simply indicate "true".
031: */
032: public final class DavRealm extends RealmBase {
033: /** Descriptive information about this Realm implementation. */
034: protected final String info = "org.sakaiproject.realm.DavRealm/1.0";
035:
036: /** Descriptive information about this Realm implementation. */
037: protected static final String name = "DavRealm";
038:
039: /**
040: * Return descriptive information about this Realm implementation and the corresponding version number, in the format <code><description>/<version></code>.
041: */
042: public String getInfo() {
043: return info;
044: }
045:
046: /**
047: * Return the Principal associated with the specified username and credentials, if there is one; otherwise return <code>null</code>.
048: *
049: * @param username
050: * Username of the Principal to look up
051: * @param credentials
052: * Password or other credentials to use in authenticating this username
053: */
054: public Principal authenticate(String username, String credentials) {
055: if (username == null || credentials == null)
056: return (null);
057: if (username.length() <= 0 || credentials.length() <= 0)
058: return (null);
059:
060: DavPrincipal prin = new DavPrincipal(username, credentials);
061:
062: return prin;
063: }
064:
065: /**
066: * Return a short name for this Realm implementation.
067: */
068: protected String getName() {
069: return name;
070: }
071:
072: protected Principal getPrincipal(String username) {
073: System.out.println("DavRealm.getPrincipal(" + username
074: + ") -- why is this being called?");
075:
076: if (username == null)
077: return (null);
078:
079: return new DavPrincipal(username, " ");
080: }
081:
082: /**
083: * Return the password associated with the given principal's user name.
084: */
085: protected String getPassword(String username) {
086: System.out.println("DavRealm.getPassword(" + username + ")");
087: return (null);
088: }
089:
090: /**
091: * Prepare for active use of the public methods of this Component.
092: *
093: * @exception IllegalStateException
094: * if this component has already been started
095: * @exception LifecycleException
096: * if this component detects a fatal error that prevents it from being started
097: */
098: public synchronized void start() throws LifecycleException {
099: System.out.println("DavRealm.start()");
100:
101: // Perform normal superclass initialization
102: super .start();
103: }
104:
105: /**
106: * Gracefully shut down active use of the public methods of this Component.
107: *
108: * @exception IllegalStateException
109: * if this component has not been started
110: * @exception LifecycleException
111: * if this component detects a fatal error that needs to be reported
112: */
113: public synchronized void stop() throws LifecycleException {
114: // Perform normal superclass finalization
115: super .stop();
116:
117: // No shutdown activities required
118: }
119:
120: public boolean hasRole(Principal principal, String role) {
121: return (true);
122: }
123: }
|