001package org.apache.archiva.redback.authentication.memory;
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.archiva.redback.authentication.AbstractAuthenticator;
023import org.apache.archiva.redback.authentication.AuthenticationDataSource;
024import org.apache.archiva.redback.authentication.AuthenticationException;
025import org.apache.archiva.redback.authentication.AuthenticationResult;
026import org.apache.archiva.redback.authentication.Authenticator;
027import org.apache.archiva.redback.authentication.PasswordBasedAuthenticationDataSource;
028import org.springframework.stereotype.Service;
029
030/**
031 * MemoryAuthenticator:
032 *
033 * @author: Jesse McConnell
034 */
035@Service("authenticator#memory")
036public class MemoryAuthenticator
037    extends AbstractAuthenticator
038    implements Authenticator
039{
040    private String login;
041
042    private String password;
043
044    public String getId()
045    {
046        return "MemoryAuthenticator";
047    }
048
049    public AuthenticationResult authenticate( AuthenticationDataSource s )
050        throws AuthenticationException
051    {
052        PasswordBasedAuthenticationDataSource source = (PasswordBasedAuthenticationDataSource) s;
053
054        login = source.getUsername();
055        password = source.getPassword();
056
057        if ( source.getPassword().equals( password ) )
058        {
059            return new AuthenticationResult( true, login, null );
060        }
061
062        return new AuthenticationResult( false, null, null );
063    }
064
065    public boolean supportsDataSource( AuthenticationDataSource source )
066    {
067        return ( source instanceof PasswordBasedAuthenticationDataSource );
068    }
069
070    public String getLogin()
071    {
072        return login;
073    }
074
075    public void setLogin( String login )
076    {
077        this.login = login;
078    }
079
080    public String getPassword()
081    {
082        return password;
083    }
084
085    public void setPassword( String password )
086    {
087        this.password = password;
088    }
089}