001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/authz/tags/sakai_2-4-1/authz-impl/impl/src/java/org/sakaiproject/authz/impl/NoSecurity.java $
003: * $Id: NoSecurity.java 16931 2006-10-10 03:47:29Z 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.authz.impl;
021:
022: import java.util.List;
023: import java.util.Vector;
024:
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027: import org.sakaiproject.authz.api.SecurityAdvisor;
028: import org.sakaiproject.authz.api.SecurityService;
029: import org.sakaiproject.user.api.User;
030: import org.sakaiproject.user.api.UserDirectoryService;
031:
032: /**
033: * <p>
034: * NoSecurity is an example implementation of the Sakai SecurityService.
035: * </p>
036: */
037: public abstract class NoSecurity implements SecurityService {
038: /** Our logger. */
039: private static Log M_log = LogFactory.getLog(NoSecurity.class);
040:
041: /**********************************************************************************************************************************************************************************************************************************************************
042: * Dependencies
043: *********************************************************************************************************************************************************************************************************************************************************/
044:
045: /**
046: * @return the UserDirectoryService collaborator.
047: */
048: protected abstract UserDirectoryService userDirectoryService();
049:
050: /**********************************************************************************************************************************************************************************************************************************************************
051: * Init and Destroy
052: *********************************************************************************************************************************************************************************************************************************************************/
053:
054: /**
055: * Final initialization, once all dependencies are set.
056: */
057: public void init() {
058: M_log.info("init()");
059: }
060:
061: /**
062: * Final cleanup.
063: */
064: public void destroy() {
065: M_log.info("destroy()");
066: }
067:
068: /**********************************************************************************************************************************************************************************************************************************************************
069: * SecurityService implementation
070: *********************************************************************************************************************************************************************************************************************************************************/
071:
072: /**
073: * Get the authenticated session user
074: *
075: * @param user
076: * If not null, use this user, else use the session one.
077: * @return the User object authenticated to the current request's session.
078: */
079: protected User getUser(User user) {
080: if (user != null)
081: return user;
082:
083: return userDirectoryService().getCurrentUser();
084: }
085:
086: /**
087: * Is this a super special super (admin) user?
088: *
089: * @return true, if the user is a cut above the rest, false if a mere mortal.
090: */
091: public boolean isSuperUser() {
092: if (M_log.isDebugEnabled())
093: M_log.debug("isSuperUser() true user: " + getUserId(null));
094: return true;
095: }
096:
097: /**
098: * {@inheritDoc}
099: */
100: public boolean isSuperUser(String userId) {
101: if (M_log.isDebugEnabled())
102: M_log.debug("isSuperUser(userId) true user: " + userId);
103: return true;
104: }
105:
106: /**
107: * Can the user in the security context unlock the lock for use with this resource?
108: *
109: * @param lock
110: * The lock id string.
111: * @param resource
112: * The resource id string, or null if no resource is involved.
113: * @return true, if the user can unlock the lock, false otherwise.
114: */
115: public boolean unlock(String lock, String resource) {
116: if (M_log.isDebugEnabled())
117: M_log.debug("unlock() true user: " + getUserId(null)
118: + " lock: " + lock + " resource: " + resource);
119: return true;
120: }
121:
122: /**
123: * Can the user in the security context unlock the lock for use with this resource?
124: *
125: * @param lock
126: * The lock id string.
127: * @param resource
128: * The resource id string, or null if no resource is involved.
129: * @return true, if the user can unlock the lock, false otherwise.
130: */
131: public boolean unlock(User user, String lock, String resource) {
132: if (M_log.isDebugEnabled())
133: M_log.debug("unlock() true user: " + getUserId(user)
134: + " lock: " + lock + " resource: " + resource);
135: return true;
136: }
137:
138: /**
139: * {@inheritDoc}
140: */
141: public boolean unlock(String userId, String lock, String resource) {
142: if (M_log.isDebugEnabled())
143: M_log.debug("unlock() true user: " + userId + " lock: "
144: + lock + " resource: " + resource);
145: return true;
146: }
147:
148: /**
149: * Access the List of Users who can unlock the lock for use with this resource.
150: *
151: * @param lock
152: * The lock id string.
153: * @param reference
154: * The resource reference string.
155: * @return A List (User) of the users can unlock the lock (may be empty).
156: */
157: public List unlockUsers(String lock, String reference) {
158: return new Vector();
159: }
160:
161: protected String getUserId(User u) {
162: User user = getUser(u);
163: if (user == null)
164: return "";
165: String id = user.getId();
166: if (id == null)
167: return "";
168: return id;
169: }
170:
171: public void pushAdvisor(SecurityAdvisor advisor) {
172: }
173:
174: public SecurityAdvisor popAdvisor() {
175: return null;
176: }
177:
178: public boolean hasAdvisors() {
179: return false;
180: }
181:
182: public void clearAdvisors() {
183: }
184: }
|