Package org.apache.james.user.jdbc

Source Code of org.apache.james.user.jdbc.ListUsersJdbcRepository

/****************************************************************
* 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.                                           *
****************************************************************/



package org.apache.james.user.jdbc;

import org.apache.james.user.api.User;
import org.apache.james.user.lib.DefaultUser;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


/**
* A very lightweight UserRepository, which persists a list
* of user names in a database. Password information is not
* persisted.
*
*/
@Deprecated
public class ListUsersJdbcRepository extends AbstractJdbcUsersRepository {

   
    /**
     * @see org.apache.james.user.lib.AbstractJamesUsersRepository#test(java.lang.String, java.lang.String)
     */
    public boolean test(String name, String password) {
        // list repository does not store passwords so we always return false!
        return false;
    }

    /**
     * @see org.apache.james.user.jdbc.AbstractJdbcUsersRepository#readUserFromResultSet(java.sql.ResultSet)
     */
    protected User readUserFromResultSet(ResultSet rsUsers) throws SQLException {
        // Get the username, and build a DefaultUser with it.
        String username = rsUsers.getString(1);
        DefaultUser user = new DefaultUser(username, "SHA");
        return user;
    }

    /**
     * @see org.apache.james.user.jdbc.AbstractJdbcUsersRepository#setUserForInsertStatement(org.apache.james.user.api.User, java.sql.PreparedStatement)
     */
    protected void setUserForInsertStatement(User user,
                                             PreparedStatement userInsert)
        throws SQLException {
        userInsert.setString(1, user.getUserName());
    }

    /**
     * Set parameters of a PreparedStatement object with
     * property values from a User instance.
     *
     * @param user       a User instance, which should be an implementation class which
     *                   is handled by this Repostory implementation.
     * @param userUpdate a PreparedStatement initialised with SQL taken from the "update" SQL definition.
     * @throws SQLException
     *                   if an exception occurs while setting parameter values.
     */
    protected void setUserForUpdateStatement(User user,
                                             PreparedStatement userUpdate)
        throws SQLException {
        throw new UnsupportedOperationException("Can't update a List User - " +
                                                "only has a single attribute.");
    }

    /**
     * @see org.apache.james.user.api.UsersRepository#addUser(java.lang.String, java.lang.String)
     */
    public boolean addUser(String username, String password)  {
        User newbie = new DefaultUser(username, "SHA");
        newbie.setPassword(password);
        return addUser(newbie);
    }


}
TOP

Related Classes of org.apache.james.user.jdbc.ListUsersJdbcRepository

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.