001package org.apache.fulcrum.security.memory.turbine; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.fulcrum.security.entity.User; 023import org.apache.fulcrum.security.memory.MemoryUserManagerImpl; 024import org.apache.fulcrum.security.model.turbine.TurbineUserManager; 025import org.apache.fulcrum.security.util.DataBackendException; 026import org.apache.fulcrum.security.util.UnknownEntityException; 027import org.apache.commons.lang3.StringUtils; 028 029/** 030 * This implementation keeps all objects in memory. This is mostly meant to help 031 * with testing and prototyping of ideas. 032 * 033 * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a> 034 * @version $Id: MemoryTurbineUserManagerImpl.java 535465 2007-05-05 06:58:06Z 035 * tv $ 036 */ 037public class MemoryTurbineUserManagerImpl extends MemoryUserManagerImpl implements TurbineUserManager { 038 039 // TODO Need to load up Crypto component and actually encrypt passwords! 040 041 /** 042 * Constructs an User object to represent an anonymous user of the application. 043 * 044 * @return An anonymous Turbine User. 045 * @throws UnknownEntityException if the implementation of User interface could 046 * not be determined, or does not exist. 047 */ 048 @Override 049 public <T extends User> T getAnonymousUser() throws UnknownEntityException { 050 T user; 051 try { 052 user = getUserInstance(); 053 } catch (DataBackendException dbe) { 054 throw new UnknownEntityException("Could not create an anonymous user.", dbe); 055 } 056 057 user.setName(""); 058 return user; 059 } 060 061 /** 062 * Checks whether a passed user object matches the anonymous user pattern 063 * according to the configured user manager 064 * 065 * @param user An user object 066 * @return <code>true</code> if this is an anonymous user 067 * 068 */ 069 @Override 070 public boolean isAnonymousUser(User user) { 071 // Test if we have an anonymous user obj 072 boolean isAnon = false; 073 if ( user == null ) { 074 isAnon = true; 075 } else { 076 if ( StringUtils.isEmpty( user.getName() ) ) 077 isAnon = true; 078 else 079 { 080 // Turbine 4.0 and great allows for a user stored in table called "anon" 081 if ( user.getName().equals("anon") ) 082 isAnon = true; 083 } 084 } 085 return isAnon; 086 } 087 088}