From 7bc2736162d4575c03abcaeb3ae6b4efbc75ecb4 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sat, 7 Apr 2012 21:56:43 +0000 Subject: package move to o.a.a.r module redback-authentication-keys git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1310882 13f79535-47bb-0310-9956-ffa450edef68 --- .../keystore/KeyStoreAuthenticator.java | 117 +++++++++++++++++++++ .../keystore/KeyStoreAuthenticator.java | 117 --------------------- .../src/main/resources/META-INF/spring-context.xml | 2 +- 3 files changed, 118 insertions(+), 118 deletions(-) create mode 100644 redback-keys/redback-authentication-keys/src/main/java/org/apache/archiva/redback/authentication/keystore/KeyStoreAuthenticator.java delete mode 100644 redback-keys/redback-authentication-keys/src/main/java/org/codehaus/plexus/redback/authentication/keystore/KeyStoreAuthenticator.java diff --git a/redback-keys/redback-authentication-keys/src/main/java/org/apache/archiva/redback/authentication/keystore/KeyStoreAuthenticator.java b/redback-keys/redback-authentication-keys/src/main/java/org/apache/archiva/redback/authentication/keystore/KeyStoreAuthenticator.java new file mode 100644 index 000000000..910dc0fb6 --- /dev/null +++ b/redback-keys/redback-authentication-keys/src/main/java/org/apache/archiva/redback/authentication/keystore/KeyStoreAuthenticator.java @@ -0,0 +1,117 @@ +package org.apache.archiva.redback.authentication.keystore; + +/* + * 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. + */ + +import org.apache.archiva.redback.authentication.AuthenticationDataSource; +import org.apache.archiva.redback.authentication.AuthenticationException; +import org.apache.archiva.redback.authentication.AuthenticationResult; +import org.apache.archiva.redback.authentication.Authenticator; +import org.apache.archiva.redback.authentication.TokenBasedAuthenticationDataSource; +import org.apache.archiva.redback.keys.AuthenticationKey; +import org.apache.archiva.redback.keys.KeyManager; +import org.apache.archiva.redback.keys.KeyManagerException; +import org.apache.archiva.redback.keys.KeyNotFoundException; +import org.codehaus.plexus.redback.policy.AccountLockedException; +import org.codehaus.plexus.redback.policy.MustChangePasswordException; +import org.apache.archiva.redback.users.User; +import org.apache.archiva.redback.users.UserManager; +import org.apache.archiva.redback.users.UserNotFoundException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +/** + * KeyStoreAuthenticator: + * + * @author: Jesse McConnell + * @version: $Id$ + */ +@Service( "authenticator#keystore" ) +public class KeyStoreAuthenticator + implements Authenticator +{ + private Logger log = LoggerFactory.getLogger( getClass() ); + + @Resource( name = "keyManager#cached" ) + private KeyManager keystore; + + @Resource( name = "userManager#configurable" ) + private UserManager userManager; + + public String getId() + { + return "$Id$"; + } + + public AuthenticationResult authenticate( AuthenticationDataSource source ) + throws AccountLockedException, AuthenticationException, MustChangePasswordException + { + TokenBasedAuthenticationDataSource dataSource = (TokenBasedAuthenticationDataSource) source; + + String key = dataSource.getToken(); + try + { + AuthenticationKey authKey = keystore.findKey( key ); + + // if we find a key (exception was probably thrown if not) then we should be authentic + if ( authKey != null ) + { + User user = userManager.findUser( dataSource.getPrincipal() ); + + if ( user.isLocked() ) + { + throw new AccountLockedException( "Account " + source.getPrincipal() + " is locked.", user ); + } + + if ( user.isPasswordChangeRequired() && source.isEnforcePasswordChange() ) + { + throw new MustChangePasswordException( "Password expired.", user ); + } + + return new AuthenticationResult( true, dataSource.getPrincipal(), null ); + } + else + { + return new AuthenticationResult( false, dataSource.getPrincipal(), + new AuthenticationException( "unable to find key" ) ); + } + } + catch ( KeyNotFoundException ne ) + { + return new AuthenticationResult( false, null, ne ); + } + catch ( KeyManagerException ke ) + { + throw new AuthenticationException( "underlaying keymanager issue", ke ); + } + catch ( UserNotFoundException e ) + { + log.warn( "Login for user " + source.getPrincipal() + " failed. user not found." ); + return new AuthenticationResult( false, null, e ); + } + } + + public boolean supportsDataSource( AuthenticationDataSource source ) + { + return source instanceof TokenBasedAuthenticationDataSource; + } +} \ No newline at end of file diff --git a/redback-keys/redback-authentication-keys/src/main/java/org/codehaus/plexus/redback/authentication/keystore/KeyStoreAuthenticator.java b/redback-keys/redback-authentication-keys/src/main/java/org/codehaus/plexus/redback/authentication/keystore/KeyStoreAuthenticator.java deleted file mode 100644 index f2906879d..000000000 --- a/redback-keys/redback-authentication-keys/src/main/java/org/codehaus/plexus/redback/authentication/keystore/KeyStoreAuthenticator.java +++ /dev/null @@ -1,117 +0,0 @@ -package org.codehaus.plexus.redback.authentication.keystore; - -/* - * 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. - */ - -import org.apache.archiva.redback.authentication.AuthenticationDataSource; -import org.apache.archiva.redback.authentication.AuthenticationException; -import org.apache.archiva.redback.authentication.AuthenticationResult; -import org.apache.archiva.redback.authentication.Authenticator; -import org.apache.archiva.redback.authentication.TokenBasedAuthenticationDataSource; -import org.apache.archiva.redback.keys.AuthenticationKey; -import org.apache.archiva.redback.keys.KeyManager; -import org.apache.archiva.redback.keys.KeyManagerException; -import org.apache.archiva.redback.keys.KeyNotFoundException; -import org.codehaus.plexus.redback.policy.AccountLockedException; -import org.codehaus.plexus.redback.policy.MustChangePasswordException; -import org.apache.archiva.redback.users.User; -import org.apache.archiva.redback.users.UserManager; -import org.apache.archiva.redback.users.UserNotFoundException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Service; - -import javax.annotation.Resource; - -/** - * KeyStoreAuthenticator: - * - * @author: Jesse McConnell - * @version: $Id$ - */ -@Service( "authenticator#keystore" ) -public class KeyStoreAuthenticator - implements Authenticator -{ - private Logger log = LoggerFactory.getLogger( getClass() ); - - @Resource( name = "keyManager#cached" ) - private KeyManager keystore; - - @Resource( name = "userManager#configurable" ) - private UserManager userManager; - - public String getId() - { - return "$Id$"; - } - - public AuthenticationResult authenticate( AuthenticationDataSource source ) - throws AccountLockedException, AuthenticationException, MustChangePasswordException - { - TokenBasedAuthenticationDataSource dataSource = (TokenBasedAuthenticationDataSource) source; - - String key = dataSource.getToken(); - try - { - AuthenticationKey authKey = keystore.findKey( key ); - - // if we find a key (exception was probably thrown if not) then we should be authentic - if ( authKey != null ) - { - User user = userManager.findUser( dataSource.getPrincipal() ); - - if ( user.isLocked() ) - { - throw new AccountLockedException( "Account " + source.getPrincipal() + " is locked.", user ); - } - - if ( user.isPasswordChangeRequired() && source.isEnforcePasswordChange() ) - { - throw new MustChangePasswordException( "Password expired.", user ); - } - - return new AuthenticationResult( true, dataSource.getPrincipal(), null ); - } - else - { - return new AuthenticationResult( false, dataSource.getPrincipal(), - new AuthenticationException( "unable to find key" ) ); - } - } - catch ( KeyNotFoundException ne ) - { - return new AuthenticationResult( false, null, ne ); - } - catch ( KeyManagerException ke ) - { - throw new AuthenticationException( "underlaying keymanager issue", ke ); - } - catch ( UserNotFoundException e ) - { - log.warn( "Login for user " + source.getPrincipal() + " failed. user not found." ); - return new AuthenticationResult( false, null, e ); - } - } - - public boolean supportsDataSource( AuthenticationDataSource source ) - { - return source instanceof TokenBasedAuthenticationDataSource; - } -} \ No newline at end of file diff --git a/redback-keys/redback-authentication-keys/src/main/resources/META-INF/spring-context.xml b/redback-keys/redback-authentication-keys/src/main/resources/META-INF/spring-context.xml index 0b7db173f..9f1df8757 100644 --- a/redback-keys/redback-authentication-keys/src/main/resources/META-INF/spring-context.xml +++ b/redback-keys/redback-authentication-keys/src/main/resources/META-INF/spring-context.xml @@ -29,6 +29,6 @@ + base-package="org.apache.archiva.redback.authentication.keystore"/> \ No newline at end of file -- cgit v1.2.3