1 /**************************************************************** 2 * Licensed to the Apache Software Foundation (ASF) under one * 3 * or more contributor license agreements. See the NOTICE file * 4 * distributed with this work for additional information * 5 * regarding copyright ownership. The ASF licenses this file * 6 * to you under the Apache License, Version 2.0 (the * 7 * "License"); you may not use this file except in compliance * 8 * with the License. You may obtain a copy of the License at * 9 * * 10 * http://www.apache.org/licenses/LICENSE-2.0 * 11 * * 12 * Unless required by applicable law or agreed to in writing, * 13 * software distributed under the License is distributed on an * 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * 15 * KIND, either express or implied. See the License for the * 16 * specific language governing permissions and limitations * 17 * under the License. * 18 ****************************************************************/ 19 20 21 22 package org.apache.james.userrepository; 23 24 import org.apache.james.api.user.User; 25 import org.apache.james.impl.user.DefaultUser; 26 27 import java.sql.PreparedStatement; 28 import java.sql.ResultSet; 29 import java.sql.SQLException; 30 31 /** 32 * A very lightweight UserRepository, which persists a list 33 * of user names in a database. Password information is not 34 * persisted. 35 * 36 */ 37 public class ListUsersJdbcRepository extends AbstractJdbcUsersRepository 38 { 39 40 41 /** 42 * @see org.apache.james.impl.jamesuser.AbstractUsersRepository#test(java.lang.String, java.lang.String) 43 */ 44 public boolean test(String name, String password) { 45 // list repository does not store passwords so we always return false! 46 return false; 47 } 48 49 /** 50 * @see org.apache.james.userrepository.AbstractJdbcUsersRepository#readUserFromResultSet(java.sql.ResultSet) 51 */ 52 protected User readUserFromResultSet(ResultSet rsUsers) throws SQLException { 53 // Get the username, and build a DefaultUser with it. 54 String username = rsUsers.getString(1); 55 DefaultUser user = new DefaultUser(username, "SHA"); 56 return user; 57 } 58 59 /** 60 * @see org.apache.james.userrepository.AbstractJdbcUsersRepository#setUserForInsertStatement(org.apache.james.api.user.User, java.sql.PreparedStatement) 61 */ 62 protected void setUserForInsertStatement(User user, 63 PreparedStatement userInsert) 64 throws SQLException { 65 userInsert.setString(1, user.getUserName()); 66 } 67 68 /** 69 * Set parameters of a PreparedStatement object with 70 * property values from a User instance. 71 * 72 * @param user a User instance, which should be an implementation class which 73 * is handled by this Repostory implementation. 74 * @param userUpdate a PreparedStatement initialised with SQL taken from the "update" SQL definition. 75 * @throws SQLException 76 * if an exception occurs while setting parameter values. 77 */ 78 protected void setUserForUpdateStatement(User user, 79 PreparedStatement userUpdate) 80 throws SQLException { 81 throw new UnsupportedOperationException("Can't update a List User - " + 82 "only has a single attribute."); 83 } 84 85 /** 86 * @see org.apache.james.api.user.UsersRepository#addUser(java.lang.String, java.lang.String) 87 */ 88 public boolean addUser(String username, String password) { 89 User newbie = new DefaultUser(username, "SHA"); 90 newbie.setPassword(password); 91 return addUser(newbie); 92 } 93 94 95 }