FileDocCategorySizeDatePackage
MockUsersRepository.javaAPI DocApache James 2.3.15325Fri Jan 12 12:56:38 GMT 2007org.apache.james.userrepository

MockUsersRepository

public class MockUsersRepository extends Object implements org.apache.james.services.UsersRepository
Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. *

Fields Summary
private final HashMap
m_users
private boolean
m_forceUseJamesUser
force the repository to hold implementations of JamesUser interface, instead of User JamesUser is _not_ required as of the UsersRepository interface, so the necessarity forcing it is due to code using UsersRepository while at the same time expecting it to hold JamesUsers (like in RemoteManagerHandler)
Constructors Summary
Methods Summary
public booleanaddUser(org.apache.james.services.User user)


        if (m_forceUseJamesUser && user instanceof DefaultUser ) {
            DefaultUser aUser = (DefaultUser)user;
            user = new DefaultJamesUser(aUser.getUserName(),
                                             aUser.getHashedPassword(),
                                             aUser.getHashAlgorithm());
        }

        String key = user.getUserName();
        if (m_users.containsKey(key)) return false;
        m_users.put(key, user);
        return true;
    
public voidaddUser(java.lang.String name, java.lang.Object attributes)

        try {
            String passwordHash = DigestUtil.digestString(((String) attributes), "SHA");

            User user;

            if (m_forceUseJamesUser) {
                user = new DefaultJamesUser(name, passwordHash, "SHA");
            } else {
                user = new DefaultUser(name, passwordHash, "SHA");
            }
           
            addUser(user);
        } catch (Exception e) {
            e.printStackTrace();  // encoding failed
        }
    
public booleanaddUser(java.lang.String username, java.lang.String password)

        if (m_users.containsKey(username)) return false;
        try {
            String passwordHash = DigestUtil.digestString((password), "SHA");

            User user;

            if (m_forceUseJamesUser) {
                user = new DefaultJamesUser(username, passwordHash, "SHA");
            } else {
                user = new DefaultUser(username, passwordHash, "SHA");
            }
           
            return addUser(user);
        } catch (Exception e) {
            e.printStackTrace();  // encoding failed
        }
        return false;
    
public booleancontains(java.lang.String name)

        return m_users.containsKey(name);
    
public booleancontainsCaseInsensitive(java.lang.String name)

        return false;  // trivial implementation
    
public intcountUsers()

        return m_users.size();
    
public java.lang.ObjectgetAttributes(java.lang.String name)

        return null;  // trivial implementation
    
public java.lang.StringgetRealName(java.lang.String name)

        return ((User) m_users.get(name)).getUserName();
    
public org.apache.james.services.UsergetUserByName(java.lang.String name)

        return (User) m_users.get(name);
    
public org.apache.james.services.UsergetUserByNameCaseInsensitive(java.lang.String name)

        return null;  // trivial implementation
    
public java.util.Iteratorlist()

        return listUserNames().iterator(); 
    
protected java.util.ListlistUserNames()

        Iterator users = m_users.values().iterator();
        List userNames = new LinkedList();
        while ( users.hasNext() ) {
            User user = (User)users.next();
            userNames.add(user.getUserName());
        }

        return userNames;
    
public voidremoveUser(java.lang.String name)

        m_users.remove(name);
    
public voidsetForceUseJamesUser()


       
        m_forceUseJamesUser = true;
    
public booleantest(java.lang.String name, java.lang.Object attributes)

        return false;  // trivial implementation
    
public booleantest(java.lang.String name, java.lang.String password)

        User user = getUserByName(name);
        if (user == null) return false;
        return user.verifyPassword(password);
    
public booleanupdateUser(org.apache.james.services.User user)

        return false;  // trivial implementation