import of redback core sources
http://svn.codehaus.org/redback/redback/trunk/ r1724 git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1310268 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
be9e1800fd
commit
5b06b6673e
|
@ -0,0 +1,17 @@
|
|||
target
|
||||
*.iml
|
||||
out
|
||||
.idea
|
||||
.project
|
||||
.settings
|
||||
.classpath
|
||||
derby.log
|
||||
redback-integrations/redback-struts2/redback-struts2-example/src/main/webapp/META-INF/
|
||||
redback-integrations/redback-struts2/redback-struts2-example/src/main/webapp/WEB-INF/classes/
|
||||
redback-integrations/redback-struts2/redback-struts2-example/src/main/webapp/WEB-INF/jsp/redback/
|
||||
redback-integrations/redback-struts2/redback-struts2-example/src/main/webapp/css/redback/
|
||||
redback-integrations/redback-struts2/redback-struts2-example/src/main/webapp/images/
|
||||
redback-integrations/redback-struts2/redback-struts2-example/src/main/webapp/template/
|
||||
redback-integrations/redback-struts2/redback-struts2-example/appserver-base
|
||||
redback-integrations/redback-struts2/redback-struts2-example/overlays/
|
||||
.DS_Store
|
|
@ -0,0 +1,13 @@
|
|||
Copyright 2006 The Codehaus.
|
||||
|
||||
Licensed 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.
|
|
@ -0,0 +1,39 @@
|
|||
#!/bin/bash
|
||||
|
||||
# How to execute
|
||||
# export PSEC_HOME=`pwd`
|
||||
# find . -name "pom.xml" -print -exec $PSEC_HOME/fixscm.sh {} \;
|
||||
|
||||
POM=$1
|
||||
|
||||
if [ ! -f $POM ] ; then
|
||||
echo "ERROR: Unable to find pom - $POM"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BASEDIR=`dirname $POM`
|
||||
NOW=`date +%Y%m%d.%H%M%S`
|
||||
|
||||
CURDIR=`pwd`
|
||||
cd `dirname $0`
|
||||
SCRIPTHOME=`pwd`
|
||||
cd $BASEDIR
|
||||
|
||||
SVNURL=`svn info | grep URL | sed -e "s@URL: http[s]://@@"`
|
||||
FISHEYEURL=`echo $SVNURL | sed -e "s@svn.codehaus.org@fisheye.codehaus.org/browse@g"`
|
||||
|
||||
BACKUP=pom.xml-${NOW}~
|
||||
|
||||
POMFILE=`basename $POM`
|
||||
|
||||
cp $POMFILE $BACKUP
|
||||
|
||||
SCRIPTHOME=`dirname $SCRIPTHOME`
|
||||
POMREL=`pwd | sed -e "s@$SCRIPTHOME@@"`
|
||||
|
||||
echo "Fixing <scm> in $POMREL/pom.xml"
|
||||
|
||||
cat $BACKUP | sed -e "s@scm:svn:\(http[s]*\)[^< ]*@scm:svn:\1://$SVNURL@g" | sed "s@http://fisheye[^<]*@http://$FISHEYEURL@g" > pom.xml
|
||||
|
||||
cd $CURDIR
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 2006 The Codehaus.
|
||||
~
|
||||
~ Licensed 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.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback</artifactId>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>redback-authentication</artifactId>
|
||||
<name>Redback :: Authentication</name>
|
||||
<packaging>pom</packaging>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-users-api</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<modules>
|
||||
<module>redback-authentication-api</module>
|
||||
<module>redback-authentication-providers</module>
|
||||
</modules>
|
||||
</project>
|
|
@ -0,0 +1,44 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 2006 The Codehaus.
|
||||
~
|
||||
~ Licensed 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.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-authentication</artifactId>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>redback-authentication-api</artifactId>
|
||||
<name>Redback :: Authentication API</name>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-policy</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.inject</groupId>
|
||||
<artifactId>javax.inject</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.annotation</groupId>
|
||||
<artifactId>jsr250-api</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,29 @@
|
|||
package org.codehaus.plexus.redback.authentication;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2006 The Codehaus.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Contants class used for authentication
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AuthenticationConstants
|
||||
{
|
||||
|
||||
// for User Manager Authenticator
|
||||
public static final String AUTHN_NO_SUCH_USER = "1";
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package org.codehaus.plexus.redback.authentication;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2006 The Codehaus.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Just a tag to indicate that the implementing class is an AuthenticationDataSource.
|
||||
*
|
||||
* todo which this back to an interface and use the mojo style expression evaluation to populate the particular required fields
|
||||
* @see PasswordBasedAuthenticationDataSource
|
||||
* @see TokenBasedAuthenticationDataSource
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface AuthenticationDataSource
|
||||
{
|
||||
public String ROLE = AuthenticationDataSource.class.getName();
|
||||
|
||||
public String getPrincipal();
|
||||
|
||||
public boolean isEnforcePasswordChange();
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package org.codehaus.plexus.redback.authentication;
|
||||
|
||||
/*
|
||||
* Copyright 2005 The Codehaus.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* AuthenticationException.java
|
||||
*
|
||||
* @author Jesse McConnell
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AuthenticationException
|
||||
extends Exception
|
||||
{
|
||||
/**
|
||||
* Constructor AuthenticationException.
|
||||
*/
|
||||
public AuthenticationException()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor AuthenticationException.
|
||||
*
|
||||
* @param message
|
||||
*/
|
||||
public AuthenticationException( String message )
|
||||
{
|
||||
super( message );
|
||||
}
|
||||
|
||||
public AuthenticationException( String message, Throwable cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
|
||||
public AuthenticationException( Throwable cause )
|
||||
{
|
||||
super( cause );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package org.codehaus.plexus.redback.authentication;
|
||||
|
||||
/*
|
||||
* Copyright 2005 The Codehaus.
|
||||
*
|
||||
* Licensed 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.codehaus.plexus.redback.policy.AccountLockedException;
|
||||
import org.codehaus.plexus.redback.policy.MustChangePasswordException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* AuthenticationManager:
|
||||
*
|
||||
* @author: Jesse McConnell <jesse@codehaus.org>
|
||||
* @version: $Id$
|
||||
*/
|
||||
public interface AuthenticationManager
|
||||
{
|
||||
String getId();
|
||||
|
||||
List<Authenticator> getAuthenticators();
|
||||
|
||||
AuthenticationResult authenticate( AuthenticationDataSource source )
|
||||
throws AccountLockedException, AuthenticationException, MustChangePasswordException;
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
package org.codehaus.plexus.redback.authentication;
|
||||
|
||||
/*
|
||||
* Copyright 2005 The Codehaus.
|
||||
*
|
||||
* Licensed 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 java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* AuthenticationResult: wrapper object for information that comes back from the authentication system
|
||||
*
|
||||
* @author Jesse McConnell <jesse@codehaus.org>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AuthenticationResult
|
||||
implements Serializable
|
||||
{
|
||||
private boolean isAuthenticated;
|
||||
|
||||
/**
|
||||
* FIXME olamy this Object is a pain !!!
|
||||
*/
|
||||
private Object principal;
|
||||
|
||||
// TODO: why aren't these just thrown from the authenticate() method?
|
||||
private Exception exception;
|
||||
|
||||
private Map<String,String> exceptionsMap;
|
||||
|
||||
public AuthenticationResult()
|
||||
{
|
||||
this.isAuthenticated = false;
|
||||
this.principal = null;
|
||||
this.exception = null;
|
||||
}
|
||||
|
||||
public AuthenticationResult( boolean authenticated, Object principal, Exception exception )
|
||||
{
|
||||
isAuthenticated = authenticated;
|
||||
this.principal = principal;
|
||||
this.exception = exception;
|
||||
}
|
||||
|
||||
public AuthenticationResult( boolean authenticated, Object principal, Exception exception, Map<String,String> exceptionsMap )
|
||||
{
|
||||
isAuthenticated = authenticated;
|
||||
this.principal = principal;
|
||||
this.exception = exception;
|
||||
this.exceptionsMap = exceptionsMap;
|
||||
}
|
||||
|
||||
public boolean isAuthenticated()
|
||||
{
|
||||
return isAuthenticated;
|
||||
}
|
||||
|
||||
public Object getPrincipal()
|
||||
{
|
||||
return principal;
|
||||
}
|
||||
|
||||
public Exception getException()
|
||||
{
|
||||
return exception;
|
||||
}
|
||||
|
||||
public Map<String,String> getExceptionsMap()
|
||||
{
|
||||
return exceptionsMap;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append( "AuthenticationResult[" );
|
||||
sb.append( "principal=" ).append( principal );
|
||||
sb.append( ",isAuthenticated=" ).append( Boolean.toString( isAuthenticated ) );
|
||||
sb.append( ",exception=" );
|
||||
if ( exception != null )
|
||||
{
|
||||
sb.append( exception.getClass().getName() );
|
||||
sb.append( " : " ).append( exception.getMessage() );
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.append( "<null>" );
|
||||
}
|
||||
sb.append( ']' );
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package org.codehaus.plexus.redback.authentication;
|
||||
|
||||
/*
|
||||
* Copyright 2005 The Codehaus.
|
||||
*
|
||||
* Licensed 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.codehaus.plexus.redback.policy.AccountLockedException;
|
||||
import org.codehaus.plexus.redback.policy.MustChangePasswordException;
|
||||
|
||||
/**
|
||||
* Authenticator:
|
||||
*
|
||||
* @author Jesse McConnell
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface Authenticator
|
||||
{
|
||||
String getId();
|
||||
|
||||
boolean supportsDataSource( AuthenticationDataSource source );
|
||||
|
||||
AuthenticationResult authenticate( AuthenticationDataSource source )
|
||||
throws AccountLockedException, AuthenticationException, MustChangePasswordException;
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
package org.codehaus.plexus.redback.authentication;
|
||||
|
||||
/*
|
||||
* Copyright 2005 The Codehaus.
|
||||
*
|
||||
* Licensed 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.codehaus.plexus.redback.policy.AccountLockedException;
|
||||
import org.codehaus.plexus.redback.policy.MustChangePasswordException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* DefaultAuthenticationManager: the goal of the authentication manager is to act as a conduit for
|
||||
* authentication requests into different authentication schemes
|
||||
* <p/>
|
||||
* For example, the default implementation can be configured with any number of authenticators and will
|
||||
* sequentially try them for an authenticated result. This allows you to have the standard user/pass
|
||||
* auth procedure followed by authentication based on a known key for 'remember me' type functionality.
|
||||
*
|
||||
* @author: Jesse McConnell <jesse@codehaus.org>
|
||||
* @version: $Id$
|
||||
*/
|
||||
@Service("authenticationManager")
|
||||
public class DefaultAuthenticationManager
|
||||
implements AuthenticationManager
|
||||
{
|
||||
|
||||
private List<Authenticator> authenticators;
|
||||
|
||||
@Inject
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@PostConstruct
|
||||
public void initialize()
|
||||
{
|
||||
this.authenticators = new ArrayList<Authenticator>
|
||||
( applicationContext.getBeansOfType( Authenticator.class ).values() );
|
||||
}
|
||||
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return "Default Authentication Manager - " + this.getClass().getName() + " : managed authenticators - " +
|
||||
knownAuthenticators();
|
||||
}
|
||||
|
||||
public AuthenticationResult authenticate( AuthenticationDataSource source )
|
||||
throws AccountLockedException, AuthenticationException, MustChangePasswordException
|
||||
{
|
||||
if ( authenticators == null || authenticators.size() == 0 )
|
||||
{
|
||||
return ( new AuthenticationResult( false, null, new AuthenticationException(
|
||||
"no valid authenticators, can't authenticate" ) ) );
|
||||
}
|
||||
|
||||
// put AuthenticationResult exceptions in a map
|
||||
Map<String,String> authnResultExceptionsMap = new HashMap<String,String>();
|
||||
for ( Authenticator authenticator : authenticators )
|
||||
{
|
||||
if ( authenticator.supportsDataSource( source ) )
|
||||
{
|
||||
AuthenticationResult authResult = authenticator.authenticate( source );
|
||||
Map<String,String> exceptionsMap = authResult.getExceptionsMap();
|
||||
|
||||
if ( authResult.isAuthenticated() )
|
||||
{
|
||||
return authResult;
|
||||
}
|
||||
|
||||
if ( exceptionsMap != null )
|
||||
{
|
||||
authnResultExceptionsMap.putAll( exceptionsMap );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ( new AuthenticationResult( false, null, new AuthenticationException(
|
||||
"authentication failed on authenticators: " + knownAuthenticators() ), authnResultExceptionsMap ) );
|
||||
}
|
||||
|
||||
public List<Authenticator> getAuthenticators()
|
||||
{
|
||||
return authenticators;
|
||||
}
|
||||
|
||||
private String knownAuthenticators()
|
||||
{
|
||||
StringBuffer strbuf = new StringBuffer();
|
||||
|
||||
for ( Authenticator authenticator : authenticators )
|
||||
{
|
||||
strbuf.append( '(' ).append( authenticator.getId() ).append( ") " );
|
||||
}
|
||||
|
||||
return strbuf.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package org.codehaus.plexus.redback.authentication;
|
||||
/*
|
||||
* Copyright 2005 The Codehaus.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* EntityAuthenticationException.java
|
||||
*
|
||||
* @author Dan Diephouse
|
||||
* @since $Id$
|
||||
*/
|
||||
public class NotAuthenticatedException
|
||||
extends Exception
|
||||
{
|
||||
/**
|
||||
* Constructor EntityAuthenticationException.
|
||||
*/
|
||||
public NotAuthenticatedException()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor EntityAuthenticationException.
|
||||
*
|
||||
* @param message
|
||||
*/
|
||||
public NotAuthenticatedException( String message )
|
||||
{
|
||||
super( message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor EntityAuthenticationException.
|
||||
*
|
||||
* @param message
|
||||
* @param cause
|
||||
*/
|
||||
public NotAuthenticatedException( String message, Exception cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
package org.codehaus.plexus.redback.authentication;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2006 The Codehaus.
|
||||
*
|
||||
* Licensed 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.commons.lang.StringUtils;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* PasswordBasedAuthenticationDataSource: the username is considered the principal with this data source
|
||||
*
|
||||
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
*
|
||||
*/
|
||||
@Service("authenticationDataSource#password")
|
||||
@Scope("prototype")
|
||||
public class PasswordBasedAuthenticationDataSource
|
||||
implements AuthenticationDataSource
|
||||
{
|
||||
private String password;
|
||||
|
||||
private String principal;
|
||||
|
||||
public PasswordBasedAuthenticationDataSource()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public PasswordBasedAuthenticationDataSource( String principal, String password )
|
||||
{
|
||||
this.principal = principal;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getPassword()
|
||||
{
|
||||
return password;
|
||||
}
|
||||
|
||||
public String getPrincipal()
|
||||
{
|
||||
return principal;
|
||||
}
|
||||
|
||||
public void setPassword( String password )
|
||||
{
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public void setPrincipal( String principal )
|
||||
{
|
||||
this.principal = principal;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append( "PasswordBasedAuthenticationDataSource[" );
|
||||
sb.append( "principal=" ).append( principal );
|
||||
sb.append( ",password=" );
|
||||
if ( StringUtils.isNotEmpty( password ) )
|
||||
{
|
||||
// Intentionally not showing real password
|
||||
sb.append( "***" );
|
||||
}
|
||||
sb.append( ']' );
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public boolean isEnforcePasswordChange()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
package org.codehaus.plexus.redback.authentication;
|
||||
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2006 The Codehaus.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* TokenBasedAuthenticationDataSource
|
||||
*
|
||||
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
*
|
||||
*/
|
||||
@Service("authenticationDataSource#token")
|
||||
@Scope("prototype")
|
||||
public class TokenBasedAuthenticationDataSource
|
||||
implements AuthenticationDataSource
|
||||
{
|
||||
private String token;
|
||||
|
||||
private String principal;
|
||||
|
||||
private boolean enforcePasswordChange = true;
|
||||
|
||||
public TokenBasedAuthenticationDataSource( String principal )
|
||||
{
|
||||
this.principal = principal;
|
||||
}
|
||||
|
||||
public TokenBasedAuthenticationDataSource()
|
||||
{
|
||||
}
|
||||
|
||||
public String getPrincipal()
|
||||
{
|
||||
return principal;
|
||||
}
|
||||
|
||||
public String getToken()
|
||||
{
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setPrincipal( String principal )
|
||||
{
|
||||
this.principal = principal;
|
||||
}
|
||||
|
||||
public void setToken( String token )
|
||||
{
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append( "TokenBasedAuthenticationDataSource[" );
|
||||
sb.append( "principal=" ).append( principal );
|
||||
sb.append( ",token=" ).append( token );
|
||||
sb.append( ']' );
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public void setEnforcePasswordChange( boolean enforcePasswordChange )
|
||||
{
|
||||
this.enforcePasswordChange = enforcePasswordChange;
|
||||
}
|
||||
|
||||
public boolean isEnforcePasswordChange()
|
||||
{
|
||||
return enforcePasswordChange;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-2.5.xsd"
|
||||
default-lazy-init="true">
|
||||
|
||||
<context:annotation-config />
|
||||
<context:component-scan
|
||||
base-package="org.codehaus.plexus.redback.authentication"/>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 2006 The Codehaus.
|
||||
~
|
||||
~ Licensed 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.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-authentication</artifactId>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>redback-authentication-providers</artifactId>
|
||||
<name>Redback :: Authentication Providers</name>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>redback-authentication-open</module>
|
||||
<module>redback-authentication-memory</module>
|
||||
<module>redback-authentication-ldap</module>
|
||||
</modules>
|
||||
</project>
|
|
@ -0,0 +1,120 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 2006 The Codehaus.
|
||||
~
|
||||
~ Licensed 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.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-authentication-providers</artifactId>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>redback-authentication-ldap</artifactId>
|
||||
<name>Redback :: Authentication Provider :: Ldap</name>
|
||||
<properties>
|
||||
<apacheds.version>1.5.1</apacheds.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-authentication-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-common-ldap</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-policy</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-users-ldap</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.annotation</groupId>
|
||||
<artifactId>jsr250-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.inject</groupId>
|
||||
<artifactId>javax.inject</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.directory.server</groupId>
|
||||
<artifactId>apacheds-core</artifactId>
|
||||
<version>${apacheds.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback.components</groupId>
|
||||
<artifactId>spring-apacheds</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.sonatype.plugins</groupId>
|
||||
<artifactId>port-allocator-maven-plugin</artifactId>
|
||||
<version>1.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>allocate-ldap-port</id>
|
||||
<phase>process-classes</phase>
|
||||
<goals>
|
||||
<goal>allocate-ports</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<ports>
|
||||
<port>
|
||||
<name>ldapPort</name>
|
||||
<portNumber>10390</portNumber>
|
||||
</port>
|
||||
</ports>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<ldapPort>${ldapPort}</ldapPort>
|
||||
<basedir>${basedir}</basedir>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,201 @@
|
|||
package org.codehaus.plexus.redback.authentication.ldap;
|
||||
|
||||
/*
|
||||
* Copyright 2005 The Codehaus.
|
||||
*
|
||||
* Licensed 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.commons.lang.StringUtils;
|
||||
import org.codehaus.plexus.redback.authentication.AuthenticationDataSource;
|
||||
import org.codehaus.plexus.redback.authentication.AuthenticationException;
|
||||
import org.codehaus.plexus.redback.authentication.AuthenticationResult;
|
||||
import org.codehaus.plexus.redback.authentication.Authenticator;
|
||||
import org.codehaus.plexus.redback.authentication.PasswordBasedAuthenticationDataSource;
|
||||
import org.codehaus.plexus.redback.common.ldap.UserMapper;
|
||||
import org.codehaus.plexus.redback.common.ldap.connection.LdapConnection;
|
||||
import org.codehaus.plexus.redback.common.ldap.connection.LdapConnectionFactory;
|
||||
import org.codehaus.plexus.redback.common.ldap.connection.LdapException;
|
||||
import org.codehaus.plexus.redback.configuration.UserConfiguration;
|
||||
import org.codehaus.plexus.redback.users.ldap.service.LdapCacheService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.directory.SearchControls;
|
||||
import javax.naming.directory.SearchResult;
|
||||
|
||||
/**
|
||||
* LdapBindAuthenticator:
|
||||
*
|
||||
* @author: Jesse McConnell <jesse@codehaus.org>
|
||||
* @version: $Id$
|
||||
*/
|
||||
@Service( "authenticator#ldap" )
|
||||
public class LdapBindAuthenticator
|
||||
implements Authenticator
|
||||
{
|
||||
|
||||
private Logger log = LoggerFactory.getLogger( getClass() );
|
||||
|
||||
@Inject
|
||||
@Named( value = "userMapper#ldap" )
|
||||
private UserMapper mapper;
|
||||
|
||||
@Inject
|
||||
@Named( value = "ldapConnectionFactory#configurable" )
|
||||
private LdapConnectionFactory connectionFactory;
|
||||
|
||||
@Inject
|
||||
@Named( value = "userConfiguration" )
|
||||
private UserConfiguration config;
|
||||
|
||||
@Inject
|
||||
private LdapCacheService ldapCacheService;
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return "LdapBindAuthenticator";
|
||||
}
|
||||
|
||||
public AuthenticationResult authenticate( AuthenticationDataSource s )
|
||||
throws AuthenticationException
|
||||
{
|
||||
PasswordBasedAuthenticationDataSource source = (PasswordBasedAuthenticationDataSource) s;
|
||||
|
||||
if ( !config.getBoolean( "ldap.bind.authenticator.enabled" ) || (
|
||||
!config.getBoolean( "ldap.bind.authenticator.allowEmptyPasswords", false ) && StringUtils.isEmpty(
|
||||
source.getPassword() ) ) )
|
||||
{
|
||||
return new AuthenticationResult( false, source.getPrincipal(), null );
|
||||
}
|
||||
|
||||
SearchControls ctls = new SearchControls();
|
||||
|
||||
ctls.setCountLimit( 1 );
|
||||
|
||||
ctls.setDerefLinkFlag( true );
|
||||
ctls.setSearchScope( SearchControls.SUBTREE_SCOPE );
|
||||
|
||||
String filter = "(&(objectClass=" + mapper.getUserObjectClass() + ")"
|
||||
+ ( mapper.getUserFilter() != null ? mapper.getUserFilter() : "" ) + "(" + mapper.getUserIdAttribute() + "="
|
||||
+ source.getPrincipal() + "))";
|
||||
|
||||
log.info( "Searching for users with filter: \'{}\'" + " from base dn: {}", filter, mapper.getUserBaseDn() );
|
||||
|
||||
LdapConnection ldapConnection = getLdapConnection();
|
||||
LdapConnection authLdapConnection = null;
|
||||
NamingEnumeration<SearchResult> results = null;
|
||||
try
|
||||
{
|
||||
// check the cache for user's userDn in the ldap server
|
||||
String userDn = ldapCacheService.getLdapUserDn( source.getPrincipal() );
|
||||
|
||||
if( userDn == null )
|
||||
{
|
||||
log.debug( "userDn for user {} not found in cache. Retrieving from ldap server..", source.getPrincipal() );
|
||||
|
||||
DirContext context = ldapConnection.getDirContext();
|
||||
|
||||
results = context.search( mapper.getUserBaseDn(), filter, ctls );
|
||||
|
||||
log.info( "Found user?: {}", results.hasMoreElements() );
|
||||
|
||||
if ( results.hasMoreElements() )
|
||||
{
|
||||
SearchResult result = results.nextElement();
|
||||
|
||||
userDn = result.getNameInNamespace();
|
||||
|
||||
log.debug( "Adding userDn {} for user {} to the cache..", userDn, source.getPrincipal() );
|
||||
|
||||
// REDBACK-289/MRM-1488 cache the ldap user's userDn to lessen calls to ldap server
|
||||
ldapCacheService.addLdapUserDn( source.getPrincipal(), userDn );
|
||||
}
|
||||
else
|
||||
{
|
||||
return new AuthenticationResult( false, source.getPrincipal(), null );
|
||||
}
|
||||
}
|
||||
|
||||
log.info( "Attempting Authenication: + {}", userDn );
|
||||
|
||||
authLdapConnection = connectionFactory.getConnection( userDn, source.getPassword() );
|
||||
|
||||
return new AuthenticationResult( true, source.getPrincipal(), null );
|
||||
}
|
||||
catch ( LdapException e )
|
||||
{
|
||||
return new AuthenticationResult( false, source.getPrincipal(), e );
|
||||
}
|
||||
catch ( NamingException e )
|
||||
{
|
||||
return new AuthenticationResult( false, source.getPrincipal(), e );
|
||||
}
|
||||
finally
|
||||
{
|
||||
closeNamingEnumeration( results );
|
||||
closeLdapConnection( ldapConnection );
|
||||
if ( authLdapConnection != null )
|
||||
{
|
||||
closeLdapConnection( authLdapConnection );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean supportsDataSource( AuthenticationDataSource source )
|
||||
{
|
||||
return ( source instanceof PasswordBasedAuthenticationDataSource );
|
||||
}
|
||||
|
||||
private LdapConnection getLdapConnection()
|
||||
{
|
||||
try
|
||||
{
|
||||
return connectionFactory.getConnection();
|
||||
}
|
||||
catch ( LdapException e )
|
||||
{
|
||||
log.warn( "failed to get a ldap connection " + e.getMessage(), e );
|
||||
throw new RuntimeException( "failed to get a ldap connection " + e.getMessage(), e );
|
||||
}
|
||||
}
|
||||
|
||||
private void closeLdapConnection( LdapConnection ldapConnection )
|
||||
{
|
||||
if ( ldapConnection != null )
|
||||
{
|
||||
ldapConnection.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void closeNamingEnumeration( NamingEnumeration<SearchResult> results )
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( results != null )
|
||||
{
|
||||
results.close();
|
||||
}
|
||||
}
|
||||
catch ( NamingException e )
|
||||
{
|
||||
log.warn( "skip exception closing naming search result " + e.getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-2.5.xsd"
|
||||
default-lazy-init="true">
|
||||
|
||||
<context:annotation-config />
|
||||
<context:component-scan
|
||||
base-package="org.codehaus.plexus.redback.authentication.ldap"/>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,210 @@
|
|||
package org.codehaus.plexus.redback.authentication.ldap;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2006 The Codehaus.
|
||||
*
|
||||
* Licensed 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 junit.framework.TestCase;
|
||||
import org.codehaus.plexus.cache.builder.CacheBuilder;
|
||||
import org.codehaus.plexus.redback.authentication.AuthenticationResult;
|
||||
import org.codehaus.plexus.redback.authentication.PasswordBasedAuthenticationDataSource;
|
||||
import org.codehaus.plexus.redback.common.ldap.LdapUser;
|
||||
import org.codehaus.plexus.redback.common.ldap.connection.LdapConnection;
|
||||
import org.codehaus.plexus.redback.policy.PasswordEncoder;
|
||||
import org.codehaus.plexus.redback.policy.encoders.SHA1PasswordEncoder;
|
||||
import org.codehaus.plexus.redback.users.ldap.service.LdapCacheService;
|
||||
import org.codehaus.redback.components.apacheds.ApacheDs;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.naming.directory.Attributes;
|
||||
import javax.naming.directory.BasicAttribute;
|
||||
import javax.naming.directory.BasicAttributes;
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.directory.InitialDirContext;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
@RunWith( SpringJUnit4ClassRunner.class )
|
||||
@ContextConfiguration( locations = "classpath*:/META-INF/spring-context.xml" )
|
||||
public class LdapBindAuthenticatorTest
|
||||
extends TestCase
|
||||
{
|
||||
|
||||
protected Logger log = LoggerFactory.getLogger( getClass() );
|
||||
|
||||
@Inject
|
||||
@Named( value = "apacheDS#test" )
|
||||
private ApacheDs apacheDs;
|
||||
|
||||
@Inject
|
||||
private LdapBindAuthenticator authnr;
|
||||
|
||||
private String suffix;
|
||||
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
@Inject
|
||||
private LdapCacheService ldapCacheService;
|
||||
|
||||
@Before
|
||||
public void setUp()
|
||||
throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
passwordEncoder = new SHA1PasswordEncoder();
|
||||
|
||||
suffix =
|
||||
apacheDs.addSimplePartition( "test", new String[]{ "redback", "plexus", "codehaus", "org" } ).getSuffix();
|
||||
|
||||
log.info( "DN Suffix: " + suffix );
|
||||
|
||||
apacheDs.startServer();
|
||||
|
||||
makeUsers();
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown()
|
||||
throws Exception
|
||||
{
|
||||
// clear the cache
|
||||
ldapCacheService.removeAllLdapUserDn();
|
||||
|
||||
InitialDirContext context = apacheDs.getAdminContext();
|
||||
|
||||
context.unbind( createDn( "jesse" ) );
|
||||
|
||||
context.unbind( createDn( "joakim" ) );
|
||||
|
||||
context.unbind( createDn( "brent" ) );
|
||||
|
||||
if ( !apacheDs.isStopped() )
|
||||
{
|
||||
apacheDs.stopServer();
|
||||
}
|
||||
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAuthenticationEmptyPassword()
|
||||
throws Exception
|
||||
{
|
||||
PasswordBasedAuthenticationDataSource authDs = new PasswordBasedAuthenticationDataSource();
|
||||
|
||||
// Would throw NPE if attempting to bind, this hack tests bind prevention
|
||||
authDs.setPrincipal( "brent" );
|
||||
authDs.setPassword( null );
|
||||
AuthenticationResult result = authnr.authenticate( authDs );
|
||||
assertFalse( result.isAuthenticated() );
|
||||
|
||||
// This passes anyway on ApacheDS, but not true for AD or Novel eDir
|
||||
authDs.setPassword( "" );
|
||||
result = authnr.authenticate( authDs );
|
||||
assertFalse( result.isAuthenticated() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAuthentication()
|
||||
throws Exception
|
||||
{
|
||||
PasswordBasedAuthenticationDataSource authDs = new PasswordBasedAuthenticationDataSource();
|
||||
authDs.setPrincipal( "jesse" );
|
||||
authDs.setPassword( passwordEncoder.encodePassword( "foo" ) );
|
||||
AuthenticationResult result = authnr.authenticate( authDs );
|
||||
assertTrue( result.isAuthenticated() );
|
||||
}
|
||||
|
||||
// REDBACK-289/MRM-1488
|
||||
@Test
|
||||
public void testAuthenticationFromCache()
|
||||
throws Exception
|
||||
{
|
||||
PasswordBasedAuthenticationDataSource authDs = new PasswordBasedAuthenticationDataSource();
|
||||
authDs.setPrincipal( "jesse" );
|
||||
authDs.setPassword( passwordEncoder.encodePassword( "foo" ) );
|
||||
|
||||
// user shouldn't be in the cache yet
|
||||
assertNull( ldapCacheService.getLdapUserDn( "jesse" ) );
|
||||
|
||||
long startTime = Calendar.getInstance().getTimeInMillis();
|
||||
AuthenticationResult result = authnr.authenticate( authDs );
|
||||
long endTime = Calendar.getInstance().getTimeInMillis();
|
||||
|
||||
assertTrue( result.isAuthenticated() );
|
||||
|
||||
long firstAuth = endTime - startTime;
|
||||
|
||||
// user should be in the cache now
|
||||
assertNotNull( ldapCacheService.getLdapUserDn( "jesse" ) );
|
||||
|
||||
startTime = Calendar.getInstance().getTimeInMillis();
|
||||
result = authnr.authenticate( authDs );
|
||||
endTime = Calendar.getInstance().getTimeInMillis();
|
||||
|
||||
long secondAuth = endTime - startTime;
|
||||
|
||||
assertTrue( "Second authn should be quicker!", secondAuth < firstAuth );
|
||||
}
|
||||
|
||||
private void makeUsers()
|
||||
throws Exception
|
||||
{
|
||||
InitialDirContext context = apacheDs.getAdminContext();
|
||||
|
||||
String cn = "jesse";
|
||||
bindUserObject( context, cn, createDn( cn ) );
|
||||
|
||||
cn = "joakim";
|
||||
bindUserObject( context, cn, createDn( cn ) );
|
||||
|
||||
cn = "brent";
|
||||
bindUserObject( context, cn, createDn( cn ) );
|
||||
}
|
||||
|
||||
private void bindUserObject( DirContext context, String cn, String dn )
|
||||
throws Exception
|
||||
{
|
||||
Attributes attributes = new BasicAttributes( true );
|
||||
BasicAttribute objectClass = new BasicAttribute( "objectClass" );
|
||||
objectClass.add( "top" );
|
||||
objectClass.add( "inetOrgPerson" );
|
||||
objectClass.add( "person" );
|
||||
objectClass.add( "organizationalperson" );
|
||||
attributes.put( objectClass );
|
||||
attributes.put( "cn", cn );
|
||||
attributes.put( "sn", "foo" );
|
||||
attributes.put( "mail", "foo" );
|
||||
attributes.put( "userPassword", passwordEncoder.encodePassword( "foo" ) );
|
||||
attributes.put( "givenName", "foo" );
|
||||
context.createSubcontext( dn, attributes );
|
||||
}
|
||||
|
||||
private String createDn( String cn )
|
||||
{
|
||||
return "cn=" + cn + "," + suffix;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||
|
||||
<context:property-placeholder system-properties-mode="OVERRIDE"/>
|
||||
|
||||
<bean name="apacheDS#test" class="org.codehaus.redback.components.apacheds.DefaultApacheDs"
|
||||
scope="prototype">
|
||||
<property name="basedir" value="${basedir}/target/apacheds"/>
|
||||
<property name="port" value="${ldapPort}"/>
|
||||
<property name="enableNetworking" value="true"/>
|
||||
<property name="password" value="secret"/>
|
||||
</bean>
|
||||
|
||||
<bean name="ldapConnectionFactory#configurable" class="org.codehaus.plexus.redback.common.ldap.connection.ConfigurableLdapConnectionFactory">
|
||||
<property name="hostname" value="localhost"/>
|
||||
<property name="port" value="${ldapPort}"/>
|
||||
<property name="baseDn" value="dc=redback,dc=plexus,dc=codehaus,dc=org"/>
|
||||
<property name="contextFactory" value="com.sun.jndi.ldap.LdapCtxFactory"/>
|
||||
<property name="password" value="secret"/>
|
||||
<property name="bindDn" value="uid=admin,ou=system"/>
|
||||
<property name="userConf" ref="userConfiguration"/>
|
||||
</bean>
|
||||
|
||||
<bean name="userMapper#ldap" class="org.codehaus.plexus.redback.common.ldap.LdapUserMapper">
|
||||
<property name="emailAttribute" value="mail"/>
|
||||
<property name="fullNameAttribute" value="givenName"/>
|
||||
<property name="passwordAttribute" value="userPassword"/>
|
||||
<property name="userIdAttribute" value="cn"/>
|
||||
<property name="userBaseDn" value="dc=redback,dc=plexus,dc=codehaus,dc=org"/>
|
||||
<property name="userObjectClass" value="inetOrgPerson"/>
|
||||
<property name="userConf" ref="userConfiguration"/>
|
||||
</bean>
|
||||
|
||||
<bean name="userConfiguration" class="org.codehaus.plexus.redback.configuration.UserConfiguration"
|
||||
init-method="initialize">
|
||||
<property name="configs">
|
||||
<list>
|
||||
<value>src/test/resources/security.properties</value>
|
||||
</list>
|
||||
</property>
|
||||
|
||||
<property name="registry" ref="registry#commons-configuration"/>
|
||||
|
||||
</bean>
|
||||
|
||||
<bean name="registry#commons-configuration" class="org.codehaus.redback.components.registry.commons.CommonsConfigurationRegistry"
|
||||
init-method="initialize">
|
||||
|
||||
</bean>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,6 @@
|
|||
user.manager.impl=ldap
|
||||
ldap.bind.authenticator.enabled=true
|
||||
redback.default.admin=adminuser
|
||||
security.policy.password.expiration.enabled=false
|
||||
user.manager.impl=cached
|
||||
ldap.bind.authenticator.enabled=true
|
|
@ -0,0 +1,49 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 2006 The Codehaus.
|
||||
~
|
||||
~ Licensed 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.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-authentication-providers</artifactId>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>redback-authentication-memory</artifactId>
|
||||
<name>Redback :: Authentication Provider :: Memory</name>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-authentication-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.inject</groupId>
|
||||
<artifactId>javax.inject</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.annotation</groupId>
|
||||
<artifactId>jsr250-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,85 @@
|
|||
package org.codehaus.plexus.redback.authentication.memory;
|
||||
|
||||
/*
|
||||
* Copyright 2005 The Codehaus.
|
||||
*
|
||||
* Licensed 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.codehaus.plexus.redback.authentication.AuthenticationDataSource;
|
||||
import org.codehaus.plexus.redback.authentication.AuthenticationException;
|
||||
import org.codehaus.plexus.redback.authentication.AuthenticationResult;
|
||||
import org.codehaus.plexus.redback.authentication.Authenticator;
|
||||
import org.codehaus.plexus.redback.authentication.PasswordBasedAuthenticationDataSource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* MemoryAuthenticator:
|
||||
*
|
||||
* @author: Jesse McConnell <jesse@codehaus.org>
|
||||
* @version: $Id$
|
||||
*/
|
||||
@Service("authenticator#memory")
|
||||
public class MemoryAuthenticator
|
||||
implements Authenticator
|
||||
{
|
||||
private String login;
|
||||
|
||||
private String password;
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return "MemoryAuthenticator";
|
||||
}
|
||||
|
||||
public AuthenticationResult authenticate( AuthenticationDataSource s )
|
||||
throws AuthenticationException
|
||||
{
|
||||
PasswordBasedAuthenticationDataSource source = (PasswordBasedAuthenticationDataSource) s;
|
||||
|
||||
login = source.getPrincipal();
|
||||
password = source.getPassword();
|
||||
|
||||
if ( source.getPassword().equals( password ) )
|
||||
{
|
||||
return new AuthenticationResult( true, login, null );
|
||||
}
|
||||
|
||||
return new AuthenticationResult( false, null, null );
|
||||
}
|
||||
|
||||
public boolean supportsDataSource( AuthenticationDataSource source )
|
||||
{
|
||||
return ( source instanceof PasswordBasedAuthenticationDataSource );
|
||||
}
|
||||
|
||||
public String getLogin()
|
||||
{
|
||||
return login;
|
||||
}
|
||||
|
||||
public void setLogin( String login )
|
||||
{
|
||||
this.login = login;
|
||||
}
|
||||
|
||||
public String getPassword()
|
||||
{
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword( String password )
|
||||
{
|
||||
this.password = password;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-2.5.xsd"
|
||||
default-lazy-init="true">
|
||||
|
||||
<context:annotation-config />
|
||||
<context:component-scan
|
||||
base-package="org.codehaus.plexus.redback.authentication.memory"/>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,62 @@
|
|||
package org.codehaus.plexus.redback.authentication.memory;
|
||||
|
||||
/*
|
||||
* Copyright 2005 The Codehaus.
|
||||
*
|
||||
* Licensed 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 junit.framework.TestCase;
|
||||
import org.codehaus.plexus.redback.authentication.AuthenticationResult;
|
||||
import org.codehaus.plexus.redback.authentication.Authenticator;
|
||||
import org.codehaus.plexus.redback.authentication.PasswordBasedAuthenticationDataSource;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
/**
|
||||
* MemoryAuthenticatorTest:
|
||||
*
|
||||
* @author: Jesse McConnell <jesse@codehaus.org>
|
||||
* @version: $Id$
|
||||
*/
|
||||
@RunWith( SpringJUnit4ClassRunner.class )
|
||||
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
|
||||
public class MemoryAuthenticatorTest
|
||||
extends TestCase
|
||||
{
|
||||
@Inject
|
||||
@Named(value = "authenticator#memory")
|
||||
Authenticator authenticator;
|
||||
|
||||
@Test
|
||||
public void testSimpleAuthentication()
|
||||
throws Exception
|
||||
{
|
||||
assertNotNull( authenticator );
|
||||
|
||||
PasswordBasedAuthenticationDataSource ds = new PasswordBasedAuthenticationDataSource();
|
||||
ds.setPrincipal( "jason" );
|
||||
ds.setPassword( "kungfu" );
|
||||
|
||||
AuthenticationResult ar = authenticator.authenticate( ds );
|
||||
|
||||
assertTrue( ar.isAuthenticated() );
|
||||
|
||||
assertEquals( "jason", ar.getPrincipal() );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||
|
||||
<bean name="memory" class="org.codehaus.plexus.redback.authentication.memory.MemoryAuthenticator">
|
||||
<property name="login" value="jason"/>
|
||||
<property name="password" value="kungfu"/>
|
||||
</bean>
|
||||
</beans>
|
|
@ -0,0 +1,40 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 2006 The Codehaus.
|
||||
~
|
||||
~ Licensed 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.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-authentication-providers</artifactId>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>redback-authentication-open</artifactId>
|
||||
<name>Redback :: Authentication Provider :: Open</name>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-authentication-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.annotation</groupId>
|
||||
<artifactId>jsr250-api</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,56 @@
|
|||
package org.codehaus.plexus.redback.authentication.open;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2006 The Codehaus.
|
||||
*
|
||||
* Licensed 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.codehaus.plexus.redback.authentication.AuthenticationDataSource;
|
||||
import org.codehaus.plexus.redback.authentication.AuthenticationException;
|
||||
import org.codehaus.plexus.redback.authentication.AuthenticationResult;
|
||||
import org.codehaus.plexus.redback.authentication.Authenticator;
|
||||
import org.codehaus.plexus.redback.authentication.PasswordBasedAuthenticationDataSource;
|
||||
import org.codehaus.plexus.redback.policy.AccountLockedException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* OpenAuthenticator - Does not test user / password.
|
||||
* All attempts result in access.
|
||||
*
|
||||
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
*
|
||||
*/
|
||||
@Service("authenticator#open")
|
||||
public class OpenAuthenticator
|
||||
implements Authenticator
|
||||
{
|
||||
|
||||
public AuthenticationResult authenticate( AuthenticationDataSource s )
|
||||
throws AccountLockedException, AuthenticationException
|
||||
{
|
||||
PasswordBasedAuthenticationDataSource source = (PasswordBasedAuthenticationDataSource) s;
|
||||
return new AuthenticationResult( true, source.getPrincipal(), null );
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return "Open Authenticator";
|
||||
}
|
||||
|
||||
public boolean supportsDataSource( AuthenticationDataSource source )
|
||||
{
|
||||
return ( source instanceof PasswordBasedAuthenticationDataSource );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-2.5.xsd"
|
||||
default-lazy-init="true">
|
||||
|
||||
<context:annotation-config />
|
||||
<context:component-scan
|
||||
base-package="org.codehaus.plexus.redback.authentication.open"/>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,37 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 2006 The Codehaus.
|
||||
~
|
||||
~ Licensed 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.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback</artifactId>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>redback-authorization</artifactId>
|
||||
<name>Redback :: Authorization</name>
|
||||
<packaging>pom</packaging>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-users-api</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<modules>
|
||||
<module>redback-authorization-api</module>
|
||||
<module>redback-authorization-providers</module>
|
||||
</modules>
|
||||
</project>
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 2006 The Codehaus.
|
||||
~
|
||||
~ Licensed 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.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-authorization</artifactId>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>redback-authorization-api</artifactId>
|
||||
<name>Redback :: Authorization API</name>
|
||||
</project>
|
|
@ -0,0 +1,72 @@
|
|||
package org.codehaus.plexus.redback.authorization;
|
||||
|
||||
import org.codehaus.plexus.redback.users.User;
|
||||
|
||||
/**
|
||||
* @author Jason van Zyl
|
||||
*/
|
||||
public class AuthorizationDataSource
|
||||
{
|
||||
Object principal;
|
||||
|
||||
User user;
|
||||
|
||||
Object permission;
|
||||
|
||||
Object resource;
|
||||
|
||||
public AuthorizationDataSource( Object principal, User user, Object permission )
|
||||
{
|
||||
this.principal = principal;
|
||||
this.user = user;
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
public AuthorizationDataSource( Object principal, User user, Object permission, Object resource )
|
||||
{
|
||||
this.principal = principal;
|
||||
this.user = user;
|
||||
this.permission = permission;
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
public Object getPrincipal()
|
||||
{
|
||||
return principal;
|
||||
}
|
||||
|
||||
public void setPrincipal( String principal )
|
||||
{
|
||||
this.principal = principal;
|
||||
}
|
||||
|
||||
public User getUser()
|
||||
{
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser( User user )
|
||||
{
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public Object getPermission()
|
||||
{
|
||||
return permission;
|
||||
}
|
||||
|
||||
public void setPermission( Object permission )
|
||||
{
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
public Object getResource()
|
||||
{
|
||||
return resource;
|
||||
}
|
||||
|
||||
public void setResource( Object resource )
|
||||
{
|
||||
this.resource = resource;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package org.codehaus.plexus.redback.authorization;
|
||||
|
||||
/*
|
||||
* Copyright 2005 The Codehaus.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* EntityAuthenticationException.java
|
||||
*
|
||||
* @author: Jesse McConnell <jesse@codehaus.org>
|
||||
* @version: $ID:$
|
||||
*/
|
||||
public class AuthorizationException
|
||||
extends Exception
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @param message
|
||||
*/
|
||||
public AuthorizationException( String message )
|
||||
{
|
||||
super( message );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* @param cause
|
||||
*/
|
||||
public AuthorizationException( String message, Exception cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package org.codehaus.plexus.redback.authorization;
|
||||
/*
|
||||
* Copyright 2005 The Codehaus.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* AuthorizationResult: wrapper object for results from the authorization system
|
||||
*
|
||||
* @author: Jesse McConnell <jesse@codehaus.org>
|
||||
* @version: $ID:$
|
||||
*/
|
||||
public class AuthorizationResult
|
||||
{
|
||||
private boolean isAuthorized;
|
||||
|
||||
private Object principal;
|
||||
|
||||
private Exception exception;
|
||||
|
||||
|
||||
public AuthorizationResult( boolean authorized,
|
||||
Object principal,
|
||||
Exception exception )
|
||||
{
|
||||
isAuthorized = authorized;
|
||||
this.principal = principal;
|
||||
this.exception = exception;
|
||||
}
|
||||
|
||||
public boolean isAuthorized()
|
||||
{
|
||||
return isAuthorized;
|
||||
}
|
||||
|
||||
public Object getPrincipal()
|
||||
{
|
||||
return principal;
|
||||
}
|
||||
|
||||
public Exception getException()
|
||||
{
|
||||
return exception;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package org.codehaus.plexus.redback.authorization;
|
||||
|
||||
/*
|
||||
* Copyright 2005 The Codehaus.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Authorizer:
|
||||
*
|
||||
* @author: Jesse McConnell <jesse@codehaus.org>
|
||||
* @version: $ID:$
|
||||
* @todo chain of command rule processing
|
||||
*/
|
||||
public interface Authorizer
|
||||
{
|
||||
String getId();
|
||||
|
||||
AuthorizationResult isAuthorized( AuthorizationDataSource source )
|
||||
throws AuthorizationException;
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package org.codehaus.plexus.redback.authorization;
|
||||
/*
|
||||
* Copyright 2005 The Codehaus.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* EntityAuthenticationException.java
|
||||
*
|
||||
* @author: Jesse McConnell <jesse@codehaus.org>
|
||||
* @version: $ID:$
|
||||
*/
|
||||
public class NotAuthorizedException
|
||||
extends Exception
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public NotAuthorizedException()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param message
|
||||
*/
|
||||
public NotAuthorizedException( String message )
|
||||
{
|
||||
super( message );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* @param cause
|
||||
*/
|
||||
public NotAuthorizedException( String message, Exception cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package org.codehaus.plexus.redback.authorization;
|
||||
|
||||
/*
|
||||
* Copyright 2011 The Codehaus.
|
||||
*
|
||||
* Licensed 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 java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @author Olivier Lamy
|
||||
* @since 1.3
|
||||
*/
|
||||
@Target( ElementType.METHOD )
|
||||
@Retention( RetentionPolicy.RUNTIME )
|
||||
public @interface RedbackAuthorization
|
||||
{
|
||||
|
||||
/**
|
||||
* @return at least one of those redback roles is needed
|
||||
*/
|
||||
String[] permissions() default ( "" );
|
||||
|
||||
/**
|
||||
* @return the redback ressource karma needed
|
||||
*/
|
||||
String resource() default ( "" );
|
||||
|
||||
/**
|
||||
* @return doc
|
||||
*/
|
||||
String description() default ( "" );
|
||||
|
||||
/**
|
||||
* @return <code>true</code> if doesn't need any special permission
|
||||
*/
|
||||
boolean noRestriction() default false;
|
||||
|
||||
/**
|
||||
* @return if this service need only authentication and not special karma
|
||||
*/
|
||||
boolean noPermission() default false;
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package org.codehaus.plexus.redback.authorization;
|
||||
/*
|
||||
* Copyright 2005 The Codehaus.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The exception thrown if an entity is unauthorized to access a resource.
|
||||
*
|
||||
* @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
|
||||
* @since Mar 1, 2003
|
||||
*/
|
||||
public class UnauthorizedException
|
||||
extends Exception
|
||||
{
|
||||
/**
|
||||
* @param message
|
||||
*/
|
||||
public UnauthorizedException( String message )
|
||||
{
|
||||
super( message );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 2006 The Codehaus.
|
||||
~
|
||||
~ Licensed 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.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-authorization</artifactId>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>redback-authorization-providers</artifactId>
|
||||
<name>Redback :: Authorization Providers</name>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>redback-authorization-open</module>
|
||||
</modules>
|
||||
</project>
|
|
@ -0,0 +1,40 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 2006 The Codehaus.
|
||||
~
|
||||
~ Licensed 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.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-authorization-providers</artifactId>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>redback-authorization-open</artifactId>
|
||||
<name>Redback :: Authorization Provider :: Open</name>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-authorization-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.annotation</groupId>
|
||||
<artifactId>jsr250-api</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,48 @@
|
|||
package org.codehaus.plexus.redback.authorization.open;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2006 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed 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.codehaus.plexus.redback.authorization.AuthorizationDataSource;
|
||||
import org.codehaus.plexus.redback.authorization.AuthorizationException;
|
||||
import org.codehaus.plexus.redback.authorization.AuthorizationResult;
|
||||
import org.codehaus.plexus.redback.authorization.Authorizer;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* OpenAuthorizer - No checks for authorization, everything passes.
|
||||
*
|
||||
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
*
|
||||
*/
|
||||
@Service("authorizer#rbac")
|
||||
public class OpenAuthorizer
|
||||
implements Authorizer
|
||||
{
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return "Open Authorizer";
|
||||
}
|
||||
|
||||
public AuthorizationResult isAuthorized( AuthorizationDataSource source )
|
||||
throws AuthorizationException
|
||||
{
|
||||
return new AuthorizationResult( true, source.getPermission(), null );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-2.5.xsd"
|
||||
default-lazy-init="true">
|
||||
|
||||
<context:annotation-config />
|
||||
<context:component-scan
|
||||
base-package="org.codehaus.plexus.redback.authorization.open"/>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 2006 The Codehaus.
|
||||
~
|
||||
~ Licensed 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.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback</artifactId>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>redback-common</artifactId>
|
||||
<name>Redback :: Commons</name>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>redback-common-jdo</module>
|
||||
<module>redback-common-ldap</module>
|
||||
<module>redback-common-test-resources</module>
|
||||
</modules>
|
||||
</project>
|
|
@ -0,0 +1,80 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 2006 The Codehaus.
|
||||
~
|
||||
~ Licensed 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.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-common</artifactId>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>redback-common-jdo</artifactId>
|
||||
<name>Redback :: JDO Common API</name>
|
||||
<packaging>jar</packaging>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback.components</groupId>
|
||||
<artifactId>spring-jdo2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jpox</groupId>
|
||||
<artifactId>jpox</artifactId>
|
||||
<scope>compile</scope>
|
||||
<exclusions>
|
||||
<!-- targeting JDK 1.4 we don't need this -->
|
||||
<exclusion>
|
||||
<groupId>javax.sql</groupId>
|
||||
<artifactId>jdbc-stdext</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
</exclusion>
|
||||
|
||||
<exclusion>
|
||||
<groupId>javax.resource</groupId>
|
||||
<artifactId>connector</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>javax.transaction</groupId>
|
||||
<artifactId>jta</artifactId>
|
||||
</exclusion>
|
||||
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hsqldb</groupId>
|
||||
<artifactId>hsqldb</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-configuration</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.annotation</groupId>
|
||||
<artifactId>jsr250-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,109 @@
|
|||
package org.codehaus.plexus.redback.common.jdo;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.codehaus.plexus.interpolation.InterpolationException;
|
||||
import org.codehaus.plexus.interpolation.PropertiesBasedValueSource;
|
||||
import org.codehaus.plexus.interpolation.StringSearchInterpolator;
|
||||
import org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory;
|
||||
import org.codehaus.plexus.redback.configuration.UserConfiguration;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
/**
|
||||
* UserConfigurableJdoFactory
|
||||
*
|
||||
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
@Service( "jdoFactory#users" )
|
||||
public class UserConfigurableJdoFactory
|
||||
extends DefaultConfigurableJdoFactory
|
||||
{
|
||||
|
||||
private Logger log = LoggerFactory.getLogger( getClass() );
|
||||
|
||||
@Inject
|
||||
@Named( value = "userConfiguration" )
|
||||
private UserConfiguration config;
|
||||
|
||||
private String getConfigString( String key, String currentValue, String defaultValue )
|
||||
{
|
||||
String valueFromSysProps = System.getProperty( "redback." + key );
|
||||
if (StringUtils.isNotEmpty( valueFromSysProps ))
|
||||
{
|
||||
return valueFromSysProps;
|
||||
}
|
||||
String value = null;
|
||||
if ( StringUtils.isNotEmpty( currentValue ) )
|
||||
{
|
||||
value = config.getString( key, currentValue );
|
||||
}
|
||||
else
|
||||
{
|
||||
value = config.getString( key, defaultValue );
|
||||
}
|
||||
// do some interpolation as we can have some ${plexus.home} etc...
|
||||
StringSearchInterpolator interpolator = new StringSearchInterpolator();
|
||||
interpolator.addValueSource( new PropertiesBasedValueSource( System.getProperties() ) );
|
||||
|
||||
try
|
||||
{
|
||||
return interpolator.interpolate( value );
|
||||
}
|
||||
catch ( InterpolationException e )
|
||||
{
|
||||
// ignore interpolation issue
|
||||
log.warn( "skip issue during interpolation " + e.getMessage() );
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void initialize()
|
||||
{
|
||||
String jdbcDriverName =
|
||||
getConfigString( "jdbc.driver.name", super.getDriverName(), "org.apache.derby.jdbc.EmbeddedDriver" );
|
||||
String jdbcUrl =
|
||||
getConfigString( "jdbc.url", super.getUrl(), "jdbc:derby:${plexus.home}/database;create=true" );
|
||||
|
||||
String jdbcUsername = getConfigString( "jdbc.username", super.getUserName(), "sa" );
|
||||
String jdbcPassword = getConfigString( "jdbc.password", super.getPassword(), "" );
|
||||
|
||||
super.setDriverName( jdbcDriverName );
|
||||
super.setUrl( jdbcUrl );
|
||||
super.setUserName( jdbcUsername );
|
||||
super.setPassword( jdbcPassword );
|
||||
|
||||
if ( StringUtils.isEmpty( super.persistenceManagerFactoryClass ) )
|
||||
{
|
||||
super.setPersistenceManagerFactoryClass( "org.jpox.PersistenceManagerFactoryImpl" );
|
||||
}
|
||||
|
||||
if ( ( super.otherProperties == null ) || super.otherProperties.isEmpty() )
|
||||
{
|
||||
super.setProperty( "org.jpox.autoCreateSchema", "true" );
|
||||
super.setProperty( "org.jpox.validateSchema", "false" );
|
||||
super.setProperty( "org.jpox.validateTables", "false" );
|
||||
super.setProperty( "org.jpox.validateConstraints", "false" );
|
||||
super.setProperty( "org.jpox.transactionIsolation", "READ_COMMITTED" );
|
||||
super.setProperty( "org.jpox.rdbms.dateTimezone", "JDK_DEFAULT_TIMEZONE" );
|
||||
}
|
||||
|
||||
super.initialize();
|
||||
}
|
||||
|
||||
public UserConfiguration getConfig()
|
||||
{
|
||||
return config;
|
||||
}
|
||||
|
||||
public void setConfig( UserConfiguration config )
|
||||
{
|
||||
this.config = config;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
package org.codehaus.plexus.redback.common.jdo.test;
|
||||
|
||||
/*
|
||||
* Copyright 2009 The Codehaus
|
||||
*
|
||||
* Licensed 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 java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.jdo.PersistenceManager;
|
||||
|
||||
import org.jpox.AbstractPersistenceManagerFactory;
|
||||
import org.jpox.ClassLoaderResolver;
|
||||
import org.jpox.plugin.ConfigurationElement;
|
||||
import org.jpox.plugin.Extension;
|
||||
import org.jpox.store.rdbms.RDBMSManager;
|
||||
|
||||
/**
|
||||
* A extension to JPOX store manager that allows counting the SQL queries
|
||||
*
|
||||
* @author Carlos Sanchez <a href="mailto:carlos@apache.org">
|
||||
*/
|
||||
public class StoreManagerDebug
|
||||
extends RDBMSManager
|
||||
{
|
||||
private static int counter;
|
||||
|
||||
public StoreManagerDebug( ClassLoaderResolver clr, AbstractPersistenceManagerFactory pmf, String userName,
|
||||
String password )
|
||||
{
|
||||
super( clr, pmf, userName, password );
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will change JPOX store manager extension so it uses our class instead of whatever is configured in
|
||||
* the plugin.xml
|
||||
*
|
||||
* @param pmf
|
||||
*/
|
||||
public static void setup( AbstractPersistenceManagerFactory pmf )
|
||||
{
|
||||
/* set our own Store Manager to allow counting SQL statements */
|
||||
Extension[] extensions =
|
||||
pmf.getPMFContext().getPluginManager().getExtensionPoint( "org.jpox.store_manager" ).getExtensions();
|
||||
Extension e = extensions[0];
|
||||
for ( ConfigurationElement element : e.getConfigurationElements() )
|
||||
{
|
||||
element.putAttribute( "class-name", StoreManagerDebug.class.getName() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently configured store manager from JPOX. Will fail if
|
||||
* {@link #setup(AbstractPersistenceManagerFactory)} is not called first.
|
||||
*
|
||||
* @param persistenceManager
|
||||
* @return
|
||||
*/
|
||||
public static StoreManagerDebug getConfiguredStoreManager( PersistenceManager persistenceManager )
|
||||
{
|
||||
return (StoreManagerDebug) ( (org.jpox.PersistenceManager) persistenceManager ).getStoreManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] executeStatementBatch( String stmt, PreparedStatement ps )
|
||||
throws SQLException
|
||||
{
|
||||
counter++;
|
||||
return super.executeStatementBatch( stmt, ps );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet executeStatementQuery( String stmt, PreparedStatement ps )
|
||||
throws SQLException
|
||||
{
|
||||
counter++;
|
||||
return super.executeStatementQuery( stmt, ps );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int executeStatementUpdate( String stmt, PreparedStatement ps )
|
||||
throws SQLException
|
||||
{
|
||||
counter++;
|
||||
return super.executeStatementUpdate( stmt, ps );
|
||||
}
|
||||
|
||||
public void resetCounter()
|
||||
{
|
||||
counter = 0;
|
||||
}
|
||||
|
||||
public int counter()
|
||||
{
|
||||
return counter;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd"
|
||||
default-lazy-init="true">
|
||||
|
||||
<bean name="jdoFactory#users" class="org.codehaus.plexus.redback.common.jdo.UserConfigurableJdoFactory">
|
||||
<property name="config" ref="userConfiguration"/>
|
||||
</bean>
|
||||
</beans>
|
|
@ -0,0 +1,60 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 2006 The Codehaus.
|
||||
~
|
||||
~ Licensed 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.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-common</artifactId>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>redback-common-ldap</artifactId>
|
||||
<name>Redback :: Ldap Common API</name>
|
||||
<packaging>jar</packaging>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-configuration</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-users-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.annotation</groupId>
|
||||
<artifactId>jsr250-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
</dependency>
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>org.apache.directory.shared</groupId>
|
||||
<artifactId>shared-ldap-client-api</artifactId>
|
||||
</dependency>
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,246 @@
|
|||
package org.codehaus.plexus.redback.common.ldap;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2007 The Codehaus.
|
||||
*
|
||||
* Licensed 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.codehaus.plexus.redback.users.User;
|
||||
|
||||
import javax.naming.directory.Attributes;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
// TODO this class should be able to be replaced with a model
|
||||
public class LdapUser
|
||||
implements User, Serializable
|
||||
{
|
||||
|
||||
private String key;
|
||||
|
||||
private String username;
|
||||
|
||||
private String fullName;
|
||||
|
||||
private String email;
|
||||
|
||||
private String encodedPassword;
|
||||
|
||||
private List<String> previousEncodedPasswords;
|
||||
|
||||
private boolean locked = false;
|
||||
|
||||
private boolean requiresPasswordChange = false;
|
||||
|
||||
private boolean permanent = true;
|
||||
|
||||
private boolean valid = true;
|
||||
|
||||
private Date creationDate = null;
|
||||
|
||||
private int failedLoginAttempts;
|
||||
|
||||
private Date lastLoginDate = null;
|
||||
|
||||
private Date lastPasswordChange = null;
|
||||
|
||||
// DO NOT STORE AS SUCH!!!
|
||||
private String newPassword;
|
||||
|
||||
private Attributes originalAttributes;
|
||||
|
||||
public LdapUser( String username )
|
||||
{
|
||||
key = username;
|
||||
this.username = username;
|
||||
previousEncodedPasswords = new ArrayList<String>( 0 );
|
||||
failedLoginAttempts = 0;
|
||||
}
|
||||
|
||||
public LdapUser( String username, String fullName, String email )
|
||||
{
|
||||
this( username );
|
||||
this.fullName = fullName;
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public LdapUser()
|
||||
{
|
||||
previousEncodedPasswords = new ArrayList<String>( 0 );
|
||||
failedLoginAttempts = Integer.MIN_VALUE;
|
||||
}
|
||||
|
||||
public void addPreviousEncodedPassword( String encodedPassword )
|
||||
{
|
||||
previousEncodedPasswords.add( encodedPassword );
|
||||
}
|
||||
|
||||
public Date getAccountCreationDate()
|
||||
{
|
||||
return creationDate;
|
||||
}
|
||||
|
||||
public int getCountFailedLoginAttempts()
|
||||
{
|
||||
return failedLoginAttempts;
|
||||
}
|
||||
|
||||
public String getEmail()
|
||||
{
|
||||
return email;
|
||||
}
|
||||
|
||||
public String getEncodedPassword()
|
||||
{
|
||||
return encodedPassword;
|
||||
}
|
||||
|
||||
public String getFullName()
|
||||
{
|
||||
return fullName;
|
||||
}
|
||||
|
||||
public Date getLastLoginDate()
|
||||
{
|
||||
return lastLoginDate;
|
||||
}
|
||||
|
||||
public Date getLastPasswordChange()
|
||||
{
|
||||
return lastPasswordChange;
|
||||
}
|
||||
|
||||
public String getPassword()
|
||||
{
|
||||
return newPassword;
|
||||
}
|
||||
|
||||
public List<String> getPreviousEncodedPasswords()
|
||||
{
|
||||
return previousEncodedPasswords;
|
||||
}
|
||||
|
||||
public Object getPrincipal()
|
||||
{
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getUsername()
|
||||
{
|
||||
return username;
|
||||
}
|
||||
|
||||
public boolean isLocked()
|
||||
{
|
||||
return locked;
|
||||
}
|
||||
|
||||
public boolean isPasswordChangeRequired()
|
||||
{
|
||||
return requiresPasswordChange;
|
||||
}
|
||||
|
||||
public boolean isPermanent()
|
||||
{
|
||||
return permanent;
|
||||
}
|
||||
|
||||
public boolean isValidated()
|
||||
{
|
||||
return valid;
|
||||
}
|
||||
|
||||
public void setCountFailedLoginAttempts( int count )
|
||||
{
|
||||
failedLoginAttempts = count;
|
||||
}
|
||||
|
||||
public void setEmail( String address )
|
||||
{
|
||||
email = address;
|
||||
}
|
||||
|
||||
public void setEncodedPassword( String encodedPassword )
|
||||
{
|
||||
this.encodedPassword = encodedPassword;
|
||||
}
|
||||
|
||||
public void setFullName( String name )
|
||||
{
|
||||
fullName = name;
|
||||
}
|
||||
|
||||
public void setAccountCreationDate( Date date )
|
||||
{
|
||||
creationDate = date;
|
||||
}
|
||||
|
||||
public void setLastLoginDate( Date date )
|
||||
{
|
||||
lastLoginDate = date;
|
||||
}
|
||||
|
||||
public void setLastPasswordChange( Date passwordChangeDate )
|
||||
{
|
||||
lastPasswordChange = passwordChangeDate;
|
||||
}
|
||||
|
||||
public void setLocked( boolean locked )
|
||||
{
|
||||
this.locked = locked;
|
||||
}
|
||||
|
||||
public void setPassword( String rawPassword )
|
||||
{
|
||||
newPassword = rawPassword;
|
||||
}
|
||||
|
||||
public void setPasswordChangeRequired( boolean changeRequired )
|
||||
{
|
||||
requiresPasswordChange = changeRequired;
|
||||
}
|
||||
|
||||
public void setPermanent( boolean permanent )
|
||||
{
|
||||
this.permanent = permanent;
|
||||
}
|
||||
|
||||
public void setPreviousEncodedPasswords( List<String> encodedPasswordList )
|
||||
{
|
||||
previousEncodedPasswords = new ArrayList<String>( encodedPasswordList );
|
||||
}
|
||||
|
||||
public void setUsername( String name )
|
||||
{
|
||||
username = name;
|
||||
}
|
||||
|
||||
public void setValidated( boolean valid )
|
||||
{
|
||||
this.valid = valid;
|
||||
}
|
||||
|
||||
public Attributes getOriginalAttributes()
|
||||
{
|
||||
return originalAttributes;
|
||||
}
|
||||
|
||||
public void setOriginalAttributes( Attributes originalAttributes )
|
||||
{
|
||||
this.originalAttributes = originalAttributes;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,310 @@
|
|||
package org.codehaus.plexus.redback.common.ldap;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2007 The Codehaus.
|
||||
*
|
||||
* Licensed 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.codehaus.plexus.redback.configuration.UserConfiguration;
|
||||
import org.codehaus.plexus.redback.users.User;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.naming.directory.Attributes;
|
||||
import javax.naming.directory.BasicAttributes;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author <a href="jesse@codehaus.org"> jesse
|
||||
* @version $Id$
|
||||
*/
|
||||
@Service( "userMapper#ldap" )
|
||||
public class LdapUserMapper
|
||||
implements UserMapper
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
String emailAttribute = "mail";
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
String fullNameAttribute = "givenName";
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
String passwordAttribute = "userPassword";
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
String userIdAttribute = "cn";
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
String userBaseDn;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
String userObjectClass = "inetOrgPerson";
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
String userFilter;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
int maxResultCount = 0;
|
||||
|
||||
@Inject
|
||||
@Named( value = "userConfiguration" )
|
||||
private UserConfiguration userConf;
|
||||
|
||||
@PostConstruct
|
||||
public void initialize()
|
||||
{
|
||||
emailAttribute = userConf.getString( "ldap.config.mapper.attribute.email", emailAttribute );
|
||||
fullNameAttribute = userConf.getString( "ldap.config.mapper.attribute.fullname", fullNameAttribute );
|
||||
passwordAttribute = userConf.getString( "ldap.config.mapper.attribute.password", passwordAttribute );
|
||||
userIdAttribute = userConf.getString( "ldap.config.mapper.attribute.user.id", userIdAttribute );
|
||||
userBaseDn = userConf.getConcatenatedList( "ldap.config.mapper.attribute.user.base.dn",
|
||||
userConf.getConcatenatedList( "ldap.config.base.dn", userBaseDn ) );
|
||||
userObjectClass = userConf.getString( "ldap.config.mapper.attribute.user.object.class", userObjectClass );
|
||||
userFilter = userConf.getString( "ldap.config.mapper.attribute.user.filter", userFilter );
|
||||
maxResultCount = userConf.getInt( "ldap.config.max.result.count", maxResultCount );
|
||||
}
|
||||
|
||||
public Attributes getCreationAttributes( User user, boolean encodePasswordIfChanged )
|
||||
throws MappingException
|
||||
{
|
||||
Attributes userAttrs = new BasicAttributes();
|
||||
|
||||
boolean passwordSet = false;
|
||||
|
||||
if ( !passwordSet && ( user.getEncodedPassword() != null ) )
|
||||
{
|
||||
userAttrs.put( getPasswordAttribute(), user.getEncodedPassword() );
|
||||
}
|
||||
|
||||
if ( !StringUtils.isEmpty( user.getFullName() ) )
|
||||
{
|
||||
userAttrs.put( getUserFullNameAttribute(), user.getFullName() );
|
||||
}
|
||||
|
||||
if ( !StringUtils.isEmpty( user.getEmail() ) )
|
||||
{
|
||||
userAttrs.put( getEmailAddressAttribute(), user.getEmail() );
|
||||
}
|
||||
|
||||
return userAttrs;
|
||||
}
|
||||
|
||||
public String getEmailAddressAttribute()
|
||||
{
|
||||
return emailAttribute;
|
||||
}
|
||||
|
||||
public String getUserFullNameAttribute()
|
||||
{
|
||||
return fullNameAttribute;
|
||||
}
|
||||
|
||||
public String getPasswordAttribute()
|
||||
{
|
||||
return passwordAttribute;
|
||||
}
|
||||
|
||||
public String[] getUserAttributeNames()
|
||||
{
|
||||
return new String[]{ emailAttribute, fullNameAttribute, passwordAttribute, userIdAttribute };
|
||||
}
|
||||
|
||||
public int getMaxResultCount()
|
||||
{
|
||||
return maxResultCount;
|
||||
}
|
||||
|
||||
public UserUpdate getUpdate( LdapUser user )
|
||||
throws MappingException
|
||||
{
|
||||
|
||||
Attributes addAttrs = new BasicAttributes();
|
||||
|
||||
Attributes modAttrs = new BasicAttributes();
|
||||
|
||||
if ( !StringUtils.isEmpty( user.getFullName() ) )
|
||||
{
|
||||
if ( user.getFullName() == null )
|
||||
{
|
||||
addAttrs.put( getUserFullNameAttribute(), user.getFullName() );
|
||||
}
|
||||
else if ( !user.getFullName().equals( user.getFullName() ) )
|
||||
{
|
||||
modAttrs.put( getUserFullNameAttribute(), user.getFullName() );
|
||||
}
|
||||
}
|
||||
|
||||
if ( !StringUtils.isEmpty( user.getEmail() ) )
|
||||
{
|
||||
if ( user.getEmail() == null )
|
||||
{
|
||||
addAttrs.put( getEmailAddressAttribute(), user.getEmail() );
|
||||
}
|
||||
else if ( !user.getEmail().equals( user.getEmail() ) )
|
||||
{
|
||||
modAttrs.put( getEmailAddressAttribute(), user.getEmail() );
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public LdapUser getUser( Attributes attributes )
|
||||
throws MappingException
|
||||
{
|
||||
String userIdAttribute = getUserIdAttribute();
|
||||
String emailAddressAttribute = getEmailAddressAttribute();
|
||||
String nameAttribute = getUserFullNameAttribute();
|
||||
String passwordAttribute = getPasswordAttribute();
|
||||
|
||||
String userId = ( LdapUtils.getAttributeValue( attributes, userIdAttribute, "username" ) );
|
||||
|
||||
LdapUser user = new LdapUser( userId );
|
||||
user.setOriginalAttributes( attributes );
|
||||
|
||||
user.setEmail( LdapUtils.getAttributeValue( attributes, emailAddressAttribute, "email address" ) );
|
||||
user.setFullName( LdapUtils.getAttributeValue( attributes, nameAttribute, "name" ) );
|
||||
|
||||
String encodedPassword = LdapUtils.getAttributeValueFromByteArray( attributes, passwordAttribute, "password" );
|
||||
|
||||
// it seems to be a common convention for the password to come back prepended with the encoding type..
|
||||
// however we deal with that via configuration right now so just smoke it.
|
||||
if ( encodedPassword != null && encodedPassword.startsWith( "{" ) )
|
||||
{
|
||||
encodedPassword = encodedPassword.substring( encodedPassword.indexOf( "}" ) + 1 );
|
||||
}
|
||||
|
||||
user.setEncodedPassword( encodedPassword );
|
||||
|
||||
// REDBACK-215: skip NPE
|
||||
user.setLastPasswordChange( new Date() );
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
public String getUserIdAttribute()
|
||||
{
|
||||
return userIdAttribute;
|
||||
}
|
||||
|
||||
public String getEmailAttribute()
|
||||
{
|
||||
return emailAttribute;
|
||||
}
|
||||
|
||||
public void setEmailAttribute( String emailAttribute )
|
||||
{
|
||||
this.emailAttribute = emailAttribute;
|
||||
}
|
||||
|
||||
public String getFullNameAttribute()
|
||||
{
|
||||
return fullNameAttribute;
|
||||
}
|
||||
|
||||
public void setFullNameAttribute( String fullNameAttribute )
|
||||
{
|
||||
this.fullNameAttribute = fullNameAttribute;
|
||||
}
|
||||
|
||||
public void setMaxResultCount( int maxResultCount )
|
||||
{
|
||||
this.maxResultCount = maxResultCount;
|
||||
}
|
||||
|
||||
public String getUserBaseDn()
|
||||
{
|
||||
return userBaseDn;
|
||||
}
|
||||
|
||||
public void setUserBaseDn( String userBaseDn )
|
||||
{
|
||||
this.userBaseDn = userBaseDn;
|
||||
}
|
||||
|
||||
public String getUserObjectClass()
|
||||
{
|
||||
return userObjectClass;
|
||||
}
|
||||
|
||||
public String getUserFilter()
|
||||
{
|
||||
return userFilter;
|
||||
}
|
||||
|
||||
public void setUserFilter( String userFilter )
|
||||
{
|
||||
this.userFilter = userFilter;
|
||||
}
|
||||
|
||||
public void setUserObjectClass( String userObjectClass )
|
||||
{
|
||||
this.userObjectClass = userObjectClass;
|
||||
}
|
||||
|
||||
public void setPasswordAttribute( String passwordAttribute )
|
||||
{
|
||||
this.passwordAttribute = passwordAttribute;
|
||||
}
|
||||
|
||||
public void setUserIdAttribute( String userIdAttribute )
|
||||
{
|
||||
this.userIdAttribute = userIdAttribute;
|
||||
}
|
||||
|
||||
public LdapUser newUserInstance( String username, String fullName, String email )
|
||||
{
|
||||
return new LdapUser( username, fullName, email );
|
||||
}
|
||||
|
||||
public LdapUser newTemplateUserInstance()
|
||||
{
|
||||
return new LdapUser();
|
||||
}
|
||||
|
||||
public String[] getReturningAttributes()
|
||||
{
|
||||
return new String[]{ getUserIdAttribute(), getEmailAttribute(), getFullNameAttribute(),
|
||||
getPasswordAttribute() };
|
||||
}
|
||||
|
||||
public UserConfiguration getUserConf()
|
||||
{
|
||||
return userConf;
|
||||
}
|
||||
|
||||
public void setUserConf( UserConfiguration userConf )
|
||||
{
|
||||
this.userConf = userConf;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,129 @@
|
|||
package org.codehaus.plexus.redback.common.ldap;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2007 The Codehaus.
|
||||
*
|
||||
* Licensed 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 javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.Attribute;
|
||||
import javax.naming.directory.Attributes;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public final class LdapUtils
|
||||
{
|
||||
private LdapUtils()
|
||||
{
|
||||
// no op
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static String getLabeledUriValue( Attributes attributes, String attrName, String label,
|
||||
String attributeDescription )
|
||||
throws MappingException
|
||||
{
|
||||
if ( attrName == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Attribute attribute = attributes.get( attrName );
|
||||
if ( attribute != null )
|
||||
{
|
||||
NamingEnumeration attrs;
|
||||
try
|
||||
{
|
||||
attrs = attribute.getAll();
|
||||
}
|
||||
catch ( NamingException e )
|
||||
{
|
||||
throw new MappingException(
|
||||
"Failed to retrieve " + attributeDescription + " (attribute: \'" + attrName + "\').", e );
|
||||
}
|
||||
|
||||
while ( attrs.hasMoreElements() )
|
||||
{
|
||||
Object value = attrs.nextElement();
|
||||
|
||||
String val = String.valueOf( value );
|
||||
|
||||
if ( val.endsWith( " " + label ) )
|
||||
{
|
||||
return val.substring( 0, val.length() - ( label.length() + 1 ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getAttributeValue( Attributes attributes, String attrName, String attributeDescription )
|
||||
throws MappingException
|
||||
{
|
||||
if ( attrName == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Attribute attribute = attributes.get( attrName );
|
||||
if ( attribute != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
Object value = attribute.get();
|
||||
|
||||
return String.valueOf( value );
|
||||
}
|
||||
catch ( NamingException e )
|
||||
{
|
||||
throw new MappingException(
|
||||
"Failed to retrieve " + attributeDescription + " (attribute: \'" + attrName + "\').", e );
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getAttributeValueFromByteArray( Attributes attributes, String attrName,
|
||||
String attributeDescription )
|
||||
throws MappingException
|
||||
{
|
||||
if ( attrName == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Attribute attribute = attributes.get( attrName );
|
||||
if ( attribute != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] value = (byte[]) attribute.get();
|
||||
|
||||
return new String( value );
|
||||
}
|
||||
catch ( NamingException e )
|
||||
{
|
||||
throw new MappingException(
|
||||
"Failed to retrieve " + attributeDescription + " (attribute: \'" + attrName + "\').", e );
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package org.codehaus.plexus.redback.common.ldap;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2007 The Codehaus.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @version $Id$
|
||||
*/
|
||||
public class MappingException
|
||||
extends Exception
|
||||
{
|
||||
|
||||
public MappingException( String message, Throwable cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
|
||||
public MappingException( String message )
|
||||
{
|
||||
super( message );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package org.codehaus.plexus.redback.common.ldap;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2007 The Codehaus.
|
||||
*
|
||||
* Licensed 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.codehaus.plexus.redback.users.User;
|
||||
|
||||
import javax.naming.directory.Attributes;
|
||||
|
||||
/**
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface UserMapper
|
||||
{
|
||||
LdapUser getUser( Attributes attributes )
|
||||
throws MappingException;
|
||||
|
||||
Attributes getCreationAttributes( User user, boolean encodePasswordIfChanged )
|
||||
throws MappingException;
|
||||
|
||||
UserUpdate getUpdate( LdapUser user )
|
||||
throws MappingException;
|
||||
|
||||
String[] getUserAttributeNames();
|
||||
|
||||
String getEmailAddressAttribute();
|
||||
|
||||
String getUserFullNameAttribute();
|
||||
|
||||
String getPasswordAttribute();
|
||||
|
||||
String getUserIdAttribute();
|
||||
|
||||
String getEmailAttribute();
|
||||
|
||||
String getUserBaseDn();
|
||||
|
||||
String getUserObjectClass();
|
||||
|
||||
String getUserFilter();
|
||||
|
||||
LdapUser newUserInstance( String username, String fullName, String email );
|
||||
|
||||
LdapUser newTemplateUserInstance();
|
||||
|
||||
String[] getReturningAttributes();
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package org.codehaus.plexus.redback.common.ldap;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2007 The Codehaus.
|
||||
*
|
||||
* Licensed 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 javax.naming.directory.Attributes;
|
||||
|
||||
/**
|
||||
* @version $Id$
|
||||
*/
|
||||
public class UserUpdate
|
||||
{
|
||||
|
||||
private final Attributes created;
|
||||
|
||||
private final Attributes modified;
|
||||
|
||||
private final Attributes removed;
|
||||
|
||||
public UserUpdate( Attributes created, Attributes modified, Attributes removed )
|
||||
{
|
||||
this.created = created;
|
||||
this.modified = modified;
|
||||
this.removed = removed;
|
||||
}
|
||||
|
||||
public Attributes getAddedAttributes()
|
||||
{
|
||||
return created;
|
||||
}
|
||||
|
||||
public Attributes getModifiedAttributes()
|
||||
{
|
||||
return modified;
|
||||
}
|
||||
|
||||
public Attributes getRemovedAttributes()
|
||||
{
|
||||
return removed;
|
||||
}
|
||||
|
||||
public boolean hasAdditions()
|
||||
{
|
||||
return ( created != null ) && ( created.size() > 0 );
|
||||
}
|
||||
|
||||
public boolean hasModifications()
|
||||
{
|
||||
return ( modified != null ) && ( modified.size() > 0 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,283 @@
|
|||
package org.codehaus.plexus.redback.common.ldap.connection;
|
||||
|
||||
/*
|
||||
* The MIT License
|
||||
* Copyright (c) 2005, The Codehaus
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
import org.codehaus.plexus.redback.configuration.UserConfiguration;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.naming.InvalidNameException;
|
||||
import javax.naming.ldap.LdapName;
|
||||
import javax.naming.ldap.Rdn;
|
||||
import javax.naming.spi.ObjectFactory;
|
||||
import javax.naming.spi.StateFactory;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
@Service( "ldapConnectionFactory#configurable" )
|
||||
public class ConfigurableLdapConnectionFactory
|
||||
implements LdapConnectionFactory
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String hostname;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private int port;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private boolean ssl;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String baseDn;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String contextFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String bindDn;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String authenticationMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private Properties extraProperties;
|
||||
|
||||
private LdapConnectionConfiguration configuration;
|
||||
|
||||
|
||||
@Inject
|
||||
@Named( value = "userConfiguration" )
|
||||
private UserConfiguration userConf;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Component Lifecycle
|
||||
// ----------------------------------------------------------------------
|
||||
@PostConstruct
|
||||
public void initialize()
|
||||
{
|
||||
try
|
||||
{
|
||||
configuration = new LdapConnectionConfiguration();
|
||||
configuration.setHostname( userConf.getString( "ldap.config.hostname", hostname ) );
|
||||
configuration.setPort( userConf.getInt( "ldap.config.port", port ) );
|
||||
configuration.setSsl( userConf.getBoolean( "ldap.config.ssl", ssl ) );
|
||||
configuration.setBaseDn( userConf.getConcatenatedList( "ldap.config.base.dn", baseDn ) );
|
||||
configuration.setContextFactory( userConf.getString( "ldap.config.context.factory", contextFactory ) );
|
||||
configuration.setBindDn( userConf.getConcatenatedList( "ldap.config.bind.dn", bindDn ) );
|
||||
configuration.setPassword( userConf.getString( "ldap.config.password", password ) );
|
||||
configuration.setAuthenticationMethod(
|
||||
userConf.getString( "ldap.config.authentication.method", authenticationMethod ) );
|
||||
configuration.setExtraProperties( extraProperties );
|
||||
}
|
||||
catch ( InvalidNameException e )
|
||||
{
|
||||
throw new RuntimeException( "Error while initializing connection factory.", e );
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// LdapConnectionFactory Implementation
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public LdapConnection getConnection()
|
||||
throws LdapException
|
||||
{
|
||||
return new LdapConnection( configuration, null );
|
||||
}
|
||||
|
||||
public LdapConnection getConnection( Rdn subRdn )
|
||||
throws LdapException
|
||||
{
|
||||
return new LdapConnection( configuration, subRdn );
|
||||
}
|
||||
|
||||
public LdapConnection getConnection( String bindDn, String password )
|
||||
throws LdapException
|
||||
{
|
||||
return new LdapConnection( configuration, bindDn, password );
|
||||
}
|
||||
|
||||
public LdapName getBaseDnLdapName()
|
||||
throws LdapException
|
||||
{
|
||||
try
|
||||
{
|
||||
return new LdapName( baseDn );
|
||||
}
|
||||
catch ( InvalidNameException e )
|
||||
{
|
||||
throw new LdapException( "The base DN is not a valid name.", e );
|
||||
}
|
||||
}
|
||||
|
||||
public void addObjectFactory( Class<? extends ObjectFactory> objectFactoryClass )
|
||||
{
|
||||
configuration.getObjectFactories().add( objectFactoryClass );
|
||||
}
|
||||
|
||||
public void addStateFactory( Class<? extends StateFactory> stateFactoryClass )
|
||||
{
|
||||
configuration.getStateFactories().add( stateFactoryClass );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "{ConfigurableLdapConnectionFactory: configuration: " + configuration + "}";
|
||||
}
|
||||
|
||||
public LdapConnectionConfiguration getConfiguration()
|
||||
{
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public String getHostname()
|
||||
{
|
||||
return hostname;
|
||||
}
|
||||
|
||||
public void setHostname( String hostname )
|
||||
{
|
||||
this.hostname = hostname;
|
||||
}
|
||||
|
||||
public int getPort()
|
||||
{
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort( int port )
|
||||
{
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public boolean isSsl()
|
||||
{
|
||||
return ssl;
|
||||
}
|
||||
|
||||
public void setSsl( boolean ssl )
|
||||
{
|
||||
this.ssl = ssl;
|
||||
}
|
||||
|
||||
public String getBaseDn()
|
||||
{
|
||||
return baseDn;
|
||||
}
|
||||
|
||||
public void setBaseDn( String baseDn )
|
||||
{
|
||||
this.baseDn = baseDn;
|
||||
}
|
||||
|
||||
public String getContextFactory()
|
||||
{
|
||||
return contextFactory;
|
||||
}
|
||||
|
||||
public void setContextFactory( String contextFactory )
|
||||
{
|
||||
this.contextFactory = contextFactory;
|
||||
}
|
||||
|
||||
public String getBindDn()
|
||||
{
|
||||
return bindDn;
|
||||
}
|
||||
|
||||
public void setBindDn( String bindDn )
|
||||
{
|
||||
this.bindDn = bindDn;
|
||||
}
|
||||
|
||||
public String getPassword()
|
||||
{
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword( String password )
|
||||
{
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getAuthenticationMethod()
|
||||
{
|
||||
return authenticationMethod;
|
||||
}
|
||||
|
||||
public void setAuthenticationMethod( String authenticationMethod )
|
||||
{
|
||||
this.authenticationMethod = authenticationMethod;
|
||||
}
|
||||
|
||||
public Properties getExtraProperties()
|
||||
{
|
||||
return extraProperties;
|
||||
}
|
||||
|
||||
public void setExtraProperties( Properties extraProperties )
|
||||
{
|
||||
this.extraProperties = extraProperties;
|
||||
}
|
||||
|
||||
public UserConfiguration getUserConf()
|
||||
{
|
||||
return userConf;
|
||||
}
|
||||
|
||||
public void setUserConf( UserConfiguration userConf )
|
||||
{
|
||||
this.userConf = userConf;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,273 @@
|
|||
package org.codehaus.plexus.redback.common.ldap.connection;
|
||||
|
||||
/*
|
||||
* The MIT License
|
||||
* Copyright (c) 2005, The Codehaus
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
import com.sun.jndi.ldap.LdapCtxFactory;
|
||||
import org.jvnet.animal_sniffer.IgnoreJRERequirement;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.ldap.LdapName;
|
||||
import javax.naming.ldap.Rdn;
|
||||
import java.util.Collections;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* The configuration for a connection will not change.
|
||||
*
|
||||
* @author <a href="mailto:trygvis@inamo.no">trygvis</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class LdapConnection
|
||||
{
|
||||
|
||||
private static LdapCtxFactory ctxFactory;// = new LdapCtxFactory();
|
||||
|
||||
|
||||
static
|
||||
{
|
||||
initCtxFactory();
|
||||
}
|
||||
|
||||
|
||||
private Logger log = LoggerFactory.getLogger( getClass() );
|
||||
|
||||
private LdapConnectionConfiguration config;
|
||||
|
||||
private DirContext context;
|
||||
|
||||
private List<Rdn> baseDnRdns;
|
||||
|
||||
@IgnoreJRERequirement
|
||||
private static void initCtxFactory()
|
||||
{
|
||||
ctxFactory = new LdapCtxFactory();
|
||||
}
|
||||
|
||||
@IgnoreJRERequirement
|
||||
public LdapConnection( LdapConnectionConfiguration config, Rdn subRdn )
|
||||
throws LdapException
|
||||
{
|
||||
this.config = config;
|
||||
|
||||
LdapName baseDn = new LdapName( config.getBaseDn().getRdns() );
|
||||
|
||||
if ( subRdn != null )
|
||||
{
|
||||
baseDn.add( subRdn );
|
||||
}
|
||||
|
||||
baseDnRdns = Collections.unmodifiableList( baseDn.getRdns() );
|
||||
|
||||
if ( context != null )
|
||||
{
|
||||
throw new LdapException( "Already connected." );
|
||||
}
|
||||
|
||||
Hashtable<Object, Object> e = getEnvironment();
|
||||
|
||||
try
|
||||
{
|
||||
context = (DirContext) ctxFactory.getInitialContext( e );
|
||||
}
|
||||
catch ( NamingException ex )
|
||||
{
|
||||
throw new LdapException( "Could not connect to the server.", ex );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This ldap connection will attempt to establish a connection using the configuration,
|
||||
* replacing the principal and the password
|
||||
*
|
||||
* @param config
|
||||
* @param bindDn
|
||||
* @param password
|
||||
* @throws LdapException
|
||||
*/
|
||||
@IgnoreJRERequirement
|
||||
public LdapConnection( LdapConnectionConfiguration config, String bindDn, String password )
|
||||
throws LdapException
|
||||
{
|
||||
this.config = config;
|
||||
|
||||
Hashtable<Object, Object> e = getEnvironment();
|
||||
|
||||
e.put( Context.SECURITY_PRINCIPAL, bindDn );
|
||||
e.put( Context.SECURITY_CREDENTIALS, password );
|
||||
|
||||
try
|
||||
{
|
||||
context = (DirContext) ctxFactory.getInitialContext( e );
|
||||
}
|
||||
catch ( NamingException ex )
|
||||
{
|
||||
throw new LdapException( "Could not connect to the server.", ex );
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Connection Managment
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public Hashtable<Object, Object> getEnvironment()
|
||||
throws LdapException
|
||||
{
|
||||
Properties env = new Properties();
|
||||
|
||||
env.putAll( config.getExtraProperties() );
|
||||
|
||||
config.check();
|
||||
|
||||
env.put( Context.INITIAL_CONTEXT_FACTORY, config.getContextFactory() );
|
||||
|
||||
// REDBACK-289/MRM-1488
|
||||
// enable connection pooling when using Sun's LDAP context factory
|
||||
if( config.getContextFactory().equals( "com.sun.jndi.ldap.LdapCtxFactory" ) )
|
||||
{
|
||||
env.put( "com.sun.jndi.ldap.connect.pool", "true");
|
||||
|
||||
env.put( "com.sun.jndi.ldap.connect.pool.timeout", "3600" );
|
||||
}
|
||||
|
||||
if ( config.getHostname() != null )
|
||||
{
|
||||
String protocol = config.isSsl() ? "ldaps" : "ldap";
|
||||
if ( config.getPort() != 0 )
|
||||
{
|
||||
env.put( Context.PROVIDER_URL, protocol + "://" + config.getHostname() + ":" + config.getPort() + "/" );
|
||||
}
|
||||
else
|
||||
{
|
||||
env.put( Context.PROVIDER_URL, protocol + "://" + config.getHostname() + "/" );
|
||||
}
|
||||
}
|
||||
|
||||
if ( config.getAuthenticationMethod() != null )
|
||||
{
|
||||
env.put( Context.SECURITY_AUTHENTICATION, config.getAuthenticationMethod() );
|
||||
}
|
||||
|
||||
if ( config.getBindDn() != null )
|
||||
{
|
||||
env.put( Context.SECURITY_PRINCIPAL, config.getBindDn().toString() );
|
||||
}
|
||||
|
||||
if ( config.getPassword() != null )
|
||||
{
|
||||
env.put( Context.SECURITY_CREDENTIALS, config.getPassword() );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Object Factories
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
String objectFactories = null;
|
||||
|
||||
for ( Class<?> objectFactoryClass : config.getObjectFactories() )
|
||||
{
|
||||
if ( objectFactories == null )
|
||||
{
|
||||
objectFactories = objectFactoryClass.getName();
|
||||
}
|
||||
else
|
||||
{
|
||||
objectFactories += ":" + objectFactoryClass.getName();
|
||||
}
|
||||
}
|
||||
|
||||
if ( objectFactories != null )
|
||||
{
|
||||
env.setProperty( Context.OBJECT_FACTORIES, objectFactories );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// State Factories
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
String stateFactories = null;
|
||||
|
||||
for ( Class<?> stateFactoryClass : config.getStateFactories() )
|
||||
{
|
||||
if ( stateFactories == null )
|
||||
{
|
||||
stateFactories = stateFactoryClass.getName();
|
||||
}
|
||||
else
|
||||
{
|
||||
stateFactories += ":" + stateFactoryClass.getName();
|
||||
}
|
||||
}
|
||||
|
||||
if ( stateFactories != null )
|
||||
{
|
||||
env.setProperty( Context.STATE_FACTORIES, stateFactories );
|
||||
}
|
||||
|
||||
return env;
|
||||
}
|
||||
|
||||
public void close()
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( context != null )
|
||||
{
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
catch ( NamingException ex )
|
||||
{
|
||||
log.info( "skip error closing ldap connection {}", ex.getMessage() );
|
||||
}
|
||||
finally
|
||||
{
|
||||
context = null;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Utils
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public LdapConnectionConfiguration getConfiguration()
|
||||
{
|
||||
return config;
|
||||
}
|
||||
|
||||
public List<Rdn> getBaseDnRdns()
|
||||
{
|
||||
return baseDnRdns;
|
||||
}
|
||||
|
||||
public DirContext getDirContext()
|
||||
{
|
||||
return context;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,348 @@
|
|||
package org.codehaus.plexus.redback.common.ldap.connection;
|
||||
/*
|
||||
* The MIT License
|
||||
* Copyright (c) 2005, The Codehaus
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import javax.naming.InvalidNameException;
|
||||
import javax.naming.ldap.LdapName;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* This class contains the configuration for a ldap connection.
|
||||
* <p/>
|
||||
* Properties of a ldap connection:
|
||||
* <ul>
|
||||
* <li>Hostname - String, required.
|
||||
* <li>Port - int, not required. If 0 then the default value is used by the ldap driver.
|
||||
* <li>Ssl - boolean, not required. If true then the ldaps will be used.
|
||||
* <li>Base DN - String, required.
|
||||
* <li>Context factory - String, required.
|
||||
* <li>Bind DN - String, not required.
|
||||
* <li>Password - String, not required.
|
||||
* </ul>
|
||||
* Note that both the bind dn and password must be set if any are set.
|
||||
*
|
||||
* @author <a href="mailto:trygvis@inamo.no">trygvis</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class LdapConnectionConfiguration
|
||||
{
|
||||
private String hostname;
|
||||
|
||||
private int port;
|
||||
|
||||
private boolean ssl;
|
||||
|
||||
private LdapName baseDn;
|
||||
|
||||
private String contextFactory;
|
||||
|
||||
private LdapName bindDn;
|
||||
|
||||
private String password;
|
||||
|
||||
private String authenticationMethod;
|
||||
|
||||
private List<Class<?>> objectFactories;
|
||||
|
||||
private List<Class<?>> stateFactories;
|
||||
|
||||
private Properties extraProperties;
|
||||
|
||||
public LdapConnectionConfiguration()
|
||||
{
|
||||
}
|
||||
|
||||
public LdapConnectionConfiguration( String hostname, int port, LdapName baseDn, String contextFactory,
|
||||
LdapName bindDn, String password, String authenticationMethod,
|
||||
Properties extraProperties )
|
||||
throws LdapException
|
||||
{
|
||||
this.hostname = hostname;
|
||||
|
||||
this.port = port;
|
||||
|
||||
if ( baseDn != null )
|
||||
{
|
||||
this.baseDn = new LdapName( baseDn.getRdns() );
|
||||
}
|
||||
|
||||
this.contextFactory = contextFactory;
|
||||
|
||||
if ( bindDn != null )
|
||||
{
|
||||
this.bindDn = new LdapName( bindDn.getRdns() );
|
||||
}
|
||||
|
||||
this.password = password;
|
||||
|
||||
this.authenticationMethod = authenticationMethod;
|
||||
|
||||
this.extraProperties = extraProperties;
|
||||
|
||||
check();
|
||||
}
|
||||
|
||||
public LdapConnectionConfiguration( String hostname, int port, String baseDn, String contextFactory, String bindDn,
|
||||
String password, String authenticationMethod, Properties extraProperties )
|
||||
throws InvalidNameException, LdapException
|
||||
{
|
||||
this.hostname = hostname;
|
||||
this.port = port;
|
||||
|
||||
if ( baseDn != null )
|
||||
{
|
||||
this.baseDn = new LdapName( baseDn );
|
||||
}
|
||||
|
||||
if ( bindDn != null )
|
||||
{
|
||||
this.bindDn = new LdapName( bindDn );
|
||||
}
|
||||
|
||||
this.contextFactory = contextFactory;
|
||||
|
||||
this.password = password;
|
||||
|
||||
this.authenticationMethod = authenticationMethod;
|
||||
|
||||
this.extraProperties = extraProperties;
|
||||
|
||||
check();
|
||||
}
|
||||
|
||||
public LdapConnectionConfiguration( String hostname, int port, LdapName baseDn, String contextFactory )
|
||||
throws LdapException
|
||||
{
|
||||
this.hostname = hostname;
|
||||
|
||||
this.port = port;
|
||||
|
||||
this.baseDn = baseDn;
|
||||
|
||||
this.contextFactory = contextFactory;
|
||||
|
||||
check();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Accessors
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public String getHostname()
|
||||
{
|
||||
return hostname;
|
||||
}
|
||||
|
||||
public void setHostname( String hostname )
|
||||
{
|
||||
this.hostname = hostname;
|
||||
}
|
||||
|
||||
public int getPort()
|
||||
{
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort( int port )
|
||||
{
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public boolean isSsl()
|
||||
{
|
||||
return ssl;
|
||||
}
|
||||
|
||||
public void setSsl( boolean ssl )
|
||||
{
|
||||
this.ssl = ssl;
|
||||
}
|
||||
|
||||
public LdapName getBaseDn()
|
||||
{
|
||||
return baseDn;
|
||||
}
|
||||
|
||||
public void setBaseDn( LdapName baseDn )
|
||||
{
|
||||
this.baseDn = baseDn;
|
||||
}
|
||||
|
||||
public void setBaseDn( String baseDn )
|
||||
throws InvalidNameException
|
||||
{
|
||||
if ( baseDn != null )
|
||||
{
|
||||
this.baseDn = new LdapName( baseDn );
|
||||
}
|
||||
}
|
||||
|
||||
public String getContextFactory()
|
||||
{
|
||||
return contextFactory;
|
||||
}
|
||||
|
||||
public void setContextFactory( String contextFactory )
|
||||
{
|
||||
this.contextFactory = contextFactory;
|
||||
}
|
||||
|
||||
public LdapName getBindDn()
|
||||
{
|
||||
return bindDn;
|
||||
}
|
||||
|
||||
public void setBindDn( LdapName bindDn )
|
||||
{
|
||||
this.bindDn = bindDn;
|
||||
}
|
||||
|
||||
public void setBindDn( String bindDn )
|
||||
throws InvalidNameException
|
||||
{
|
||||
if ( bindDn != null )
|
||||
{
|
||||
this.bindDn = new LdapName( bindDn );
|
||||
}
|
||||
}
|
||||
|
||||
public String getPassword()
|
||||
{
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword( String password )
|
||||
{
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getAuthenticationMethod()
|
||||
{
|
||||
return authenticationMethod;
|
||||
}
|
||||
|
||||
public void setAuthenticationMethod( String authenticationMethod )
|
||||
{
|
||||
this.authenticationMethod = authenticationMethod;
|
||||
}
|
||||
|
||||
public List<Class<?>> getObjectFactories()
|
||||
{
|
||||
if ( objectFactories == null )
|
||||
{
|
||||
objectFactories = new ArrayList<Class<?>>( 0 );
|
||||
}
|
||||
|
||||
return objectFactories;
|
||||
}
|
||||
|
||||
public void setObjectFactories( List<Class<?>> objectFactories )
|
||||
{
|
||||
this.objectFactories = objectFactories;
|
||||
}
|
||||
|
||||
public List<Class<?>> getStateFactories()
|
||||
{
|
||||
if ( stateFactories == null )
|
||||
{
|
||||
stateFactories = new ArrayList<Class<?>>( 0 );
|
||||
}
|
||||
|
||||
return stateFactories;
|
||||
}
|
||||
|
||||
public void setStateFactories( List<Class<?>> stateFactories )
|
||||
{
|
||||
this.stateFactories = stateFactories;
|
||||
}
|
||||
|
||||
public Properties getExtraProperties()
|
||||
{
|
||||
if ( extraProperties == null )
|
||||
{
|
||||
extraProperties = new Properties();
|
||||
}
|
||||
|
||||
return extraProperties;
|
||||
}
|
||||
|
||||
public void setExtraProperties( Properties extraProperties )
|
||||
{
|
||||
this.extraProperties = extraProperties;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public void check()
|
||||
throws LdapException
|
||||
{
|
||||
if ( port < 0 || port > 65535 )
|
||||
{
|
||||
throw new LdapException( "The port must be between 1 and 65535." );
|
||||
}
|
||||
if ( baseDn == null )
|
||||
{
|
||||
throw new LdapException( "The base DN must be set." );
|
||||
}
|
||||
if ( StringUtils.isEmpty( contextFactory ) )
|
||||
{
|
||||
throw new LdapException( "The context factory must be set." );
|
||||
}
|
||||
if ( password != null && bindDn == null )
|
||||
{
|
||||
throw new LdapException( "The password cant be set unless the bind dn is." );
|
||||
}
|
||||
|
||||
if ( extraProperties == null )
|
||||
{
|
||||
extraProperties = new Properties();
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "{LdapConnectionConfiguration: " +
|
||||
"hostname: " + getHostname() + ", " +
|
||||
"port: " + getPort() + ", " +
|
||||
"ssl: " + isSsl() + ", " +
|
||||
"baseDn: " + getBaseDn() + ", " +
|
||||
"contextFactory: " + getContextFactory() + ", " +
|
||||
"bindDn: " + getBindDn() + ", " +
|
||||
"password: " + getPassword() + ", " +
|
||||
"authenticationMethod: " + getAuthenticationMethod() + ", " +
|
||||
"objectFactories: " + getObjectFactories() + ", " +
|
||||
"stateFactories: " + getStateFactories() + ", " +
|
||||
"extraProperties: " + new TreeMap<Object, Object>( extraProperties ).toString() + "}";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package org.codehaus.plexus.redback.common.ldap.connection;
|
||||
|
||||
/*
|
||||
* The MIT License
|
||||
* Copyright (c) 2005, The Codehaus
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
import javax.naming.ldap.LdapName;
|
||||
import javax.naming.ldap.Rdn;
|
||||
import javax.naming.spi.ObjectFactory;
|
||||
import javax.naming.spi.StateFactory;
|
||||
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface LdapConnectionFactory
|
||||
{
|
||||
String ROLE = LdapConnectionFactory.class.getName();
|
||||
|
||||
LdapConnection getConnection()
|
||||
throws LdapException;
|
||||
|
||||
LdapConnection getConnection( Rdn subRdn )
|
||||
throws LdapException;
|
||||
|
||||
LdapConnection getConnection( String bindDn, String password )
|
||||
throws LdapException;
|
||||
|
||||
LdapName getBaseDnLdapName()
|
||||
throws LdapException;
|
||||
|
||||
void addObjectFactory( Class<? extends ObjectFactory> objectFactoryClass );
|
||||
|
||||
void addStateFactory( Class<? extends StateFactory> objectFactoryClass );
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package org.codehaus.plexus.redback.common.ldap.connection;
|
||||
|
||||
/*
|
||||
* The MIT License
|
||||
* Copyright (c) 2005, The Codehaus
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
import javax.naming.NamingException;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:trygvis@inamo.no">trygvis</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class LdapException
|
||||
extends NamingException
|
||||
{
|
||||
public LdapException( String message )
|
||||
{
|
||||
super( message );
|
||||
}
|
||||
|
||||
public LdapException( String message, Throwable t )
|
||||
{
|
||||
super( message );
|
||||
setRootCause( t );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd"
|
||||
default-lazy-init="true">
|
||||
|
||||
<context:annotation-config />
|
||||
<context:component-scan base-package="org.codehaus.plexus.redback.common.ldap"/>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,41 @@
|
|||
package org.codehaus.plexus.redback.common.ldap;
|
||||
|
||||
/*
|
||||
* Copyright 2009 The Codehaus.
|
||||
*
|
||||
* Licensed 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 junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
@RunWith( SpringJUnit4ClassRunner.class )
|
||||
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
|
||||
public class LdapUserMapperTest
|
||||
extends TestCase
|
||||
{
|
||||
@Inject @Named(value = "userMapper#ldap")
|
||||
LdapUserMapper mapper;
|
||||
|
||||
@Test
|
||||
public void testConfiguration()
|
||||
{
|
||||
assertEquals( "o=People,dc=codehaus,dc=org", mapper.getUserBaseDn() );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package org.codehaus.plexus.redback.common.ldap.connection;
|
||||
|
||||
/*
|
||||
* Copyright 2009 The Codehaus.
|
||||
*
|
||||
* Licensed 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 junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
@RunWith( SpringJUnit4ClassRunner.class )
|
||||
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
|
||||
public class ConfigurableLdapConnectionFactoryTest
|
||||
extends TestCase
|
||||
{
|
||||
|
||||
@Inject
|
||||
@Named( value = "ldapConnectionFactory#configurable" )
|
||||
ConfigurableLdapConnectionFactory factory;
|
||||
|
||||
@Test
|
||||
public void testConfiguration()
|
||||
{
|
||||
assertEquals( "dc=codehaus,dc=org", factory.getConfiguration().getBaseDn().toString() );
|
||||
assertEquals( "uid=user,dc=codehaus,dc=org", factory.getConfiguration().getBindDn().toString() );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||
|
||||
<bean name="userConfiguration" class="org.codehaus.plexus.redback.configuration.UserConfiguration">
|
||||
<property name="configs">
|
||||
<list>
|
||||
<value>src/test/resources/test.properties</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,10 @@
|
|||
# LDAP settings
|
||||
|
||||
ldap.bind.authenticator.enabled=true
|
||||
|
||||
#ldap.config.hostname=
|
||||
#ldap.config.port=389
|
||||
ldap.config.base.dn=dc=codehaus,dc=org
|
||||
ldap.config.bind.dn=uid=user,dc=codehaus,dc=org
|
||||
|
||||
ldap.config.mapper.attribute.user.base.dn=o=People,dc=codehaus,dc=org
|
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 2011 The Codehaus.
|
||||
~
|
||||
~ Licensed 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.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-common</artifactId>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>redback-common-test-resources</artifactId>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
<name>Redback :: Common TestResources</name>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,228 @@
|
|||
<redback-role-model>
|
||||
<modelVersion>1.0.0</modelVersion>
|
||||
<applications>
|
||||
<application>
|
||||
<id>System</id>
|
||||
<description>Roles that apply system-wide, across all of the applications</description>
|
||||
<version>1.0.0</version>
|
||||
<resources>
|
||||
<resource>
|
||||
<id>global</id>
|
||||
<name>*</name>
|
||||
<permanent>true</permanent>
|
||||
<description>global resource implies full access for authorization</description>
|
||||
</resource>
|
||||
<resource>
|
||||
<id>username</id>
|
||||
<name>${username}</name>
|
||||
<permanent>true</permanent>
|
||||
<description>replaced with the username of the principal at authorization check time</description>
|
||||
</resource>
|
||||
</resources>
|
||||
<operations>
|
||||
<operation>
|
||||
<id>configuration-edit</id>
|
||||
<name>configuration-edit</name>
|
||||
<description>edit configuration</description>
|
||||
<permanent>true</permanent>
|
||||
</operation>
|
||||
<operation>
|
||||
<id>user-management-user-create</id>
|
||||
<name>user-management-user-create</name>
|
||||
<description>create user</description>
|
||||
<permanent>true</permanent>
|
||||
</operation>
|
||||
<operation>
|
||||
<id>user-management-user-edit</id>
|
||||
<name>user-management-user-edit</name>
|
||||
<description>edit user</description>
|
||||
<permanent>true</permanent>
|
||||
</operation>
|
||||
<operation>
|
||||
<id>user-management-user-role</id>
|
||||
<name>user-management-user-role</name>
|
||||
<description>user roles</description>
|
||||
<permanent>true</permanent>
|
||||
</operation>
|
||||
<operation>
|
||||
<id>user-management-user-delete</id>
|
||||
<name>user-management-user-delete</name>
|
||||
<description>delete user</description>
|
||||
<permanent>true</permanent>
|
||||
</operation>
|
||||
<operation>
|
||||
<id>user-management-user-list</id>
|
||||
<name>user-management-user-list</name>
|
||||
<description>list users</description>
|
||||
<permanent>true</permanent>
|
||||
</operation>
|
||||
<operation>
|
||||
<id>user-management-role-grant</id>
|
||||
<name>user-management-role-grant</name>
|
||||
<description>grant role</description>
|
||||
<permanent>true</permanent>
|
||||
</operation>
|
||||
<operation>
|
||||
<id>user-management-role-drop</id>
|
||||
<name>user-management-role-drop</name>
|
||||
<description>drop role</description>
|
||||
<permanent>true</permanent>
|
||||
</operation>
|
||||
<operation>
|
||||
<id>user-management-rbac-admin</id>
|
||||
<name>user-management-rbac-admin</name>
|
||||
<description>administer rbac</description>
|
||||
<permanent>true</permanent>
|
||||
</operation>
|
||||
<operation>
|
||||
<id>guest-access</id>
|
||||
<name>guest-access</name>
|
||||
<description>access guest</description>
|
||||
<permanent>true</permanent>
|
||||
</operation>
|
||||
<operation>
|
||||
<id>user-management-manage-data</id>
|
||||
<name>user-management-manage-data</name>
|
||||
<description>manage data</description>
|
||||
<permanent>true</permanent>
|
||||
</operation>
|
||||
</operations>
|
||||
<roles>
|
||||
<role>
|
||||
<id>system-administrator</id>
|
||||
<name>System Administrator</name>
|
||||
<permanent>true</permanent>
|
||||
<assignable>true</assignable>
|
||||
<permissions>
|
||||
<permission>
|
||||
<id>edit-redback-configuration</id>
|
||||
<name>Edit Redback Configuration</name>
|
||||
<operation>configuration-edit</operation>
|
||||
<resource>global</resource>
|
||||
<permanent>true</permanent>
|
||||
</permission>
|
||||
<permission>
|
||||
<id>manage-rbac-setup</id>
|
||||
<name>User RBAC Management</name>
|
||||
<operation>user-management-rbac-admin</operation>
|
||||
<resource>global</resource>
|
||||
<permanent>true</permanent>
|
||||
</permission>
|
||||
<permission>
|
||||
<id>manage-rbac-data</id>
|
||||
<name>RBAC Manage Data</name>
|
||||
<operation>user-management-manage-data</operation>
|
||||
<resource>global</resource>
|
||||
<permanent>true</permanent>
|
||||
</permission>
|
||||
</permissions>
|
||||
<childRoles>
|
||||
<childRole>user-administrator</childRole>
|
||||
</childRoles>
|
||||
</role>
|
||||
<role>
|
||||
<id>user-administrator</id>
|
||||
<name>User Administrator</name>
|
||||
<permanent>true</permanent>
|
||||
<assignable>true</assignable>
|
||||
<permissions>
|
||||
<permission>
|
||||
<id>drop-roles-for-anyone</id>
|
||||
<name>Drop Roles for Anyone</name>
|
||||
<operation>user-management-role-drop</operation>
|
||||
<resource>global</resource>
|
||||
<permanent>true</permanent>
|
||||
</permission>
|
||||
<permission>
|
||||
<id>grant-roles-for-anyone</id>
|
||||
<name>Grant Roles for Anyone</name>
|
||||
<operation>user-management-role-grant</operation>
|
||||
<resource>global</resource>
|
||||
<permanent>true</permanent>
|
||||
</permission>
|
||||
<permission>
|
||||
<id>user-create</id>
|
||||
<name>Create Users</name>
|
||||
<operation>user-management-user-create</operation>
|
||||
<resource>global</resource>
|
||||
<permanent>true</permanent>
|
||||
</permission>
|
||||
<permission>
|
||||
<id>user-delete</id>
|
||||
<name>Delete Users</name>
|
||||
<operation>user-management-user-delete</operation>
|
||||
<resource>global</resource>
|
||||
<permanent>true</permanent>
|
||||
</permission>
|
||||
<permission>
|
||||
<id>user-edit</id>
|
||||
<name>Edit Users</name>
|
||||
<operation>user-management-user-edit</operation>
|
||||
<resource>global</resource>
|
||||
<permanent>true</permanent>
|
||||
</permission>
|
||||
<permission>
|
||||
<id>access-users-roles</id>
|
||||
<name>Access Users Roles</name>
|
||||
<operation>user-management-user-role</operation>
|
||||
<resource>global</resource>
|
||||
<permanent>true</permanent>
|
||||
</permission>
|
||||
<permission>
|
||||
<id>access-user-list</id>
|
||||
<name>Access User List</name>
|
||||
<operation>user-management-user-list</operation>
|
||||
<resource>global</resource>
|
||||
<permanent>true</permanent>
|
||||
</permission>
|
||||
</permissions>
|
||||
</role>
|
||||
<role>
|
||||
<id>edit-users-list</id>
|
||||
<name>edit users list</name>
|
||||
<permanent>true</permanent>
|
||||
<assignable>true</assignable>
|
||||
<permissions>
|
||||
<permission>
|
||||
<id>access-user-list</id>
|
||||
<name>Access User List</name>
|
||||
<operation>user-management-user-list</operation>
|
||||
<resource>global</resource>
|
||||
<permanent>true</permanent>
|
||||
</permission>
|
||||
</permissions>
|
||||
</role>
|
||||
<role>
|
||||
<id>registered-user</id>
|
||||
<name>Registered User</name>
|
||||
<permanent>true</permanent>
|
||||
<assignable>true</assignable>
|
||||
<permissions>
|
||||
<permission>
|
||||
<id>edit-user-by-username</id>
|
||||
<name>Edit User Data by Username</name>
|
||||
<operation>user-management-user-edit</operation>
|
||||
<resource>username</resource>
|
||||
<permanent>true</permanent>
|
||||
</permission>
|
||||
</permissions>
|
||||
</role>
|
||||
<role>
|
||||
<id>guest</id>
|
||||
<name>Guest</name>
|
||||
<permanent>true</permanent>
|
||||
<assignable>true</assignable>
|
||||
<permissions>
|
||||
<permission>
|
||||
<id>guest-permission</id>
|
||||
<name>Guest Permission</name>
|
||||
<operation>guest-access</operation>
|
||||
<resource>global</resource>
|
||||
<permanent>true</permanent>
|
||||
</permission>
|
||||
</permissions>
|
||||
</role>
|
||||
</roles>
|
||||
</application>
|
||||
</applications>
|
||||
</redback-role-model>
|
|
@ -0,0 +1,130 @@
|
|||
#
|
||||
# Copyright 2006 The Codehaus.
|
||||
#
|
||||
# Licensed 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.
|
||||
#
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# Application Configuration
|
||||
|
||||
application.timestamp=EEE d MMM yyyy HH:mm:ss Z
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# JDBC Setup
|
||||
|
||||
#jdbc.driver.name=org.hsqldb.jdbcDriver
|
||||
jdbc.driver.name=org.apache.derby.jdbc.EmbeddedDriver
|
||||
#jdbc.url=jdbc:hsqldb:mem:redback-users-tests
|
||||
#jdbc.url=jdbc:derby:memory:users-test;create=true
|
||||
jdbc.url=jdbc:derby:users-test;create=true
|
||||
jdbc.username=sa
|
||||
jdbc.password=
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# Email Settings
|
||||
|
||||
email.jndiSessionName=java:comp/env/mail/Session
|
||||
email.smtp.host=localhost
|
||||
email.smtp.port=25
|
||||
email.smtp.ssl.enabled=false
|
||||
email.smtp.tls.enabled=false
|
||||
email.smtp.username=
|
||||
email.smtp.password=
|
||||
|
||||
#TODO: move description elsewhere, remove bad default
|
||||
# All emails sent by the system will be from the following address
|
||||
#email.from.address=${user.name}@localhost
|
||||
# All emails sent by the system will be from the following user name (used in conjunction with address)
|
||||
#email.from.name=Unconfigured Username
|
||||
|
||||
# If all email addresses (from new user registration) require an account validation email.
|
||||
email.validation.required=true
|
||||
# Timeout (in minutes) for the key generated for an email validation to remain valid.
|
||||
# 2880 minutes = 48 hours
|
||||
email.validation.timeout=2880
|
||||
# The subject line for the email message.
|
||||
email.validation.subject=Welcome
|
||||
|
||||
#TODO: move description elsewhere, remove bad default
|
||||
# Get the Feedback to use for any outgoing emails.
|
||||
# NOTE: if feedback.path starts with a "/" it is appended to the end of the value provided in application.url
|
||||
# This value can be in the format/syntax of "/feedback.action" or even "mailto:feedback@application.com"
|
||||
#email.feedback.path=/feedback.action
|
||||
|
||||
#Set the application base URL. The default is to derive it from the HTTP request
|
||||
#application.url=http://myurl.mycompany.com
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# Auto Login Settings
|
||||
|
||||
security.rememberme.enabled=true
|
||||
# Timeout in minutes ( 525600 minutes = 1 year )
|
||||
security.rememberme.timeout=525600
|
||||
|
||||
# Single Sign On
|
||||
# Timeout in minutes
|
||||
security.signon.timeout=30
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# Default Username Values
|
||||
redback.default.admin=admin
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# Security Policies
|
||||
|
||||
#security.policy.password.encoder=
|
||||
security.policy.password.previous.count=6
|
||||
security.policy.password.expiration.enabled=true
|
||||
security.policy.password.expiration.days=90
|
||||
security.policy.password.expiration.notify.days=10
|
||||
security.policy.allowed.login.attempt=10
|
||||
|
||||
# turn off the perclick enforcement of various security policies, slightly
|
||||
# more heavyweight since it will ensure that the User object on each click
|
||||
# is up to date
|
||||
security.policy.strict.enforcement.enabled=true
|
||||
security.policy.strict.force.password.change.enabled=true
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# Password Rules
|
||||
security.policy.password.rule.alphanumeric.enabled=false
|
||||
security.policy.password.rule.alphacount.enabled=true
|
||||
security.policy.password.rule.alphacount.minimum=1
|
||||
security.policy.password.rule.characterlength.enabled=true
|
||||
security.policy.password.rule.characterlength.minimum=1
|
||||
security.policy.password.rule.characterlength.maximum=24
|
||||
security.policy.password.rule.musthave.enabled=true
|
||||
security.policy.password.rule.numericalcount.enabled=true
|
||||
security.policy.password.rule.numericalcount.minimum=1
|
||||
security.policy.password.rule.reuse.enabled=true
|
||||
security.policy.password.rule.nowhitespace.enabled=true
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# ldap settings
|
||||
#
|
||||
ldap.bind.authenticator.enabled=false
|
||||
|
||||
# ldap options for configuration via properties file
|
||||
#ldap.config.hostname=
|
||||
#ldap.config.port=
|
||||
#ldap.config.base.dn=
|
||||
#ldap.config.context.factory=
|
||||
#ldap.config.bind.dn=
|
||||
#ldap.config.password=
|
||||
#ldap.config.authentication.method=
|
||||
|
||||
# config parameter for the ConfigurableUserManager
|
||||
user.manager.impl=cached
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 2006 The Codehaus.
|
||||
~
|
||||
~ Licensed 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.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback</artifactId>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>redback-configuration</artifactId>
|
||||
<name>Redback :: Configuration</name>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-expression-evaluator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback.components.registry</groupId>
|
||||
<artifactId>spring-registry-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback.components.registry</groupId>
|
||||
<artifactId>spring-registry-commons</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.inject</groupId>
|
||||
<artifactId>javax.inject</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.annotation</groupId>
|
||||
<artifactId>jsr250-api</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,221 @@
|
|||
package org.codehaus.plexus.redback.configuration;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2006 The Codehaus.
|
||||
*
|
||||
* Licensed 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.codehaus.plexus.evaluator.DefaultExpressionEvaluator;
|
||||
import org.codehaus.plexus.evaluator.EvaluatorException;
|
||||
import org.codehaus.plexus.evaluator.ExpressionEvaluator;
|
||||
import org.codehaus.plexus.evaluator.sources.SystemPropertyExpressionSource;
|
||||
import org.codehaus.plexus.registry.Registry;
|
||||
import org.codehaus.plexus.registry.RegistryException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ConfigurationFactory
|
||||
*
|
||||
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
@Service( "userConfiguration" )
|
||||
public class UserConfiguration
|
||||
{
|
||||
private static final String DEFAULT_CONFIG_RESOURCE = "org/codehaus/plexus/redback/config-defaults.properties";
|
||||
|
||||
protected Logger log = LoggerFactory.getLogger( getClass() );
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @deprecated Please configure the Plexus registry instead
|
||||
*/
|
||||
private List<String> configs;
|
||||
|
||||
private Registry lookupRegistry;
|
||||
|
||||
private static final String PREFIX = "org.codehaus.plexus.redback";
|
||||
|
||||
@Inject
|
||||
@Named( value = "commons-configuration" )
|
||||
private Registry registry;
|
||||
|
||||
//TODO move this method call in the constructor
|
||||
|
||||
@PostConstruct
|
||||
public void initialize()
|
||||
throws RegistryException
|
||||
{
|
||||
performLegacyInitialization();
|
||||
|
||||
try
|
||||
{
|
||||
registry.addConfigurationFromResource( DEFAULT_CONFIG_RESOURCE, PREFIX );
|
||||
}
|
||||
catch ( RegistryException e )
|
||||
{
|
||||
// Ok, not found in context classloader; try the one in this jar.
|
||||
|
||||
ClassLoader prevCl = Thread.currentThread().getContextClassLoader();
|
||||
try
|
||||
{
|
||||
|
||||
Thread.currentThread().setContextClassLoader( getClass().getClassLoader() );
|
||||
registry.addConfigurationFromResource( DEFAULT_CONFIG_RESOURCE, PREFIX );
|
||||
}
|
||||
finally
|
||||
{
|
||||
Thread.currentThread().setContextClassLoader( prevCl );
|
||||
}
|
||||
}
|
||||
|
||||
lookupRegistry = registry.getSubset( PREFIX );
|
||||
|
||||
if ( log.isDebugEnabled() )
|
||||
{
|
||||
log.debug( lookupRegistry.dump() );
|
||||
}
|
||||
}
|
||||
|
||||
private void performLegacyInitialization()
|
||||
throws RegistryException
|
||||
{
|
||||
ExpressionEvaluator evaluator = new DefaultExpressionEvaluator();
|
||||
evaluator.addExpressionSource( new SystemPropertyExpressionSource() );
|
||||
|
||||
if ( configs != null )
|
||||
{
|
||||
if ( !configs.isEmpty() )
|
||||
{
|
||||
// TODO: plexus should be able to do this on it's own.
|
||||
log.warn(
|
||||
"DEPRECATED: the <configs> elements is deprecated. Please configure the Plexus registry instead" );
|
||||
}
|
||||
|
||||
for ( String configName : configs )
|
||||
{
|
||||
try
|
||||
{
|
||||
configName = evaluator.expand( configName );
|
||||
}
|
||||
catch ( EvaluatorException e )
|
||||
{
|
||||
log.warn( "Unable to resolve configuration name: " + e.getMessage(), e );
|
||||
}
|
||||
log.info( "Attempting to find configuration [{}] (resolved to [{}])", configName, configName );
|
||||
|
||||
registry.addConfigurationFromFile( new File( configName ), PREFIX );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getString( String key )
|
||||
{
|
||||
return lookupRegistry.getString( key );
|
||||
}
|
||||
|
||||
public String getString( String key, String defaultValue )
|
||||
{
|
||||
String value = lookupRegistry.getString( key, defaultValue );
|
||||
return value;
|
||||
}
|
||||
|
||||
public int getInt( String key )
|
||||
{
|
||||
return lookupRegistry.getInt( key );
|
||||
}
|
||||
|
||||
public int getInt( String key, int defaultValue )
|
||||
{
|
||||
return lookupRegistry.getInt( key, defaultValue );
|
||||
}
|
||||
|
||||
public boolean getBoolean( String key )
|
||||
{
|
||||
return lookupRegistry.getBoolean( key );
|
||||
}
|
||||
|
||||
public boolean getBoolean( String key, boolean defaultValue )
|
||||
{
|
||||
return lookupRegistry.getBoolean( key, defaultValue );
|
||||
}
|
||||
|
||||
@SuppressWarnings( "unchecked" )
|
||||
public List<String> getList( String key )
|
||||
{
|
||||
return lookupRegistry.getList( key );
|
||||
}
|
||||
|
||||
public String getConcatenatedList( String key, String defaultValue )
|
||||
{
|
||||
String concatenatedList;
|
||||
List<String> list = getList( key );
|
||||
if ( !list.isEmpty() )
|
||||
{
|
||||
StringBuilder s = new StringBuilder();
|
||||
for ( String value : list )
|
||||
{
|
||||
if ( s.length() > 0 )
|
||||
{
|
||||
s.append( "," );
|
||||
}
|
||||
s.append( value );
|
||||
}
|
||||
concatenatedList = s.toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
concatenatedList = defaultValue;
|
||||
}
|
||||
|
||||
return concatenatedList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @deprecated
|
||||
*/
|
||||
public List<String> getConfigs()
|
||||
{
|
||||
return configs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param configs
|
||||
* @deprecated
|
||||
*/
|
||||
public void setConfigs( List<String> configs )
|
||||
{
|
||||
this.configs = configs;
|
||||
}
|
||||
|
||||
public Registry getRegistry()
|
||||
{
|
||||
return registry;
|
||||
}
|
||||
|
||||
public void setRegistry( Registry registry )
|
||||
{
|
||||
this.registry = registry;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd"
|
||||
default-lazy-init="true">
|
||||
|
||||
<context:annotation-config />
|
||||
<context:component-scan base-package="org.codehaus.plexus.redback.configuration"/>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,127 @@
|
|||
#
|
||||
# Copyright 2006 The Codehaus.
|
||||
#
|
||||
# Licensed 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.
|
||||
#
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# Application Configuration
|
||||
|
||||
application.timestamp=EEE d MMM yyyy HH:mm:ss Z
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# JDBC Setup
|
||||
|
||||
jdbc.driver.name=org.apache.derby.jdbc.EmbeddedDriver
|
||||
jdbc.url=jdbc:derby:${plexus.home}/database;create=true
|
||||
jdbc.username=sa
|
||||
jdbc.password=
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# Email Settings
|
||||
|
||||
email.jndiSessionName=java:comp/env/mail/Session
|
||||
email.smtp.host=localhost
|
||||
email.smtp.port=25
|
||||
email.smtp.ssl.enabled=false
|
||||
email.smtp.tls.enabled=false
|
||||
email.smtp.username=
|
||||
email.smtp.password=
|
||||
|
||||
#TODO: move description elsewhere, remove bad default
|
||||
# All emails sent by the system will be from the following address
|
||||
#email.from.address=${user.name}@localhost
|
||||
# All emails sent by the system will be from the following user name (used in conjunction with address)
|
||||
#email.from.name=Unconfigured Username
|
||||
|
||||
# If all email addresses (from new user registration) require an account validation email.
|
||||
email.validation.required=true
|
||||
# Timeout (in minutes) for the key generated for an email validation to remain valid.
|
||||
# 2880 minutes = 48 hours
|
||||
email.validation.timeout=2880
|
||||
# The subject line for the email message.
|
||||
email.validation.subject=Welcome
|
||||
|
||||
#TODO: move description elsewhere, remove bad default
|
||||
# Get the Feedback to use for any outgoing emails.
|
||||
# NOTE: if feedback.path starts with a "/" it is appended to the end of the value provided in application.url
|
||||
# This value can be in the format/syntax of "/feedback.action" or even "mailto:feedback@application.com"
|
||||
#email.feedback.path=/feedback.action
|
||||
|
||||
#Set the application base URL. The default is to derive it from the HTTP request
|
||||
#application.url=http://myurl.mycompany.com
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# Auto Login Settings
|
||||
|
||||
security.rememberme.enabled=true
|
||||
# Timeout in minutes ( 525600 minutes = 1 year )
|
||||
security.rememberme.timeout=525600
|
||||
|
||||
# Single Sign On
|
||||
# Timeout in minutes
|
||||
security.signon.timeout=30
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# Default Username Values
|
||||
redback.default.admin=admin
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# Security Policies
|
||||
|
||||
#security.policy.password.encoder=
|
||||
security.policy.password.previous.count=6
|
||||
security.policy.password.expiration.enabled=true
|
||||
security.policy.password.expiration.days=90
|
||||
security.policy.password.expiration.notify.days=10
|
||||
security.policy.allowed.login.attempt=10
|
||||
|
||||
# turn off the perclick enforcement of various security policies, slightly
|
||||
# more heavyweight since it will ensure that the User object on each click
|
||||
# is up to date
|
||||
security.policy.strict.enforcement.enabled=true
|
||||
security.policy.strict.force.password.change.enabled=true
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# Password Rules
|
||||
security.policy.password.rule.alphanumeric.enabled=false
|
||||
security.policy.password.rule.alphacount.enabled=true
|
||||
security.policy.password.rule.alphacount.minimum=1
|
||||
security.policy.password.rule.characterlength.enabled=true
|
||||
security.policy.password.rule.characterlength.minimum=1
|
||||
security.policy.password.rule.characterlength.maximum=24
|
||||
security.policy.password.rule.musthave.enabled=true
|
||||
security.policy.password.rule.numericalcount.enabled=true
|
||||
security.policy.password.rule.numericalcount.minimum=1
|
||||
security.policy.password.rule.reuse.enabled=true
|
||||
security.policy.password.rule.nowhitespace.enabled=true
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# ldap settings
|
||||
#
|
||||
ldap.bind.authenticator.enabled=false
|
||||
|
||||
# ldap options for configuration via properties file
|
||||
#ldap.config.hostname=
|
||||
#ldap.config.port=
|
||||
#ldap.config.base.dn=
|
||||
#ldap.config.context.factory=
|
||||
#ldap.config.bind.dn=
|
||||
#ldap.config.password=
|
||||
#ldap.config.authentication.method=
|
||||
|
||||
# config parameter for the ConfigurableUserManager
|
||||
user.manager.impl=cached
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
package org.codehaus.plexus.redback.configuration;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2006 The Codehaus.
|
||||
*
|
||||
* Licensed 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 junit.framework.TestCase;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
/**
|
||||
* UserConfigurationTest
|
||||
*
|
||||
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
@RunWith( SpringJUnit4ClassRunner.class )
|
||||
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
|
||||
public class UserConfigurationTest
|
||||
extends TestCase
|
||||
{
|
||||
|
||||
@Inject @Named(value = "test")
|
||||
UserConfiguration config;
|
||||
|
||||
private void assertEmpty( String str )
|
||||
{
|
||||
if ( StringUtils.isNotEmpty( str ) )
|
||||
{
|
||||
fail( "Expected String to be empty." );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoad()
|
||||
throws Exception
|
||||
{
|
||||
assertNotNull( config );
|
||||
// check that the configuration loaded correctly - if this fails, maybe you aren't in the right basedir
|
||||
assertNotNull( config.getString( "test.value" ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetString()
|
||||
throws Exception
|
||||
{
|
||||
// Test default configuration entry
|
||||
assertEquals( "25", config.getString( "email.smtp.port" ) );
|
||||
// Test overlaid configuration entry
|
||||
assertEquals( "127.0.2.2", config.getString( "email.smtp.host" ) );
|
||||
// Test default value
|
||||
assertEquals( "127.0.0.1", config.getString( "email.smtp.host.bad", "127.0.0.1" ) );
|
||||
/* Requires commons-configuration 1.4
|
||||
// Test expressions
|
||||
assertEquals( "jdbc:derby:" + System.getProperty( "plexus.home" ) + "/database;create=true",
|
||||
config.getString( "jdbc.url" ) );
|
||||
assertEquals( "foo/bar", config.getString( "test.expression" ) );
|
||||
*/
|
||||
|
||||
assertEmpty( config.getString( "email.smtp.foo.foo" ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBoolean()
|
||||
throws Exception
|
||||
{
|
||||
assertFalse( config.getBoolean( "email.smtp.ssl.enabled" ) );
|
||||
assertFalse( config.getBoolean( "email.smtp.tls.enabled" ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInt()
|
||||
throws Exception
|
||||
{
|
||||
assertEquals( 25, config.getInt( "email.smtp.port" ) );
|
||||
assertEquals( 8080, config.getInt( "email.smtp.port.bad", 8080 ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConcatenatedList()
|
||||
{
|
||||
assertEquals( "uid=brett,dc=codehaus,dc=org", config.getConcatenatedList( "ldap.bind.dn", null ) );
|
||||
assertEquals( "dc=codehaus,dc=org", config.getConcatenatedList( "ldap.base.dn", null ) );
|
||||
assertEquals( "foo", config.getConcatenatedList( "short.list", null ) );
|
||||
assertEquals( "bar,baz", config.getConcatenatedList( "no.list", "bar,baz" ) );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd"
|
||||
default-lazy-init="true">
|
||||
|
||||
|
||||
<bean name="test" class="org.codehaus.plexus.redback.configuration.UserConfiguration">
|
||||
<property name="configs">
|
||||
<list>
|
||||
<value>src/test/resources/props/test-another.properties</value>
|
||||
<value>src/test/resources/props/test-overlaid.properties</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,4 @@
|
|||
email.smtp.host=127.0.2.2
|
||||
test.value=foo
|
||||
test.expression=${org.codehaus.plexus.security.test.value}/bar
|
||||
ldap.bind.dn=uid=brett,dc=codehaus,dc=org
|
|
@ -0,0 +1,6 @@
|
|||
email.smtp.host=127.0.1.1
|
||||
email.smtp.description=Testable Description
|
||||
#can't do this, it's appended
|
||||
#ldap.bind.dn=uid=user,dc=codehaus,dc=org
|
||||
ldap.base.dn=dc=codehaus,dc=org
|
||||
short.list=foo
|
|
@ -0,0 +1,80 @@
|
|||
<?xml version="1.0"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<artifactId>redback</artifactId>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>redback-data-management</artifactId>
|
||||
<name>Redback :: Data Management Utilities</name>
|
||||
<description>Back up, restore and upgrade utilities for JDO databases using XML</description>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-rbac-jdo</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-keys-jdo</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-users-jdo</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.annotation</groupId>
|
||||
<artifactId>jsr250-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-rbac-tests</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.derby</groupId>
|
||||
<artifactId>derby</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>stax</groupId>
|
||||
<artifactId>stax</artifactId>
|
||||
<version>1.1.1-dev</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>xmlbeans</groupId>
|
||||
<artifactId>xmlbeans-jsr173-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-collections</groupId>
|
||||
<artifactId>commons-collections</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<basedir>${basedir}</basedir>
|
||||
<derby.system.home>${project.build.directory}/test-home</derby.system.home>
|
||||
<plexus.home>${project.build.directory}/test-home</plexus.home>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,61 @@
|
|||
package org.codehaus.plexus.redback.management;
|
||||
|
||||
/*
|
||||
* Copyright 2006 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed 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.codehaus.plexus.redback.keys.KeyManager;
|
||||
import org.codehaus.plexus.redback.rbac.RBACManager;
|
||||
import org.codehaus.plexus.redback.rbac.RbacManagerException;
|
||||
import org.codehaus.plexus.redback.users.UserManager;
|
||||
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Data management tool API.
|
||||
*/
|
||||
public interface DataManagementTool
|
||||
{
|
||||
/**
|
||||
* Plexus role.
|
||||
*/
|
||||
String ROLE = DataManagementTool.class.getName();
|
||||
|
||||
void backupRBACDatabase( RBACManager manager, File backupDirectory )
|
||||
throws RbacManagerException, IOException, XMLStreamException;
|
||||
|
||||
void backupUserDatabase( UserManager manager, File backupDirectory )
|
||||
throws IOException, XMLStreamException;
|
||||
|
||||
void backupKeyDatabase( KeyManager manager, File backupDirectory )
|
||||
throws IOException, XMLStreamException;
|
||||
|
||||
void restoreRBACDatabase( RBACManager manager, File backupDirectory )
|
||||
throws IOException, XMLStreamException, RbacManagerException;
|
||||
|
||||
void restoreUsersDatabase( UserManager manager, File backupDirectory )
|
||||
throws IOException, XMLStreamException;
|
||||
|
||||
void restoreKeysDatabase( KeyManager manager, File backupDirectory )
|
||||
throws IOException, XMLStreamException;
|
||||
|
||||
void eraseRBACDatabase( RBACManager manager );
|
||||
|
||||
void eraseUsersDatabase( UserManager manager );
|
||||
|
||||
void eraseKeysDatabase( KeyManager manager );
|
||||
}
|
|
@ -0,0 +1,303 @@
|
|||
package org.codehaus.plexus.redback.management;
|
||||
|
||||
/*
|
||||
* Copyright 2006 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed 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 java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
|
||||
import org.codehaus.plexus.redback.keys.AuthenticationKey;
|
||||
import org.codehaus.plexus.redback.keys.KeyManager;
|
||||
import org.codehaus.plexus.redback.keys.KeyManagerException;
|
||||
import org.codehaus.plexus.redback.keys.jdo.AuthenticationKeyDatabase;
|
||||
import org.codehaus.plexus.redback.keys.jdo.io.stax.RedbackKeyManagementJdoStaxReader;
|
||||
import org.codehaus.plexus.redback.keys.jdo.io.stax.RedbackKeyManagementJdoStaxWriter;
|
||||
import org.codehaus.plexus.redback.rbac.Operation;
|
||||
import org.codehaus.plexus.redback.rbac.Permission;
|
||||
import org.codehaus.plexus.redback.rbac.RBACManager;
|
||||
import org.codehaus.plexus.redback.rbac.RbacManagerException;
|
||||
import org.codehaus.plexus.redback.rbac.Resource;
|
||||
import org.codehaus.plexus.redback.rbac.Role;
|
||||
import org.codehaus.plexus.redback.rbac.UserAssignment;
|
||||
import org.codehaus.plexus.redback.rbac.jdo.RbacDatabase;
|
||||
import org.codehaus.plexus.redback.rbac.jdo.io.stax.RbacJdoModelStaxReader;
|
||||
import org.codehaus.plexus.redback.rbac.jdo.io.stax.RbacJdoModelStaxWriter;
|
||||
import org.codehaus.plexus.redback.users.User;
|
||||
import org.codehaus.plexus.redback.users.UserManager;
|
||||
import org.codehaus.plexus.redback.users.jdo.UserDatabase;
|
||||
import org.codehaus.plexus.redback.users.jdo.io.stax.UsersManagementStaxReader;
|
||||
import org.codehaus.plexus.redback.users.jdo.io.stax.UsersManagementStaxWriter;
|
||||
import org.codehaus.plexus.util.IOUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* JDO implementation of the data management tool.
|
||||
*
|
||||
* @todo do we really need JDO specifics here? Could optimize by going straight to JDOFactory
|
||||
* @todo check whether this current method logs everything unnecessarily.
|
||||
*/
|
||||
@Service("dataManagementTool#jdo")
|
||||
public class JdoDataManagementTool
|
||||
implements DataManagementTool
|
||||
{
|
||||
private static final String USERS_XML_NAME = "users.xml";
|
||||
|
||||
private static final String KEYS_XML_NAME = "keys.xml";
|
||||
|
||||
private static final String RBAC_XML_NAME = "rbac.xml";
|
||||
|
||||
public void backupRBACDatabase( RBACManager manager, File backupDirectory )
|
||||
throws RbacManagerException, IOException, XMLStreamException
|
||||
{
|
||||
RbacDatabase database = new RbacDatabase();
|
||||
database.setRoles( manager.getAllRoles() );
|
||||
database.setUserAssignments( manager.getAllUserAssignments() );
|
||||
database.setPermissions( manager.getAllPermissions() );
|
||||
database.setOperations( manager.getAllOperations() );
|
||||
database.setResources( manager.getAllResources() );
|
||||
|
||||
RbacJdoModelStaxWriter writer = new RbacJdoModelStaxWriter();
|
||||
Writer fileWriter = createWriter( backupDirectory, RBAC_XML_NAME, database.getModelEncoding() );
|
||||
try
|
||||
{
|
||||
writer.write( fileWriter, database );
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close( fileWriter );
|
||||
}
|
||||
}
|
||||
|
||||
public void backupUserDatabase( UserManager manager, File backupDirectory )
|
||||
throws IOException, XMLStreamException
|
||||
{
|
||||
UserDatabase database = new UserDatabase();
|
||||
database.setUsers( manager.getUsers() );
|
||||
|
||||
UsersManagementStaxWriter writer = new UsersManagementStaxWriter();
|
||||
Writer fileWriter = createWriter( backupDirectory, USERS_XML_NAME, database.getModelEncoding() );
|
||||
try
|
||||
{
|
||||
writer.write( fileWriter, database );
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close( fileWriter );
|
||||
}
|
||||
}
|
||||
|
||||
public void backupKeyDatabase( KeyManager manager, File backupDirectory )
|
||||
throws IOException, XMLStreamException
|
||||
{
|
||||
try
|
||||
{
|
||||
manager.removeExpiredKeys();
|
||||
}
|
||||
catch ( KeyManagerException e )
|
||||
{
|
||||
throw new IOException( "Error removing expired keys" );
|
||||
}
|
||||
|
||||
AuthenticationKeyDatabase database = new AuthenticationKeyDatabase();
|
||||
database.setKeys( manager.getAllKeys() );
|
||||
|
||||
RedbackKeyManagementJdoStaxWriter writer = new RedbackKeyManagementJdoStaxWriter();
|
||||
Writer fileWriter = createWriter( backupDirectory, KEYS_XML_NAME, database.getModelEncoding() );
|
||||
try
|
||||
{
|
||||
writer.write( fileWriter, database );
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close( fileWriter );
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void restoreRBACDatabase( RBACManager manager, File backupDirectory )
|
||||
throws IOException, XMLStreamException, RbacManagerException
|
||||
{
|
||||
RbacJdoModelStaxReader reader = new RbacJdoModelStaxReader();
|
||||
|
||||
FileReader fileReader = new FileReader( new File( backupDirectory, RBAC_XML_NAME ) );
|
||||
|
||||
RbacDatabase database;
|
||||
try
|
||||
{
|
||||
database = reader.read( fileReader );
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close( fileReader );
|
||||
}
|
||||
|
||||
Map<String, Permission> permissionMap = new HashMap<String, Permission>();
|
||||
Map<String, Resource> resources = new HashMap<String, Resource>();
|
||||
Map<String, Operation> operations = new HashMap<String, Operation>();
|
||||
for ( Role role : (List<Role>) database.getRoles() )
|
||||
{
|
||||
// TODO: this could be generally useful and put into saveRole itself as long as the performance penalty isn't too harsh.
|
||||
// Currently it always saves everything where it could pull pack the existing permissions, etc if they exist
|
||||
List<Permission> permissions = new ArrayList<Permission>();
|
||||
for ( Permission permission : role.getPermissions() )
|
||||
{
|
||||
if ( permissionMap.containsKey( permission.getName() ) )
|
||||
{
|
||||
permission = permissionMap.get( permission.getName() );
|
||||
}
|
||||
else if ( manager.permissionExists( permission ) )
|
||||
{
|
||||
permission = manager.getPermission( permission.getName() );
|
||||
permissionMap.put( permission.getName(), permission );
|
||||
}
|
||||
else
|
||||
{
|
||||
Operation operation = permission.getOperation();
|
||||
if ( operations.containsKey( operation.getName() ) )
|
||||
{
|
||||
operation = operations.get( operation.getName() );
|
||||
}
|
||||
else if ( manager.operationExists( operation ) )
|
||||
{
|
||||
operation = manager.getOperation( operation.getName() );
|
||||
operations.put( operation.getName(), operation );
|
||||
}
|
||||
else
|
||||
{
|
||||
operation = manager.saveOperation( operation );
|
||||
operations.put( operation.getName(), operation );
|
||||
}
|
||||
permission.setOperation( operation );
|
||||
|
||||
Resource resource = permission.getResource();
|
||||
if ( resources.containsKey( resource.getIdentifier() ) )
|
||||
{
|
||||
resource = resources.get( resource.getIdentifier() );
|
||||
}
|
||||
else if ( manager.resourceExists( resource ) )
|
||||
{
|
||||
resource = manager.getResource( resource.getIdentifier() );
|
||||
resources.put( resource.getIdentifier(), resource );
|
||||
}
|
||||
else
|
||||
{
|
||||
resource = manager.saveResource( resource );
|
||||
resources.put( resource.getIdentifier(), resource );
|
||||
}
|
||||
permission.setResource( resource );
|
||||
|
||||
permission = manager.savePermission( permission );
|
||||
permissionMap.put( permission.getName(), permission );
|
||||
}
|
||||
permissions.add( permission );
|
||||
}
|
||||
role.setPermissions( permissions );
|
||||
|
||||
manager.saveRole( role );
|
||||
}
|
||||
|
||||
for ( UserAssignment userAssignment : (List<UserAssignment>) database.getUserAssignments() )
|
||||
{
|
||||
manager.saveUserAssignment( userAssignment );
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void restoreUsersDatabase( UserManager manager, File backupDirectory )
|
||||
throws IOException, XMLStreamException
|
||||
{
|
||||
UsersManagementStaxReader reader = new UsersManagementStaxReader();
|
||||
|
||||
FileReader fileReader = new FileReader( new File( backupDirectory, USERS_XML_NAME ) );
|
||||
|
||||
UserDatabase database;
|
||||
try
|
||||
{
|
||||
database = reader.read( fileReader );
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close( fileReader );
|
||||
}
|
||||
|
||||
for ( User user : (List<User>) database.getUsers() )
|
||||
{
|
||||
manager.addUserUnchecked( user );
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void restoreKeysDatabase( KeyManager manager, File backupDirectory )
|
||||
throws IOException, XMLStreamException
|
||||
{
|
||||
RedbackKeyManagementJdoStaxReader reader = new RedbackKeyManagementJdoStaxReader();
|
||||
|
||||
FileReader fileReader = new FileReader( new File( backupDirectory, KEYS_XML_NAME ) );
|
||||
|
||||
AuthenticationKeyDatabase database;
|
||||
try
|
||||
{
|
||||
database = reader.read( fileReader );
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close( fileReader );
|
||||
}
|
||||
|
||||
for ( AuthenticationKey key : (List<AuthenticationKey>) database.getKeys() )
|
||||
{
|
||||
manager.addKey( key );
|
||||
}
|
||||
}
|
||||
|
||||
public void eraseRBACDatabase( RBACManager manager )
|
||||
{
|
||||
manager.eraseDatabase();
|
||||
}
|
||||
|
||||
public void eraseUsersDatabase( UserManager manager )
|
||||
{
|
||||
manager.eraseDatabase();
|
||||
}
|
||||
|
||||
public void eraseKeysDatabase( KeyManager manager )
|
||||
{
|
||||
manager.eraseDatabase();
|
||||
}
|
||||
|
||||
private Writer createWriter( File directory, String file, String encoding )
|
||||
throws FileNotFoundException
|
||||
{
|
||||
File f = new File( directory, file );
|
||||
File parentFile = f.getParentFile();
|
||||
parentFile.mkdirs();
|
||||
|
||||
FileOutputStream out = new FileOutputStream( f );
|
||||
return new OutputStreamWriter( out, Charset.forName( encoding ) );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd"
|
||||
default-lazy-init="true">
|
||||
|
||||
<context:annotation-config />
|
||||
<context:component-scan
|
||||
base-package="org.codehaus.plexus.redback.management"/>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,453 @@
|
|||
package org.codehaus.plexus.redback.management;
|
||||
|
||||
/*
|
||||
* Copyright 2006
|
||||
*
|
||||
* Licensed 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 junit.framework.TestCase;
|
||||
import org.codehaus.plexus.redback.common.jdo.UserConfigurableJdoFactory;
|
||||
import org.codehaus.plexus.redback.keys.AuthenticationKey;
|
||||
import org.codehaus.plexus.redback.keys.KeyManager;
|
||||
import org.codehaus.plexus.redback.keys.KeyManagerException;
|
||||
import org.codehaus.plexus.redback.rbac.Permission;
|
||||
import org.codehaus.plexus.redback.rbac.RBACManager;
|
||||
import org.codehaus.plexus.redback.rbac.RbacManagerException;
|
||||
import org.codehaus.plexus.redback.rbac.Role;
|
||||
import org.codehaus.plexus.redback.rbac.UserAssignment;
|
||||
import org.codehaus.plexus.redback.tests.utils.RBACDefaults;
|
||||
import org.codehaus.plexus.redback.users.User;
|
||||
import org.codehaus.plexus.redback.users.UserManager;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
import org.codehaus.plexus.util.IOUtil;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
@RunWith( SpringJUnit4ClassRunner.class )
|
||||
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
|
||||
public class DataManagementTest
|
||||
extends TestCase
|
||||
{
|
||||
@Inject
|
||||
private DataManagementTool dataManagementTool;
|
||||
|
||||
private File targetDirectory;
|
||||
|
||||
@Inject
|
||||
@Named( value = "jdoFactory#users" )
|
||||
UserConfigurableJdoFactory jdoFactory;
|
||||
|
||||
@Inject
|
||||
@Named( value = "userManager#jdo" )
|
||||
UserManager userManager;
|
||||
|
||||
@Inject
|
||||
@Named( value = "keyManager#jdo" )
|
||||
KeyManager keyManager;
|
||||
|
||||
|
||||
@Inject
|
||||
@Named( value = "rBACManager#jdo" )
|
||||
RBACManager rbacManager;
|
||||
|
||||
@Before
|
||||
public void setUp()
|
||||
throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
targetDirectory = createBackupDirectory();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEraseUsers()
|
||||
throws Exception
|
||||
{
|
||||
|
||||
dataManagementTool.eraseUsersDatabase( userManager );
|
||||
|
||||
createUserDatabase( userManager );
|
||||
|
||||
dataManagementTool.eraseUsersDatabase( userManager );
|
||||
|
||||
assertEmpty( userManager );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEraseKeys()
|
||||
throws Exception
|
||||
{
|
||||
|
||||
createKeyDatabase( keyManager );
|
||||
|
||||
dataManagementTool.eraseKeysDatabase( keyManager );
|
||||
|
||||
assertEmpty( keyManager );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBackupRbac()
|
||||
throws Exception
|
||||
{
|
||||
RBACManager manager = rbacManager;
|
||||
|
||||
dataManagementTool.eraseRBACDatabase( manager );
|
||||
|
||||
createRbacDatabase( manager );
|
||||
|
||||
dataManagementTool.backupRBACDatabase( manager, targetDirectory );
|
||||
|
||||
File backupFile = new File( targetDirectory, "rbac.xml" );
|
||||
|
||||
assertTrue( "Check database exists", backupFile.exists() );
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
|
||||
IOUtil.copy( getClass().getResourceAsStream( "/expected-rbac.xml" ), sw );
|
||||
|
||||
assertEquals( "Check database content", convertLineEndings( sw.toString() ).trim(),
|
||||
fixXmlQuotes( FileUtils.fileRead( backupFile ) ).trim() );
|
||||
|
||||
}
|
||||
|
||||
private void createRbacDatabase( RBACManager manager )
|
||||
throws RbacManagerException
|
||||
{
|
||||
RBACDefaults defaults = new RBACDefaults( manager );
|
||||
|
||||
defaults.createDefaults();
|
||||
|
||||
UserAssignment assignment = manager.createUserAssignment( "bob" );
|
||||
assignment.addRoleName( "Developer" );
|
||||
manager.saveUserAssignment( assignment );
|
||||
|
||||
assignment = manager.createUserAssignment( "betty" );
|
||||
assignment.addRoleName( "System Administrator" );
|
||||
manager.saveUserAssignment( assignment );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBackupUsers()
|
||||
throws Exception
|
||||
{
|
||||
UserManager manager = userManager;
|
||||
|
||||
createUserDatabase( manager );
|
||||
|
||||
dataManagementTool.backupUserDatabase( manager, targetDirectory );
|
||||
|
||||
File backupFile = new File( targetDirectory, "users.xml" );
|
||||
|
||||
assertTrue( "Check database exists", backupFile.exists() );
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
|
||||
IOUtil.copy( getClass().getResourceAsStream( "/expected-users.xml" ), sw );
|
||||
|
||||
String actual = FileUtils.fileRead( backupFile ).trim();
|
||||
String expected = sw.toString().trim();
|
||||
assertEquals( "Check database content", convertLineEndings( removeTimestampVariance( expected ) ),
|
||||
fixXmlQuotes( removeTimestampVariance( actual ) ) );
|
||||
}
|
||||
|
||||
private void createUserDatabase( UserManager manager )
|
||||
{
|
||||
User user = manager.createUser( "smcqueen", "Steve McQueen", "the cooler king" );
|
||||
user.setPassword( "abc123" );
|
||||
manager.addUser( user );
|
||||
|
||||
user = manager.createUser( "bob", "Sideshow Bob", "bob_862@hotmail.com" );
|
||||
user.setPassword( "bobby862" );
|
||||
manager.addUser( user );
|
||||
|
||||
user = manager.createUser( "betty", "Betty", "betty@aol.com" );
|
||||
user.setPassword( "rover2" );
|
||||
manager.addUser( user );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBackupKeys()
|
||||
throws Exception
|
||||
{
|
||||
KeyManager manager = keyManager;
|
||||
|
||||
createKeyDatabase( manager );
|
||||
|
||||
Thread.sleep( 60000 );
|
||||
|
||||
dataManagementTool.backupKeyDatabase( manager, targetDirectory );
|
||||
|
||||
File backupFile = new File( targetDirectory, "keys.xml" );
|
||||
|
||||
assertTrue( "Check database exists", backupFile.exists() );
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
|
||||
IOUtil.copy( getClass().getResourceAsStream( "/expected-keys.xml" ), sw );
|
||||
|
||||
String actual = FileUtils.fileRead( backupFile ).trim();
|
||||
String expected = sw.toString().trim();
|
||||
assertEquals( "Check database content", convertLineEndings( removeKeyAndTimestampVariance( expected ) ),
|
||||
fixXmlQuotes( removeKeyAndTimestampVariance( actual ) ) );
|
||||
}
|
||||
|
||||
private static void createKeyDatabase( KeyManager manager )
|
||||
throws KeyManagerException
|
||||
{
|
||||
manager.createKey( "bob", "Testing", 15 );
|
||||
manager.createKey( "betty", "Something", 25 );
|
||||
manager.createKey( "fred", "Else", 30 );
|
||||
manager.createKey( "tony", "Expired", 0 );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRestoreRbac()
|
||||
throws Exception
|
||||
{
|
||||
RBACManager manager = rbacManager;
|
||||
|
||||
dataManagementTool.eraseRBACDatabase( manager );
|
||||
|
||||
assertEmpty( manager );
|
||||
|
||||
File backupFile = new File( targetDirectory, "rbac.xml" );
|
||||
|
||||
IOUtil.copy( getClass().getResourceAsStream( "/expected-rbac.xml" ), new FileWriter( backupFile ) );
|
||||
|
||||
dataManagementTool.restoreRBACDatabase( manager, targetDirectory );
|
||||
|
||||
List<Role> roles = manager.getAllRoles();
|
||||
List<UserAssignment> assignments = manager.getAllUserAssignments();
|
||||
assertEquals( 4, roles.size() );
|
||||
assertEquals( 2, assignments.size() );
|
||||
assertEquals( 6, manager.getAllOperations().size() );
|
||||
assertEquals( 1, manager.getAllResources().size() );
|
||||
assertEquals( 6, manager.getAllPermissions().size() );
|
||||
|
||||
Role role = (Role) roles.get( 0 );
|
||||
assertEquals( "User Administrator", role.getName() );
|
||||
assertTrue( role.isAssignable() );
|
||||
assertEquals( 2, role.getPermissions().size() );
|
||||
assertPermission( (Permission) role.getPermissions().get( 0 ), "Edit All Users", "edit-all-users", "*" );
|
||||
assertPermission( (Permission) role.getPermissions().get( 1 ), "Remove Roles", "remove-roles", "*" );
|
||||
|
||||
role = (Role) roles.get( 1 );
|
||||
assertEquals( "System Administrator", role.getName() );
|
||||
assertTrue( role.isAssignable() );
|
||||
assertEquals( 1, role.getChildRoleNames().size() );
|
||||
assertEquals( "User Administrator", role.getChildRoleNames().get( 0 ) );
|
||||
assertEquals( 4, role.getPermissions().size() );
|
||||
assertPermission( (Permission) role.getPermissions().get( 0 ), "Edit Configuration", "edit-configuration",
|
||||
"*" );
|
||||
assertPermission( (Permission) role.getPermissions().get( 1 ), "Run Indexer", "run-indexer", "*" );
|
||||
assertPermission( (Permission) role.getPermissions().get( 2 ), "Add Repository", "add-repository", "*" );
|
||||
assertPermission( (Permission) role.getPermissions().get( 3 ), "Regenerate Index", "regenerate-index", "*" );
|
||||
|
||||
role = (Role) roles.get( 2 );
|
||||
assertEquals( "Trusted Developer", role.getName() );
|
||||
assertTrue( role.isAssignable() );
|
||||
assertEquals( 1, role.getChildRoleNames().size() );
|
||||
assertEquals( "System Administrator", role.getChildRoleNames().get( 0 ) );
|
||||
assertEquals( 1, role.getPermissions().size() );
|
||||
assertPermission( (Permission) role.getPermissions().get( 0 ), "Run Indexer", "run-indexer", "*" );
|
||||
|
||||
role = (Role) roles.get( 3 );
|
||||
assertEquals( "Developer", role.getName() );
|
||||
assertTrue( role.isAssignable() );
|
||||
assertEquals( 1, role.getChildRoleNames().size() );
|
||||
assertEquals( "Trusted Developer", role.getChildRoleNames().get( 0 ) );
|
||||
assertEquals( 1, role.getPermissions().size() );
|
||||
assertPermission( (Permission) role.getPermissions().get( 0 ), "Run Indexer", "run-indexer", "*" );
|
||||
|
||||
UserAssignment assignment = (UserAssignment) assignments.get( 0 );
|
||||
assertEquals( "bob", assignment.getPrincipal() );
|
||||
assertEquals( 1, assignment.getRoleNames().size() );
|
||||
assertEquals( "Developer", assignment.getRoleNames().get( 0 ) );
|
||||
|
||||
assignment = (UserAssignment) assignments.get( 1 );
|
||||
assertEquals( "betty", assignment.getPrincipal() );
|
||||
assertEquals( 1, assignment.getRoleNames().size() );
|
||||
assertEquals( "System Administrator", assignment.getRoleNames().get( 0 ) );
|
||||
}
|
||||
|
||||
private void assertEmpty( RBACManager manager )
|
||||
throws RbacManagerException
|
||||
{
|
||||
assertEquals( 0, manager.getAllRoles().size() );
|
||||
assertEquals( 0, manager.getAllUserAssignments().size() );
|
||||
assertEquals( 0, manager.getAllOperations().size() );
|
||||
assertEquals( 0, manager.getAllResources().size() );
|
||||
assertEquals( 0, manager.getAllPermissions().size() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRestoreUsers()
|
||||
throws Exception
|
||||
{
|
||||
UserManager manager = userManager;
|
||||
|
||||
dataManagementTool.eraseUsersDatabase( manager );
|
||||
|
||||
assertEmpty( manager );
|
||||
|
||||
File backupFile = new File( targetDirectory, "users.xml" );
|
||||
|
||||
IOUtil.copy( getClass().getResourceAsStream( "/expected-users.xml" ), new FileWriter( backupFile ) );
|
||||
|
||||
dataManagementTool.restoreUsersDatabase( manager, targetDirectory );
|
||||
|
||||
List<User> users = manager.getUsers();
|
||||
assertEquals( 3, users.size() );
|
||||
|
||||
User user = (User) users.get( 0 );
|
||||
assertEquals( "smcqueen", user.getUsername() );
|
||||
assertEquals( "bKE9UspwyIPg8LsQHkJaiehiTeUdstI5JZOvaoQRgJA=", user.getEncodedPassword() );
|
||||
assertEquals( "Steve McQueen", user.getFullName() );
|
||||
assertEquals( "the cooler king", user.getEmail() );
|
||||
assertEquals( 1164424661686L, user.getLastPasswordChange().getTime() );
|
||||
assertEquals( Arrays.asList( new String[]{ "bKE9UspwyIPg8LsQHkJaiehiTeUdstI5JZOvaoQRgJA=" } ),
|
||||
user.getPreviousEncodedPasswords() );
|
||||
|
||||
user = (User) users.get( 1 );
|
||||
assertEquals( "bob", user.getUsername() );
|
||||
assertEquals( "A0MR+q0lm554bD6Uft60ztlYZ8N1pEqXhKNM9H7SlS8=", user.getEncodedPassword() );
|
||||
assertEquals( "Sideshow Bob", user.getFullName() );
|
||||
assertEquals( "bob_862@hotmail.com", user.getEmail() );
|
||||
assertEquals( 1164424669526L, user.getLastPasswordChange().getTime() );
|
||||
assertEquals( Arrays.asList( new String[]{ "A0MR+q0lm554bD6Uft60ztlYZ8N1pEqXhKNM9H7SlS8=" } ),
|
||||
user.getPreviousEncodedPasswords() );
|
||||
|
||||
user = (User) users.get( 2 );
|
||||
assertEquals( "betty", user.getUsername() );
|
||||
assertEquals( "L/mA/suWallwvYzw4wyRYkn5y8zWxAITuv4sLhJLN1E=", user.getEncodedPassword() );
|
||||
assertEquals( "Betty", user.getFullName() );
|
||||
assertEquals( "betty@aol.com", user.getEmail() );
|
||||
assertEquals( 1164424669536L, user.getLastPasswordChange().getTime() );
|
||||
assertEquals( Arrays.asList( new String[]{ "L/mA/suWallwvYzw4wyRYkn5y8zWxAITuv4sLhJLN1E=" } ),
|
||||
user.getPreviousEncodedPasswords() );
|
||||
}
|
||||
|
||||
private void assertEmpty( UserManager manager )
|
||||
{
|
||||
List<User> users = manager.getUsers();
|
||||
assertEquals( 0, users.size() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRestoreKeys()
|
||||
throws Exception
|
||||
{
|
||||
KeyManager manager = keyManager;
|
||||
|
||||
dataManagementTool.eraseKeysDatabase( manager );
|
||||
|
||||
assertEmpty( manager );
|
||||
|
||||
File backupFile = new File( targetDirectory, "keys.xml" );
|
||||
|
||||
IOUtil.copy( getClass().getResourceAsStream( "/expected-keys.xml" ), new FileWriter( backupFile ) );
|
||||
|
||||
dataManagementTool.restoreKeysDatabase( manager, targetDirectory );
|
||||
|
||||
List<AuthenticationKey> keys = manager.getAllKeys();
|
||||
assertEquals( 3, keys.size() );
|
||||
|
||||
AuthenticationKey key = (AuthenticationKey) keys.get( 0 );
|
||||
assertEquals( "248df0fec5d54e3eb11339f5e81d8bd7", key.getKey() );
|
||||
assertEquals( "bob", key.getForPrincipal() );
|
||||
assertEquals( "Testing", key.getPurpose() );
|
||||
assertEquals( 1164426311921L, key.getDateCreated().getTime() );
|
||||
assertEquals( 1164427211921L, key.getDateExpires().getTime() );
|
||||
|
||||
key = (AuthenticationKey) keys.get( 1 );
|
||||
assertEquals( "a98dddc2ae614a7c82f8afd3ba6e39fb", key.getKey() );
|
||||
assertEquals( "betty", key.getForPrincipal() );
|
||||
assertEquals( "Something", key.getPurpose() );
|
||||
assertEquals( 1164426315657L, key.getDateCreated().getTime() );
|
||||
assertEquals( 1164427815657L, key.getDateExpires().getTime() );
|
||||
|
||||
key = (AuthenticationKey) keys.get( 2 );
|
||||
assertEquals( "1428d2ca3a0246f0a1d979504e351388", key.getKey() );
|
||||
assertEquals( "fred", key.getForPrincipal() );
|
||||
assertEquals( "Else", key.getPurpose() );
|
||||
assertEquals( 1164426315664L, key.getDateCreated().getTime() );
|
||||
assertEquals( 1164428115664L, key.getDateExpires().getTime() );
|
||||
}
|
||||
|
||||
private void assertEmpty( KeyManager manager )
|
||||
{
|
||||
assertEquals( 0, manager.getAllKeys().size() );
|
||||
}
|
||||
|
||||
private String removeKeyAndTimestampVariance( String content )
|
||||
{
|
||||
return removeTagContent( removeTagContent( removeTagContent( content, "dateCreated" ), "dateExpires" ), "key" );
|
||||
}
|
||||
|
||||
private static String removeTimestampVariance( String content )
|
||||
{
|
||||
return removeTagContent( removeTagContent( content, "lastPasswordChange" ), "accountCreationDate" );
|
||||
}
|
||||
|
||||
private static String removeTagContent( String content, String field )
|
||||
{
|
||||
return content.replaceAll( "<" + field + ">.*</" + field + ">", "<" + field + "></" + field + ">" );
|
||||
}
|
||||
|
||||
private static void assertPermission( Permission permission, String name, String operation, String resource )
|
||||
{
|
||||
assertEquals( name, permission.getName() );
|
||||
assertEquals( operation, permission.getOperation().getName() );
|
||||
assertEquals( resource, permission.getResource().getIdentifier() );
|
||||
}
|
||||
|
||||
private static File createBackupDirectory()
|
||||
{
|
||||
String timestamp = new SimpleDateFormat( "yyyyMMdd.HHmmss", Locale.US ).format( new Date() );
|
||||
|
||||
File targetDirectory = new File( "./target/backups/" + timestamp );
|
||||
targetDirectory.mkdirs();
|
||||
|
||||
return targetDirectory;
|
||||
}
|
||||
|
||||
private static String fixXmlQuotes( String s )
|
||||
{
|
||||
if ( s.startsWith( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" ) )
|
||||
{
|
||||
return "<?xml version='1.0' encoding='UTF-8'?>" + s.substring(
|
||||
"<?xml version='1.0' encoding='UTF-8'?>".length() );
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
private String convertLineEndings( String s )
|
||||
{
|
||||
return s.replaceAll( "\r\n", "\n" );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<authenticationKeyDatabase>
|
||||
<keys>
|
||||
<key>
|
||||
<key>248df0fec5d54e3eb11339f5e81d8bd7</key>
|
||||
<forPrincipal>bob</forPrincipal>
|
||||
<purpose>Testing</purpose>
|
||||
<dateCreated>1164426311921</dateCreated>
|
||||
<dateExpires>1164427211921</dateExpires>
|
||||
</key>
|
||||
<key>
|
||||
<key>a98dddc2ae614a7c82f8afd3ba6e39fb</key>
|
||||
<forPrincipal>betty</forPrincipal>
|
||||
<purpose>Something</purpose>
|
||||
<dateCreated>1164426315657</dateCreated>
|
||||
<dateExpires>1164427815657</dateExpires>
|
||||
</key>
|
||||
<key>
|
||||
<key>1428d2ca3a0246f0a1d979504e351388</key>
|
||||
<forPrincipal>fred</forPrincipal>
|
||||
<purpose>Else</purpose>
|
||||
<dateCreated>1164426315664</dateCreated>
|
||||
<dateExpires>1164428115664</dateExpires>
|
||||
</key>
|
||||
</keys>
|
||||
</authenticationKeyDatabase>
|
|
@ -0,0 +1,133 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<rbacDatabase>
|
||||
<roles>
|
||||
<role>
|
||||
<name>User Administrator</name>
|
||||
<assignable>true</assignable>
|
||||
<permissions>
|
||||
<permission name="Edit All Users"></permission>
|
||||
<permission name="Remove Roles"></permission>
|
||||
</permissions>
|
||||
</role>
|
||||
<role>
|
||||
<name>System Administrator</name>
|
||||
<assignable>true</assignable>
|
||||
<childRoleNames>
|
||||
<childRoleName>User Administrator</childRoleName>
|
||||
</childRoleNames>
|
||||
<permissions>
|
||||
<permission name="Edit Configuration"></permission>
|
||||
<permission name="Run Indexer"></permission>
|
||||
<permission name="Add Repository"></permission>
|
||||
<permission name="Regenerate Index"></permission>
|
||||
</permissions>
|
||||
</role>
|
||||
<role>
|
||||
<name>Trusted Developer</name>
|
||||
<assignable>true</assignable>
|
||||
<childRoleNames>
|
||||
<childRoleName>System Administrator</childRoleName>
|
||||
</childRoleNames>
|
||||
<permissions>
|
||||
<permission name="Run Indexer"></permission>
|
||||
</permissions>
|
||||
</role>
|
||||
<role>
|
||||
<name>Developer</name>
|
||||
<assignable>true</assignable>
|
||||
<childRoleNames>
|
||||
<childRoleName>Trusted Developer</childRoleName>
|
||||
</childRoleNames>
|
||||
<permissions>
|
||||
<permission name="Run Indexer"></permission>
|
||||
</permissions>
|
||||
</role>
|
||||
</roles>
|
||||
<permissions>
|
||||
<permission>
|
||||
<name>Edit Configuration</name>
|
||||
<operation name="edit-configuration"></operation>
|
||||
<resource identifier="*"></resource>
|
||||
</permission>
|
||||
<permission>
|
||||
<name>Run Indexer</name>
|
||||
<operation name="run-indexer"></operation>
|
||||
<resource identifier="*"></resource>
|
||||
</permission>
|
||||
<permission>
|
||||
<name>Add Repository</name>
|
||||
<operation name="add-repository"></operation>
|
||||
<resource identifier="*"></resource>
|
||||
</permission>
|
||||
<permission>
|
||||
<name>Edit All Users</name>
|
||||
<operation name="edit-all-users"></operation>
|
||||
<resource identifier="*"></resource>
|
||||
</permission>
|
||||
<permission>
|
||||
<name>Remove Roles</name>
|
||||
<operation name="remove-roles"></operation>
|
||||
<resource identifier="*"></resource>
|
||||
</permission>
|
||||
<permission>
|
||||
<name>Regenerate Index</name>
|
||||
<operation name="regenerate-index"></operation>
|
||||
<resource identifier="*"></resource>
|
||||
</permission>
|
||||
</permissions>
|
||||
<operations>
|
||||
<operation>
|
||||
<name>add-repository</name>
|
||||
</operation>
|
||||
<operation>
|
||||
<name>edit-repository</name>
|
||||
</operation>
|
||||
<operation>
|
||||
<name>delete-repository</name>
|
||||
</operation>
|
||||
<operation>
|
||||
<name>edit-configuration</name>
|
||||
</operation>
|
||||
<operation>
|
||||
<name>run-indexer</name>
|
||||
</operation>
|
||||
<operation>
|
||||
<name>regenerate-index</name>
|
||||
</operation>
|
||||
<operation>
|
||||
<name>get-reports</name>
|
||||
</operation>
|
||||
<operation>
|
||||
<name>regenerate-reports</name>
|
||||
</operation>
|
||||
<operation>
|
||||
<name>edit-user</name>
|
||||
</operation>
|
||||
<operation>
|
||||
<name>edit-all-users</name>
|
||||
</operation>
|
||||
<operation>
|
||||
<name>remove-roles</name>
|
||||
</operation>
|
||||
</operations>
|
||||
<resources>
|
||||
<resource>
|
||||
<identifier>*</identifier>
|
||||
<permanent>true</permanent>
|
||||
</resource>
|
||||
</resources>
|
||||
<userAssignments>
|
||||
<userAssignment>
|
||||
<principal>bob</principal>
|
||||
<roleNames>
|
||||
<roleName>Developer</roleName>
|
||||
</roleNames>
|
||||
</userAssignment>
|
||||
<userAssignment>
|
||||
<principal>betty</principal>
|
||||
<roleNames>
|
||||
<roleName>System Administrator</roleName>
|
||||
</roleNames>
|
||||
</userAssignment>
|
||||
</userAssignments>
|
||||
</rbacDatabase>
|
|
@ -0,0 +1,41 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<userDatabase>
|
||||
<users>
|
||||
<user>
|
||||
<username>smcqueen</username>
|
||||
<encodedPassword>bKE9UspwyIPg8LsQHkJaiehiTeUdstI5JZOvaoQRgJA=</encodedPassword>
|
||||
<fullName>Steve McQueen</fullName>
|
||||
<email>the cooler king</email>
|
||||
<lastPasswordChange>1164424661686</lastPasswordChange>
|
||||
<passwordChangeRequired>true</passwordChangeRequired>
|
||||
<previousEncodedPasswords>
|
||||
<previousEncodedPassword>bKE9UspwyIPg8LsQHkJaiehiTeUdstI5JZOvaoQRgJA=</previousEncodedPassword>
|
||||
</previousEncodedPasswords>
|
||||
<accountCreationDate>1164424661686</accountCreationDate>
|
||||
</user>
|
||||
<user>
|
||||
<username>bob</username>
|
||||
<encodedPassword>A0MR+q0lm554bD6Uft60ztlYZ8N1pEqXhKNM9H7SlS8=</encodedPassword>
|
||||
<fullName>Sideshow Bob</fullName>
|
||||
<email>bob_862@hotmail.com</email>
|
||||
<lastPasswordChange>1164424669526</lastPasswordChange>
|
||||
<passwordChangeRequired>true</passwordChangeRequired>
|
||||
<previousEncodedPasswords>
|
||||
<previousEncodedPassword>A0MR+q0lm554bD6Uft60ztlYZ8N1pEqXhKNM9H7SlS8=</previousEncodedPassword>
|
||||
</previousEncodedPasswords>
|
||||
<accountCreationDate>1164424661686</accountCreationDate>
|
||||
</user>
|
||||
<user>
|
||||
<username>betty</username>
|
||||
<encodedPassword>L/mA/suWallwvYzw4wyRYkn5y8zWxAITuv4sLhJLN1E=</encodedPassword>
|
||||
<fullName>Betty</fullName>
|
||||
<email>betty@aol.com</email>
|
||||
<lastPasswordChange>1164424669536</lastPasswordChange>
|
||||
<passwordChangeRequired>true</passwordChangeRequired>
|
||||
<previousEncodedPasswords>
|
||||
<previousEncodedPassword>L/mA/suWallwvYzw4wyRYkn5y8zWxAITuv4sLhJLN1E=</previousEncodedPassword>
|
||||
</previousEncodedPasswords>
|
||||
<accountCreationDate>1164424661686</accountCreationDate>
|
||||
</user>
|
||||
</users>
|
||||
</userDatabase>
|
|
@ -0,0 +1,127 @@
|
|||
jdbc.url=jdbc:derby:target/database;create=true
|
||||
#
|
||||
# Copyright 2006 The Codehaus.
|
||||
#
|
||||
# Licensed 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.
|
||||
#
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# Application Configuration
|
||||
|
||||
application.timestamp=EEE d MMM yyyy HH:mm:ss Z
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# JDBC Setup
|
||||
|
||||
jdbc.driver.name=org.apache.derby.jdbc.EmbeddedDriver
|
||||
jdbc.username=sa
|
||||
jdbc.password=
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# Email Settings
|
||||
|
||||
email.jndiSessionName=java:comp/env/mail/Session
|
||||
email.smtp.host=localhost
|
||||
email.smtp.port=25
|
||||
email.smtp.ssl.enabled=false
|
||||
email.smtp.tls.enabled=false
|
||||
email.smtp.username=
|
||||
email.smtp.password=
|
||||
|
||||
#TODO: move description elsewhere, remove bad default
|
||||
# All emails sent by the system will be from the following address
|
||||
#email.from.address=${user.name}@localhost
|
||||
# All emails sent by the system will be from the following user name (used in conjunction with address)
|
||||
#email.from.name=Unconfigured Username
|
||||
|
||||
# If all email addresses (from new user registration) require an account validation email.
|
||||
email.validation.required=true
|
||||
# Timeout (in minutes) for the key generated for an email validation to remain valid.
|
||||
# 2880 minutes = 48 hours
|
||||
email.validation.timeout=2880
|
||||
# The subject line for the email message.
|
||||
email.validation.subject=Welcome
|
||||
|
||||
#TODO: move description elsewhere, remove bad default
|
||||
# Get the Feedback to use for any outgoing emails.
|
||||
# NOTE: if feedback.path starts with a "/" it is appended to the end of the value provided in application.url
|
||||
# This value can be in the format/syntax of "/feedback.action" or even "mailto:feedback@application.com"
|
||||
#email.feedback.path=/feedback.action
|
||||
|
||||
#Set the application base URL. The default is to derive it from the HTTP request
|
||||
#application.url=http://myurl.mycompany.com
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# Auto Login Settings
|
||||
|
||||
security.rememberme.enabled=true
|
||||
# Timeout in minutes ( 525600 minutes = 1 year )
|
||||
security.rememberme.timeout=525600
|
||||
|
||||
# Single Sign On
|
||||
# Timeout in minutes
|
||||
security.signon.timeout=30
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# Default Username Values
|
||||
redback.default.admin=admin
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# Security Policies
|
||||
|
||||
#security.policy.password.encoder=
|
||||
security.policy.password.previous.count=6
|
||||
security.policy.password.expiration.enabled=true
|
||||
security.policy.password.expiration.days=90
|
||||
security.policy.password.expiration.notify.days=10
|
||||
security.policy.allowed.login.attempt=10
|
||||
|
||||
# turn off the perclick enforcement of various security policies, slightly
|
||||
# more heavyweight since it will ensure that the User object on each click
|
||||
# is up to date
|
||||
security.policy.strict.enforcement.enabled=true
|
||||
security.policy.strict.force.password.change.enabled=true
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# Password Rules
|
||||
security.policy.password.rule.alphanumeric.enabled=false
|
||||
security.policy.password.rule.alphacount.enabled=true
|
||||
security.policy.password.rule.alphacount.minimum=1
|
||||
security.policy.password.rule.characterlength.enabled=true
|
||||
security.policy.password.rule.characterlength.minimum=1
|
||||
security.policy.password.rule.characterlength.maximum=24
|
||||
security.policy.password.rule.musthave.enabled=true
|
||||
security.policy.password.rule.numericalcount.enabled=true
|
||||
security.policy.password.rule.numericalcount.minimum=1
|
||||
security.policy.password.rule.reuse.enabled=true
|
||||
security.policy.password.rule.nowhitespace.enabled=true
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# ldap settings
|
||||
#
|
||||
ldap.bind.authenticator.enabled=false
|
||||
|
||||
# ldap options for configuration via properties file
|
||||
#ldap.config.hostname=
|
||||
#ldap.config.port=
|
||||
#ldap.config.base.dn=
|
||||
#ldap.config.context.factory=
|
||||
#ldap.config.bind.dn=
|
||||
#ldap.config.password=
|
||||
#ldap.config.authentication.method=
|
||||
|
||||
# config parameter for the ConfigurableUserManager
|
||||
user.manager.impl=cached
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||
|
||||
<context:property-placeholder system-properties-mode="OVERRIDE"/>
|
||||
|
||||
<bean name="jdoFactory#users" class="org.codehaus.plexus.redback.common.jdo.UserConfigurableJdoFactory">
|
||||
<property name="config" ref="userConfiguration"/>
|
||||
<property name="driverName" value="org.apache.derby.jdbc.EmbeddedDriver"/>
|
||||
<property name="url" value="jdbc:derby:${basedir}/target" />
|
||||
<property name="userName" value="sa"/>
|
||||
<property name="password" value=""/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,60 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 2006 The Codehaus.
|
||||
~
|
||||
~ Licensed 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.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback</artifactId>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>redback-integrations</artifactId>
|
||||
<name>Redback :: Integrations</name>
|
||||
<packaging>pom</packaging>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-common-integrations</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>taglibs</groupId>
|
||||
<artifactId>standard</artifactId>
|
||||
<version>1.1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>jstl</artifactId>
|
||||
<version>1.1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>jsp-api</artifactId>
|
||||
<version>2.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<modules>
|
||||
<module>redback-common-integrations</module>
|
||||
<module>redback-rest</module>
|
||||
<module>redback-struts2</module>
|
||||
<module>redback-jee</module>
|
||||
<module>redback-jsecurity</module>
|
||||
<module>redback-integrations-security</module>
|
||||
</modules>
|
||||
</project>
|
|
@ -0,0 +1,218 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 2005-2006 The Codehaus.
|
||||
~
|
||||
~ Licensed 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.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-integrations</artifactId>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>redback-common-integrations</artifactId>
|
||||
<name>Redback :: Integration :: Common</name>
|
||||
<packaging>jar</packaging>
|
||||
<dependencies>
|
||||
<!-- ================================================================ -->
|
||||
<!-- Core Plexus Security Dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-configuration</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-system</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-policy</artifactId>
|
||||
</dependency>
|
||||
<!-- User Management / Authentication -->
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-authentication-users</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-authentication-ldap</artifactId>
|
||||
</dependency>
|
||||
<!-- Keys Management / Authentication -->
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-keys-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-authentication-keys</artifactId>
|
||||
</dependency>
|
||||
<!-- RBAC Management / Authorization -->
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-authorization-rbac</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-rbac-role-manager</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-rbac-cached</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-users-ldap</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-users-configurable</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-data-management</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-integrations-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
</dependency>
|
||||
<!-- ================================================================ -->
|
||||
<!-- OTHER Dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.mail</groupId>
|
||||
<artifactId>mail</artifactId>
|
||||
<version>1.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.annotation</groupId>
|
||||
<artifactId>jsr250-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.extremecomponents</groupId>
|
||||
<artifactId>extremecomponents</artifactId>
|
||||
<version>1.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-beanutils</groupId>
|
||||
<artifactId>commons-beanutils-bean-collections</artifactId>
|
||||
<version>1.7.0</version>
|
||||
<!-- Needed by extremecomponents -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-utils</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>jsp-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>taglibs</groupId>
|
||||
<artifactId>standard</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>jstl</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-collections</groupId>
|
||||
<artifactId>commons-collections</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
</dependency>
|
||||
<!-- === Test Dependencies ======================= -->
|
||||
<dependency>
|
||||
<groupId>org.hsqldb</groupId>
|
||||
<artifactId>hsqldb</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.derby</groupId>
|
||||
<artifactId>derby</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-keys-memory</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-keys-cached</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-common-test-resources</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<basedir>${basedir}</basedir>
|
||||
<derby.system.home>${project.build.directory}/test-home</derby.system.home>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,77 @@
|
|||
package org.codehaus.redback.integration;
|
||||
|
||||
/*
|
||||
* Copyright 2005-2006 The Codehaus.
|
||||
*
|
||||
* Licensed 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 java.util.Properties;
|
||||
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Collection of Utility methods useful in an Http environment.
|
||||
*
|
||||
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
* @todo should move this to plexus-utils or plexus-utils-web
|
||||
*/
|
||||
public class HttpUtils
|
||||
{
|
||||
/**
|
||||
* Convert typical complex header into properties.
|
||||
* <p/>
|
||||
* <p/>
|
||||
* Example:
|
||||
* </p>
|
||||
* <p/>
|
||||
* <code>
|
||||
* realm="Somewhere Over The Rainbow", domain="kansas.co.us", nonce="65743ABCF"
|
||||
* </code>
|
||||
* <p/>
|
||||
* <p>becomes</p>
|
||||
* <p/>
|
||||
* <code>
|
||||
* Map ( "realm", "Somewhere Over The Rainbox" )
|
||||
* Map ( "domain", "kansas.co.us" )
|
||||
* Map ( "nonce", "65743ABCF" )
|
||||
* </code>
|
||||
*
|
||||
* @param rawheader
|
||||
* @param majorDelim
|
||||
* @param subDelim
|
||||
* @return
|
||||
*/
|
||||
public static Properties complexHeaderToProperties( String rawheader, String majorDelim, String subDelim )
|
||||
{
|
||||
Properties ret = new Properties();
|
||||
|
||||
if ( StringUtils.isEmpty( rawheader ) )
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
String array[] = StringUtils.split( rawheader, majorDelim );
|
||||
for ( int i = 0; i < array.length; i++ )
|
||||
{
|
||||
// String quotes.
|
||||
String rawelem = StringUtils.replace( array[i], "\"", "" );
|
||||
String parts[] = StringUtils.split( rawelem, subDelim, 2 );
|
||||
|
||||
ret.setProperty( StringUtils.trim( parts[0] ), StringUtils.trim( parts[1] ) );
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
package org.codehaus.redback.integration.checks;
|
||||
|
||||
/*
|
||||
* Copyright 2005-2006 The Codehaus.
|
||||
*
|
||||
* Licensed 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 java.util.List;
|
||||
|
||||
import org.codehaus.plexus.redback.system.check.EnvironmentCheck;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* ExpectedJsps
|
||||
* @FIXME the jsp list is not correct
|
||||
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
@Service("environmentCheck#ExpectedJsps")
|
||||
public class ExpectedJsps
|
||||
implements EnvironmentCheck
|
||||
{
|
||||
public void validateEnvironment( List<String> violations )
|
||||
{
|
||||
String redback = "/WEB-INF/jsp/redback";
|
||||
String resources[] = new String[]{"/admin/userCreate.jspf", "/admin/userList.jspf", "/admin/userEdit.jspf",
|
||||
"/admin/userFind.jspf", "/userCredentials.jspf", "/account.jspf", "/login.jspf", "/passwordChange.jspf",
|
||||
"/register.jspf"};
|
||||
|
||||
int missingCount = 0;
|
||||
String jspPath;
|
||||
|
||||
for ( int i = 0; i >= resources.length; i++ )
|
||||
{
|
||||
jspPath = redback + resources[i];
|
||||
if ( !jspExists( jspPath ) )
|
||||
{
|
||||
violations.add( "Missing JSP " + quote( jspPath ) + "." );
|
||||
missingCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if ( missingCount > 0 )
|
||||
{
|
||||
violations.add( "Missing " + missingCount + " JSP(s)." );
|
||||
}
|
||||
}
|
||||
|
||||
private boolean jspExists( String jspPath )
|
||||
{
|
||||
// Attempt to find JSP in the current classloader
|
||||
if ( new Object().getClass().getResource( jspPath ) == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private String quote( Object o )
|
||||
{
|
||||
if ( o == null )
|
||||
{
|
||||
return "<null>";
|
||||
}
|
||||
return "\"" + o.toString() + "\"";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,228 @@
|
|||
package org.codehaus.redback.integration.checks.security;
|
||||
/*
|
||||
* 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.commons.lang.StringUtils;
|
||||
import org.codehaus.plexus.redback.authentication.PasswordBasedAuthenticationDataSource;
|
||||
import org.codehaus.plexus.redback.configuration.UserConfiguration;
|
||||
import org.codehaus.plexus.redback.rbac.RBACManager;
|
||||
import org.codehaus.plexus.redback.rbac.RbacManagerException;
|
||||
import org.codehaus.plexus.redback.rbac.Role;
|
||||
import org.codehaus.plexus.redback.role.RoleManager;
|
||||
import org.codehaus.plexus.redback.role.RoleManagerException;
|
||||
import org.codehaus.plexus.redback.system.SecuritySession;
|
||||
import org.codehaus.plexus.redback.system.SecuritySystem;
|
||||
import org.codehaus.plexus.redback.system.check.EnvironmentCheck;
|
||||
import org.codehaus.plexus.redback.users.User;
|
||||
import org.codehaus.plexus.redback.users.UserManager;
|
||||
import org.codehaus.plexus.redback.users.UserNotFoundException;
|
||||
import org.codehaus.plexus.util.IOUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author Olivier Lamy
|
||||
* @since 1.5
|
||||
*/
|
||||
@Service( "AdminAutoCreateCheck" )
|
||||
public class AdminAutoCreateCheck
|
||||
implements EnvironmentCheck
|
||||
{
|
||||
|
||||
private Logger log = LoggerFactory.getLogger( getClass() );
|
||||
|
||||
public static final String FORCE_ADMIN_FILE_PATH = "redback.admin.creation.file";
|
||||
|
||||
public static final String ADMIN_FULL_NAME_KEY = "redback.admin.fullname";
|
||||
|
||||
public static final String ADMIN_EMAIL_KEY = "redback.admin.email";
|
||||
|
||||
public static final String ADMIN_PASSWORD_KEY = "redback.admin.password";
|
||||
|
||||
@Inject
|
||||
@Named( value = "userManager#configurable" )
|
||||
private UserManager userManager;
|
||||
|
||||
@Inject
|
||||
private UserConfiguration config;
|
||||
|
||||
@Inject
|
||||
protected SecuritySystem securitySystem;
|
||||
|
||||
@Inject
|
||||
private RoleManager roleManager;
|
||||
|
||||
@Inject
|
||||
@Named( value = "rBACManager#cached" )
|
||||
private RBACManager rbacManager;
|
||||
|
||||
public void validateEnvironment( List<String> violations )
|
||||
{
|
||||
try
|
||||
{
|
||||
User user = userManager.findUser( getAdminUid() );
|
||||
if ( user == null )
|
||||
{
|
||||
useForceAdminCreationFile();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
catch ( UserNotFoundException e )
|
||||
{
|
||||
useForceAdminCreationFile();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkAdminKarma( User u )
|
||||
{
|
||||
try
|
||||
{
|
||||
Collection<Role> roles = rbacManager.getEffectivelyAssignedRoles( getAdminUid() );
|
||||
boolean adminRole = false;
|
||||
for ( Role role : roles )
|
||||
{
|
||||
if ( StringUtils.equals( "system-administrator", role.getName() ) )
|
||||
{
|
||||
adminRole = true;
|
||||
}
|
||||
}
|
||||
if ( !adminRole )
|
||||
{
|
||||
assignAdminRole( u );
|
||||
}
|
||||
}
|
||||
catch ( RbacManagerException e )
|
||||
{
|
||||
log.warn( "fail to checkAdminKarma {}", e, e.getMessage() );
|
||||
}
|
||||
catch ( RoleManagerException e )
|
||||
{
|
||||
log.warn( "fail to assignAdmin role {}", e, e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
private void useForceAdminCreationFile()
|
||||
{
|
||||
try
|
||||
{
|
||||
String forceAdminFilePath = System.getProperty( FORCE_ADMIN_FILE_PATH );
|
||||
if ( StringUtils.isBlank( forceAdminFilePath ) )
|
||||
{
|
||||
log.info( FORCE_ADMIN_FILE_PATH + " system props is empty don't use an auto creation admin " );
|
||||
return;
|
||||
}
|
||||
File file = new File( forceAdminFilePath );
|
||||
if ( !file.exists() )
|
||||
{
|
||||
log.warn( "file set in sysprops " + FORCE_ADMIN_FILE_PATH + " not exists skip admin auto creation" );
|
||||
return;
|
||||
}
|
||||
log.debug( "user {} not found try auto creation" );
|
||||
Properties properties = new Properties();
|
||||
FileInputStream fis = new FileInputStream( file );
|
||||
try
|
||||
{
|
||||
properties.load( fis );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
log.warn( "error loading properties from file " + forceAdminFilePath + " skip admin auto creation" );
|
||||
return;
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close( fis );
|
||||
}
|
||||
|
||||
// ensure we have all properties
|
||||
String password = properties.getProperty( ADMIN_PASSWORD_KEY );
|
||||
String email = properties.getProperty( ADMIN_EMAIL_KEY );
|
||||
String fullName = properties.getProperty( ADMIN_FULL_NAME_KEY );
|
||||
|
||||
if ( StringUtils.isBlank( password ) )
|
||||
{
|
||||
log.warn( "property " + ADMIN_PASSWORD_KEY + " not set skip auto admin creation" );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( StringUtils.isBlank( email ) )
|
||||
{
|
||||
log.warn( "property " + ADMIN_EMAIL_KEY + " not set skip auto admin creation" );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( StringUtils.isBlank( fullName ) )
|
||||
{
|
||||
log.warn( "property " + ADMIN_FULL_NAME_KEY + " not set skip auto admin creation" );
|
||||
return;
|
||||
}
|
||||
|
||||
User u = userManager.createUser( getAdminUid(), fullName, email );
|
||||
|
||||
u.setPassword( password );
|
||||
u.setLocked( false );
|
||||
u.setPasswordChangeRequired( false );
|
||||
u.setPermanent( true );
|
||||
u.setValidated( true );
|
||||
|
||||
u = userManager.addUser( u );
|
||||
u.setPassword( password );
|
||||
|
||||
PasswordBasedAuthenticationDataSource authdatasource = new PasswordBasedAuthenticationDataSource();
|
||||
authdatasource.setPrincipal( u.getUsername() );
|
||||
authdatasource.setPassword( u.getPassword() );
|
||||
SecuritySession securitySession = securitySystem.authenticate( authdatasource );
|
||||
if ( securitySession.getAuthenticationResult().isAuthenticated() )
|
||||
{
|
||||
// good add various tokens.
|
||||
u = securitySession.getUser();
|
||||
u.setLastLoginDate( new Date() );
|
||||
securitySystem.getUserManager().updateUser( u );
|
||||
}
|
||||
assignAdminRole( u );
|
||||
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
log.warn( "failed to automatically create an admin account " + e.getMessage(), e );
|
||||
}
|
||||
}
|
||||
|
||||
private void assignAdminRole( User user )
|
||||
throws RoleManagerException
|
||||
{
|
||||
roleManager.assignRole( "system-administrator", user.getPrincipal().toString() );
|
||||
}
|
||||
|
||||
private String getAdminUid()
|
||||
{
|
||||
return config.getString( "redback.default.admin" );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
package org.codehaus.redback.integration.checks.security;
|
||||
|
||||
/*
|
||||
* Copyright 2005-2006 The Codehaus.
|
||||
*
|
||||
* Licensed 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.codehaus.plexus.redback.policy.UserSecurityPolicy;
|
||||
import org.codehaus.plexus.redback.role.RoleManager;
|
||||
import org.codehaus.plexus.redback.role.RoleManagerException;
|
||||
import org.codehaus.plexus.redback.system.SecuritySystem;
|
||||
import org.codehaus.plexus.redback.system.check.EnvironmentCheck;
|
||||
import org.codehaus.plexus.redback.users.User;
|
||||
import org.codehaus.plexus.redback.users.UserManager;
|
||||
import org.codehaus.plexus.redback.users.UserNotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* RequiredRolesEnvironmentCheck:
|
||||
*
|
||||
* @author: Jesse McConnell <jesse@codehaus.org>
|
||||
* @version: $Id$
|
||||
*/
|
||||
@Service( "environmentCheck#guest-user-check" )
|
||||
public class GuestUserEnvironmentCheck
|
||||
implements EnvironmentCheck
|
||||
{
|
||||
|
||||
@Inject
|
||||
private RoleManager roleManager;
|
||||
|
||||
@Inject
|
||||
private SecuritySystem securitySystem;
|
||||
|
||||
/**
|
||||
* boolean detailing if this environment check has been executed
|
||||
*/
|
||||
private boolean checked = false;
|
||||
|
||||
/**
|
||||
* @param violations
|
||||
*/
|
||||
public void validateEnvironment( List<String> violations )
|
||||
{
|
||||
if ( !checked )
|
||||
{
|
||||
UserManager userManager = securitySystem.getUserManager();
|
||||
UserSecurityPolicy policy = securitySystem.getPolicy();
|
||||
|
||||
User guest;
|
||||
try
|
||||
{
|
||||
guest = userManager.getGuestUser();
|
||||
}
|
||||
catch ( UserNotFoundException e )
|
||||
{
|
||||
policy.setEnabled( false );
|
||||
guest = userManager.createGuestUser();
|
||||
policy.setEnabled( true );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
roleManager.assignRole( "guest", guest.getPrincipal().toString() );
|
||||
}
|
||||
catch ( RoleManagerException rpe )
|
||||
{
|
||||
violations.add( "unable to initialize guest user properly: " + rpe.getMessage() );
|
||||
}
|
||||
|
||||
checked = true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
package org.codehaus.redback.integration.checks.security;
|
||||
|
||||
/*
|
||||
* Copyright 2005-2006 The Codehaus.
|
||||
*
|
||||
* Licensed 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.codehaus.plexus.redback.rbac.RBACManager;
|
||||
import org.codehaus.plexus.redback.rbac.RbacManagerException;
|
||||
import org.codehaus.plexus.redback.rbac.UserAssignment;
|
||||
import org.codehaus.plexus.redback.system.check.EnvironmentCheck;
|
||||
import org.codehaus.plexus.redback.users.User;
|
||||
import org.codehaus.plexus.redback.users.UserManager;
|
||||
import org.codehaus.plexus.redback.users.UserNotFoundException;
|
||||
import org.codehaus.redback.integration.role.RoleConstants;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* LockedAdminEnvironmentCheck: checks if accounts marked as system administrator are locked
|
||||
* and unlocks them on startup.
|
||||
*
|
||||
* @author: Jesse McConnell <jesse@codehaus.org>
|
||||
* @version: $Id$
|
||||
*/
|
||||
@Service( "environmentCheck#locked-admin-check" )
|
||||
public class LockedAdminEnvironmentCheck
|
||||
implements EnvironmentCheck
|
||||
{
|
||||
|
||||
protected Logger log = LoggerFactory.getLogger( getClass() );
|
||||
|
||||
@Inject
|
||||
@Named( value = "userManager#configurable" )
|
||||
private UserManager userManager;
|
||||
|
||||
@Inject
|
||||
@Named( value = "rBACManager#cached" )
|
||||
private RBACManager rbacManager;
|
||||
|
||||
/**
|
||||
* boolean detailing if this environment check has been executed
|
||||
*/
|
||||
private boolean checked = false;
|
||||
|
||||
/**
|
||||
* This environment check will unlock system administrator accounts that are locked on the restart of the
|
||||
* application when the environment checks are processed.
|
||||
*
|
||||
* @param violations
|
||||
*/
|
||||
public void validateEnvironment( List<String> violations )
|
||||
{
|
||||
if ( !checked && !userManager.isReadOnly() )
|
||||
{
|
||||
List<String> roles = new ArrayList<String>();
|
||||
roles.add( RoleConstants.SYSTEM_ADMINISTRATOR_ROLE );
|
||||
|
||||
List<UserAssignment> systemAdminstrators;
|
||||
try
|
||||
{
|
||||
systemAdminstrators = rbacManager.getUserAssignmentsForRoles( roles );
|
||||
|
||||
for ( UserAssignment userAssignment : systemAdminstrators )
|
||||
{
|
||||
try
|
||||
{
|
||||
User admin = userManager.findUser( userAssignment.getPrincipal() );
|
||||
|
||||
if ( admin.isLocked() )
|
||||
{
|
||||
log.info( "Unlocking system administrator: {}", admin.getUsername() );
|
||||
admin.setLocked( false );
|
||||
userManager.updateUser( admin );
|
||||
}
|
||||
}
|
||||
catch ( UserNotFoundException ne )
|
||||
{
|
||||
log.warn( "Dangling UserAssignment -> {}", userAssignment.getPrincipal() );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( RbacManagerException e )
|
||||
{
|
||||
log.warn( "Exception when checking for locked admin user: " + e.getMessage(), e );
|
||||
}
|
||||
|
||||
checked = true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
package org.codehaus.redback.integration.checks.security;
|
||||
|
||||
/*
|
||||
* Copyright 2005-2006 The Codehaus.
|
||||
*
|
||||
* Licensed 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 java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.codehaus.plexus.redback.role.RoleManager;
|
||||
import org.codehaus.plexus.redback.role.RoleManagerException;
|
||||
import org.codehaus.plexus.redback.system.check.EnvironmentCheck;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* RequiredRolesEnvironmentCheck: this environment check will check that the
|
||||
* required roles of the redback-xwork-integration artifact exist to be
|
||||
* assigned.
|
||||
*
|
||||
* @author: Jesse McConnell <jesse@codehaus.org>
|
||||
* @version: $Id$
|
||||
*/
|
||||
@Service("environmentCheck#required-roles")
|
||||
public class RequiredRolesEnvironmentCheck
|
||||
implements EnvironmentCheck
|
||||
{
|
||||
|
||||
protected Logger log = LoggerFactory.getLogger( getClass() );
|
||||
|
||||
@Inject
|
||||
private RoleManager roleManager;
|
||||
|
||||
/**
|
||||
* boolean detailing if this environment check has been executed
|
||||
*/
|
||||
private boolean checked = false;
|
||||
|
||||
/**
|
||||
* @param violations
|
||||
*/
|
||||
public void validateEnvironment( List<String> violations )
|
||||
{
|
||||
if ( !checked )
|
||||
{
|
||||
log.info( "Checking the existence of required roles." );
|
||||
|
||||
try
|
||||
{
|
||||
if ( !roleManager.roleExists( "registered-user" ) )
|
||||
{
|
||||
violations.add( "unable to validate existence of the registered-user role" );
|
||||
}
|
||||
|
||||
if ( !roleManager.roleExists( "user-administrator" ) )
|
||||
{
|
||||
violations.add( "unable to validate existence of the user-administator role" );
|
||||
}
|
||||
|
||||
if ( !roleManager.roleExists( "system-administrator" ) )
|
||||
{
|
||||
violations.add( "unable to validate existence of the system-administrator role" );
|
||||
}
|
||||
}
|
||||
catch ( RoleManagerException e )
|
||||
{
|
||||
violations.add( "unable to check required roles: " + e.getMessage() );
|
||||
}
|
||||
|
||||
checked = true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package org.codehaus.redback.integration.checks.xwork;
|
||||
|
||||
/*
|
||||
* Copyright 2005-2006 The Codehaus.
|
||||
*
|
||||
* Licensed 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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* XworkActionConfig
|
||||
*
|
||||
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class XworkActionConfig
|
||||
{
|
||||
public String name;
|
||||
|
||||
public String clazz;
|
||||
|
||||
public String method;
|
||||
|
||||
public List<String> results = new ArrayList<String>();
|
||||
|
||||
public XworkActionConfig( String name, String className, String method )
|
||||
{
|
||||
this.name = name;
|
||||
this.clazz = className;
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public XworkActionConfig addResult( String name )
|
||||
{
|
||||
results.add( name );
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package org.codehaus.redback.integration.checks.xwork;
|
||||
|
||||
/*
|
||||
* Copyright 2005-2006 The Codehaus.
|
||||
*
|
||||
* Licensed 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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* XworkPackageConfig
|
||||
*
|
||||
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class XworkPackageConfig
|
||||
{
|
||||
public String name;
|
||||
|
||||
public List<XworkActionConfig> actions = new ArrayList<XworkActionConfig>();
|
||||
|
||||
public XworkPackageConfig( String name )
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public XworkActionConfig addAction( String name, String className, String method )
|
||||
{
|
||||
XworkActionConfig config = new XworkActionConfig( name, className, method );
|
||||
actions.add( config );
|
||||
return config;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package org.codehaus.redback.integration.eXc;
|
||||
|
||||
/*
|
||||
* Copyright 2005-2006 The Codehaus.
|
||||
*
|
||||
* Licensed 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.extremecomponents.table.bean.Column;
|
||||
import org.extremecomponents.table.cell.AbstractCell;
|
||||
import org.extremecomponents.table.core.TableModel;
|
||||
import org.extremecomponents.table.view.html.BuilderUtils;
|
||||
|
||||
/**
|
||||
* CheckboxImageCell
|
||||
*
|
||||
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class CheckboxImageCell
|
||||
extends AbstractCell
|
||||
{
|
||||
|
||||
private static final String CHECKBOX_TRUE = "icon_success_sml";
|
||||
|
||||
private static final String CHECKBOX_FALSE = "checkbox-false";
|
||||
|
||||
protected String getCellValue( TableModel model, Column column )
|
||||
{
|
||||
Object value = column.getPropertyValue();
|
||||
if ( value == null )
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
Boolean bool = (Boolean) value;
|
||||
|
||||
String cellValue = "<img src=\"";
|
||||
|
||||
if ( bool.booleanValue() )
|
||||
{
|
||||
cellValue = cellValue + BuilderUtils.getImage( model, CHECKBOX_TRUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
cellValue = cellValue + BuilderUtils.getImage( model, CHECKBOX_FALSE );
|
||||
}
|
||||
|
||||
cellValue = cellValue + "\" alt=\"" + bool.toString() + "\"/>";
|
||||
|
||||
return cellValue;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue