You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by ra...@apache.org on 2002/03/08 07:24:02 UTC
cvs commit: jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/usermanager ObjStoreUserManager.java ObjStoreUserManager.xinfo
rana_b 02/03/07 22:24:02
Added: ftpserver/src/java/org/apache/avalon/ftpserver/usermanager
ObjStoreUserManager.java ObjStoreUserManager.xinfo
Log:
first time addition
Revision Changes Path
1.1 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/usermanager/ObjStoreUserManager.java
Index: ObjStoreUserManager.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.ftpserver.usermanager;
import java.util.List;
import java.util.Iterator;
import java.util.Collections;
import java.util.ArrayList;
import org.apache.avalon.cornerstone.services.store.ObjectRepository;
import org.apache.avalon.cornerstone.services.store.Store;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
/**
* File object repository based user manager.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public
class ObjStoreUserManager extends AbstractUserManager {
protected Configuration mStoreConfig;
protected Store mStore;
protected ObjectRepository mObjectRepository;
/**
* Configure user manager
*/
public void configure(Configuration conf) throws ConfigurationException {
super.configure(conf);
mStoreConfig = conf.getChild("repository");
}
/**
* Get store manager.
*/
public void compose(ComponentManager compManager) throws ComponentException {
super.compose(compManager);
mStore = (Store) compManager.lookup(Store.class.getName());
}
/**
* Initialize object repository.
*/
public void initialize() throws Exception {
super.initialize();
mObjectRepository = (ObjectRepository) mStore.select(mStoreConfig);
}
/**
* Save user object.
*/
public synchronized void save(User usr) {
if (usr.getName() == null) {
throw new NullPointerException("User name is null.");
}
usr.setPassword(getPassword(usr));
mObjectRepository.put(usr.getName(), usr);
}
/**
* Delete an user. Removes all this user entries from the properties.
* After removing the corresponding from the properties, save the data.
*/
public synchronized void delete(String usrName) {
mObjectRepository.remove(usrName);
}
/**
* Get all user names.
*/
public synchronized List getAllUserNames() {
ArrayList usrList = new ArrayList();
Iterator nameIt = mObjectRepository.list();
while(nameIt.hasNext()) {
usrList.add(nameIt.next());
}
Collections.sort(usrList);
return usrList;
}
/**
* Load user data.
*/
public synchronized User getUserByName(String userName) {
User user = null;
if(doesExist(userName)) {
user = (User)mObjectRepository.get(userName);
}
return user;
}
/**
* User existance check
*/
public synchronized boolean doesExist(String name) {
return mObjectRepository.containsKey(name);
}
/**
* Get user password. Returns the encrypted value.
* If the password value is not null
* password = new password
* else
* if user does exist
* password = old password
* else
* password = ""
*/
private String getPassword(User usr) {
String password = usr.getPassword();
if ( (password == null) && doesExist(usr.getName()) ) {
usr = getUserByName(usr.getName());
password = usr.getPassword();
}
if (password == null) {
password = "";
}
return password;
}
/**
* User authenticate method
*/
public boolean authenticate(String userName, String password) {
User user = getUserByName(userName);
if(user == null) {
return false;
}
if(user.getIsAnonymous()) {
return true;
}
return password.equals(user.getPassword());
}
}
1.1 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/usermanager/ObjStoreUserManager.xinfo
Index: ObjStoreUserManager.xinfo
===================================================================
<?xml version="1.0"?>
<blockinfo>
<!-- section to describe block -->
<block>
<version>1.0</version>
</block>
<!-- services that are offered by this block -->
<services>
<service name="org.apache.avalon.ftpserver.usermanager.UserManagerInterface" version="1.0" />
</services>
<!-- service dependency -->
<dependencies>
<dependency>
<service name="org.apache.avalon.cornerstone.services.store.Store" version="1.0"/>
</dependency>
</dependencies>
</blockinfo>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>