You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ol...@apache.org on 2012/04/06 11:59:32 UTC
svn commit: r1310268 [29/42] - in /archiva/redback/redback-core/trunk: ./
redback-authentication/ redback-authentication/redback-authentication-api/
redback-authentication/redback-authentication-api/src/
redback-authentication/redback-authentication-ap...
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/src/main/java/org/codehaus/plexus/redback/keys/memory/MemoryAuthenticationKey.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/src/main/java/org/codehaus/plexus/redback/keys/memory/MemoryAuthenticationKey.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/src/main/java/org/codehaus/plexus/redback/keys/memory/MemoryKeyManager.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/src/main/java/org/codehaus/plexus/redback/keys/memory/MemoryKeyManager.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/src/main/java/org/codehaus/plexus/redback/keys/memory/MemoryKeyManager.java (added)
+++ archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/src/main/java/org/codehaus/plexus/redback/keys/memory/MemoryKeyManager.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,122 @@
+package org.codehaus.plexus.redback.keys.memory;
+
+/*
+ * 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.keys.AbstractKeyManager;
+import org.codehaus.plexus.redback.keys.AuthenticationKey;
+import org.codehaus.plexus.redback.keys.KeyManagerException;
+import org.codehaus.plexus.redback.keys.KeyNotFoundException;
+import org.codehaus.plexus.util.StringUtils;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * KeyManager backed by an in-memory only store.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Service("keyManager#memory")
+public class MemoryKeyManager
+ extends AbstractKeyManager
+{
+ private Map<String, AuthenticationKey> keys = new HashMap<String, AuthenticationKey>();
+
+ public AuthenticationKey createKey( String principal, String purpose, int expirationMinutes )
+ throws KeyManagerException
+ {
+ AuthenticationKey key = new MemoryAuthenticationKey();
+ key.setKey( super.generateUUID() );
+ key.setForPrincipal( principal );
+ key.setPurpose( purpose );
+ key.setDateCreated( new Date() );
+
+ if ( expirationMinutes >= 0 )
+ {
+ Calendar expiration = Calendar.getInstance();
+ expiration.add( Calendar.MINUTE, expirationMinutes );
+ key.setDateExpires( expiration.getTime() );
+ }
+
+ keys.put( key.getKey(), key );
+
+ return key;
+ }
+
+ public AuthenticationKey findKey( String key )
+ throws KeyNotFoundException, KeyManagerException
+ {
+ if ( StringUtils.isEmpty( key ) )
+ {
+ throw new KeyNotFoundException( "Empty key not found." );
+ }
+
+ AuthenticationKey authkey = keys.get( key );
+
+ if ( authkey == null )
+ {
+ throw new KeyNotFoundException( "Key [" + key + "] not found." );
+ }
+
+ assertNotExpired( authkey );
+
+ return authkey;
+ }
+
+ public void deleteKey( AuthenticationKey authkey )
+ throws KeyManagerException
+ {
+ keys.remove( authkey );
+ }
+
+ public void deleteKey( String key )
+ throws KeyManagerException
+ {
+ AuthenticationKey authkey = keys.get( key );
+ if ( authkey != null )
+ {
+ keys.remove( authkey );
+ }
+ }
+
+ public List<AuthenticationKey> getAllKeys()
+ {
+ return new ArrayList<AuthenticationKey>( keys.values() );
+ }
+
+ public AuthenticationKey addKey( AuthenticationKey key )
+ {
+ keys.put( key.getKey(), key );
+ return key;
+ }
+
+ public void eraseDatabase()
+ {
+ keys.clear();
+ }
+
+ public String getId()
+ {
+ return "Memory Key Manager";
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/src/main/java/org/codehaus/plexus/redback/keys/memory/MemoryKeyManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/src/main/java/org/codehaus/plexus/redback/keys/memory/MemoryKeyManager.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/src/main/resources/META-INF/spring-context.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/src/main/resources/META-INF/spring-context.xml?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/src/main/resources/META-INF/spring-context.xml (added)
+++ archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/src/main/resources/META-INF/spring-context.xml Fri Apr 6 09:58:14 2012
@@ -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.keys.memory"/>
+
+</beans>
\ No newline at end of file
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/src/main/resources/META-INF/spring-context.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/src/main/resources/META-INF/spring-context.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/src/test/java/org/codehaus/plexus/redback/keys/memory/MemoryKeyManagerTest.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/src/test/java/org/codehaus/plexus/redback/keys/memory/MemoryKeyManagerTest.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/src/test/java/org/codehaus/plexus/redback/keys/memory/MemoryKeyManagerTest.java (added)
+++ archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/src/test/java/org/codehaus/plexus/redback/keys/memory/MemoryKeyManagerTest.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,47 @@
+package org.codehaus.plexus.redback.keys.memory;
+
+/*
+ * 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.keys.KeyManager;
+import org.codehaus.plexus.redback.keys.KeyManagerTestCase;
+import org.junit.Before;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+/**
+ * MemoryKeyManagerTest
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class MemoryKeyManagerTest
+ extends KeyManagerTestCase
+{
+ @Inject @Named(value="keyManager#memory")
+ KeyManager keyManager;
+
+ @Before
+ public void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ super.setKeyManager( keyManager );
+ }
+
+}
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/src/test/java/org/codehaus/plexus/redback/keys/memory/MemoryKeyManagerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-providers/redback-keys-memory/src/test/java/org/codehaus/plexus/redback/keys/memory/MemoryKeyManagerTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-keys/redback-keys-tests/pom.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-keys/redback-keys-tests/pom.xml?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-keys/redback-keys-tests/pom.xml (added)
+++ archiva/redback/redback-core/trunk/redback-keys/redback-keys-tests/pom.xml Fri Apr 6 09:58:14 2012
@@ -0,0 +1,41 @@
+<?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-keys</artifactId>
+ <version>1.5-SNAPSHOT</version>
+ </parent>
+ <artifactId>redback-keys-tests</artifactId>
+ <name>Redback :: Key Management Test Harness</name>
+ <packaging>jar</packaging>
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.redback</groupId>
+ <artifactId>redback-keys-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+</project>
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-tests/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-tests/pom.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-keys/redback-keys-tests/src/main/java/org/codehaus/plexus/redback/keys/KeyManagerTestCase.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-keys/redback-keys-tests/src/main/java/org/codehaus/plexus/redback/keys/KeyManagerTestCase.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-keys/redback-keys-tests/src/main/java/org/codehaus/plexus/redback/keys/KeyManagerTestCase.java (added)
+++ archiva/redback/redback-core/trunk/redback-keys/redback-keys-tests/src/main/java/org/codehaus/plexus/redback/keys/KeyManagerTestCase.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,230 @@
+package org.codehaus.plexus.redback.keys;
+
+/*
+ * 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 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 java.text.SimpleDateFormat;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * KeyManagerTestCase
+ *
+ * @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 KeyManagerTestCase
+ extends TestCase
+{
+ private KeyManager manager;
+
+ public KeyManager getKeyManager()
+ {
+ return manager;
+ }
+
+ public void setKeyManager( KeyManager manager )
+ {
+ this.manager = manager;
+ }
+
+ private void assertSameDates( Date expected, Date actual )
+ {
+ if ( ( expected == null ) && ( actual != null ) )
+ {
+ fail( "Expected date is null, actual date [" + actual + "]." );
+ }
+
+ if ( ( expected != null ) && ( actual == null ) )
+ {
+ fail( "Expected date [" + expected + "], actual date is null." );
+ }
+
+ SimpleDateFormat format = new SimpleDateFormat( "EEE, d MMM yyyy HH:mm:ss Z" );
+ assertEquals( format.format( expected ), format.format( actual ) );
+ }
+
+ @Test
+ public void testNormal()
+ throws KeyNotFoundException, KeyManagerException
+ {
+ String principal = "foo";
+ String purpose = "Testing";
+
+ AuthenticationKey created = getKeyManager().createKey( principal, purpose, 15 );
+
+ assertNotNull( created );
+ assertNotNull( created.getKey() );
+ assertNotNull( created.getDateCreated() );
+ assertNotNull( created.getDateExpires() );
+
+ assertEquals( principal, created.getForPrincipal() );
+ assertEquals( purpose, created.getPurpose() );
+
+ Date expectedCreated = created.getDateCreated();
+ Date expectedExpires = created.getDateExpires();
+
+ String expectedKey = created.getKey();
+
+ AuthenticationKey found = getKeyManager().findKey( expectedKey );
+
+ assertEquals( expectedKey, found.getKey() );
+ assertEquals( principal, found.getForPrincipal() );
+ assertEquals( purpose, found.getPurpose() );
+ assertSameDates( expectedCreated, found.getDateCreated() );
+ assertSameDates( expectedExpires, found.getDateExpires() );
+ }
+
+ @Test
+ public void testGetAllKeys()
+ throws KeyManagerException
+ {
+ getKeyManager().eraseDatabase();
+ AuthenticationKey created1 = getKeyManager().createKey( "foo", "Testing", 15 );
+ AuthenticationKey created2 = getKeyManager().createKey( "bar", "Something", 23 );
+
+ assertNotNull( created1 );
+ assertNotNull( created2 );
+
+ assertEquals( "foo", created1.getForPrincipal() );
+ assertEquals( "Testing", created1.getPurpose() );
+
+ assertEquals( "bar", created2.getForPrincipal() );
+ assertEquals( "Something", created2.getPurpose() );
+
+ List<AuthenticationKey> keys = getKeyManager().getAllKeys();
+ Collections.sort( keys, new Comparator<AuthenticationKey>()
+ {
+ public int compare( AuthenticationKey key1, AuthenticationKey key2 )
+ {
+ return key2.getForPrincipal().compareTo( key1.getForPrincipal() );
+ }
+ } );
+
+ AuthenticationKey found = (AuthenticationKey) keys.get( 0 );
+ assertEquals( created1.getKey(), found.getKey() );
+ assertEquals( "foo", found.getForPrincipal() );
+ assertEquals( "Testing", found.getPurpose() );
+ assertSameDates( created1.getDateCreated(), found.getDateCreated() );
+ assertSameDates( created1.getDateExpires(), found.getDateExpires() );
+
+ found = (AuthenticationKey) keys.get( 1 );
+ assertEquals( created2.getKey(), found.getKey() );
+ assertEquals( "bar", found.getForPrincipal() );
+ assertEquals( "Something", found.getPurpose() );
+ assertSameDates( created2.getDateCreated(), found.getDateCreated() );
+ assertSameDates( created2.getDateExpires(), found.getDateExpires() );
+ }
+
+ @Test
+ public void testNotThere()
+ throws KeyManagerException
+ {
+ String principal = "foo";
+ String purpose = "Testing";
+
+ AuthenticationKey created = getKeyManager().createKey( principal, purpose, 15 );
+
+ assertNotNull( created );
+ assertNotNull( created.getKey() );
+ assertNotNull( created.getDateCreated() );
+ assertNotNull( created.getDateExpires() );
+
+ assertEquals( principal, created.getForPrincipal() );
+ assertEquals( purpose, created.getPurpose() );
+
+ try
+ {
+ getKeyManager().findKey( "deadbeefkey" );
+ fail( "Invalid Key should not have been found." );
+ }
+ catch ( KeyNotFoundException e )
+ {
+ // Expected path for this test.
+ }
+ }
+
+ @Test
+ public void testExpired()
+ throws KeyManagerException, InterruptedException
+ {
+ String principal = "foo";
+ String purpose = "Testing";
+
+ AuthenticationKey created = getKeyManager().createKey( principal, purpose, 0 );
+
+ assertNotNull( created );
+ assertNotNull( created.getKey() );
+ assertNotNull( created.getDateCreated() );
+ assertNotNull( created.getDateExpires() );
+
+ assertEquals( principal, created.getForPrincipal() );
+ assertEquals( purpose, created.getPurpose() );
+
+ String expectedKey = created.getKey();
+
+ try
+ {
+ Thread.sleep( 500 ); // Sleep to let it expire
+ getKeyManager().findKey( expectedKey );
+ fail( "Expired Key should not have been found." );
+ }
+ catch ( KeyNotFoundException e )
+ {
+ // Expected path for this test.
+ }
+ }
+
+ @Test
+ public void testPermanent()
+ throws KeyManagerException
+ {
+ String principal = "foo";
+ String purpose = "Testing";
+
+ AuthenticationKey created = getKeyManager().createKey( principal, purpose, -1 );
+
+ assertNotNull( created );
+ assertNotNull( created.getKey() );
+ assertNotNull( created.getDateCreated() );
+ assertNull( created.getDateExpires() );
+
+ assertEquals( principal, created.getForPrincipal() );
+ assertEquals( purpose, created.getPurpose() );
+
+ Date expectedCreated = created.getDateCreated();
+
+ String expectedKey = created.getKey();
+
+ AuthenticationKey found = getKeyManager().findKey( expectedKey );
+
+ assertEquals( expectedKey, found.getKey() );
+ assertEquals( principal, found.getForPrincipal() );
+ assertEquals( purpose, found.getPurpose() );
+ assertSameDates( expectedCreated, found.getDateCreated() );
+ assertNull( found.getDateExpires() );
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-tests/src/main/java/org/codehaus/plexus/redback/keys/KeyManagerTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-keys/redback-keys-tests/src/main/java/org/codehaus/plexus/redback/keys/KeyManagerTestCase.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-policy/pom.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-policy/pom.xml?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-policy/pom.xml (added)
+++ archiva/redback/redback-core/trunk/redback-policy/pom.xml Fri Apr 6 09:58:14 2012
@@ -0,0 +1,57 @@
+<?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-policy</artifactId>
+ <name>Redback :: Policy</name>
+ <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>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Propchange: archiva/redback/redback-core/trunk/redback-policy/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-policy/pom.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/AbstractCookieSettings.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/AbstractCookieSettings.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/AbstractCookieSettings.java (added)
+++ archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/AbstractCookieSettings.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,68 @@
+package org.codehaus.plexus.redback.policy;
+
+/*
+ * 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 javax.annotation.Resource;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.codehaus.plexus.redback.configuration.UserConfiguration;
+
+/**
+ * Base class for cookie settings. These will only differ by their configuration keys.
+ *
+ * @todo not sure if having the domain and path in the general configuration is a good idea - this is probably something
+ * customised once for all cookies and applications. Should it be in a sharead configuration file, under a sharead key,
+ * or perhaps even configured at the application server level? (ie, in Naming).
+ */
+public abstract class AbstractCookieSettings
+ implements CookieSettings
+{
+ @Inject @Named(value="userConfiguration")
+ protected UserConfiguration config;
+
+ /**
+ * Timeout (in minutes) for the sign on cookie.
+ */
+ protected int cookieTimeout;
+
+ /**
+ * The domain for the cookie.
+ */
+ protected String domain;
+
+ /**
+ * The path for the cookie.
+ */
+ protected String path;
+
+ public int getCookieTimeout()
+ {
+ return cookieTimeout;
+ }
+
+ public String getDomain()
+ {
+ return domain;
+ }
+
+ public String getPath()
+ {
+ return path;
+ }
+
+}
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/AbstractCookieSettings.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/AbstractCookieSettings.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/AccountLockedException.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/AccountLockedException.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/AccountLockedException.java (added)
+++ archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/AccountLockedException.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,43 @@
+package org.codehaus.plexus.redback.policy;
+
+/*
+ * 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.users.User;
+
+/**
+ * AccountLockedException
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class AccountLockedException
+ extends PolicyViolationException
+{
+ private User user;
+
+ public AccountLockedException( String message, User user )
+ {
+ super( message );
+ this.user = user;
+ }
+
+ public User getUser()
+ {
+ return user;
+ }
+}
+
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/AccountLockedException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/AccountLockedException.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/CookieSettings.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/CookieSettings.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/CookieSettings.java (added)
+++ archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/CookieSettings.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,54 @@
+package org.codehaus.plexus.redback.policy;
+
+/*
+ * 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.
+ */
+
+/**
+ * CookieSettings
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public interface CookieSettings
+{
+ /**
+ * Gets the Cookie timeout (in minutes) for the signon cookie.
+ *
+ * @return the timeout in minutes
+ */
+ int getCookieTimeout();
+
+ /**
+ * Gets the domain to use for the signon cookie.
+ *
+ * @return the domain
+ */
+ String getDomain();
+
+ /**
+ * Gets the path to use for the signon cookie.
+ *
+ * @return the path
+ */
+ String getPath();
+
+ /**
+ * Enable or disables the remember me features of the application.
+ *
+ * @return true if remember me settings are enabled.
+ */
+ boolean isEnabled();
+}
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/CookieSettings.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/CookieSettings.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/DefaultUserSecurityPolicy.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/DefaultUserSecurityPolicy.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/DefaultUserSecurityPolicy.java (added)
+++ archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/DefaultUserSecurityPolicy.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,437 @@
+package org.codehaus.plexus.redback.policy;
+
+/*
+ * 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.configuration.UserConfiguration;
+import org.codehaus.plexus.redback.policy.rules.MustHavePasswordRule;
+import org.codehaus.plexus.redback.users.User;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.ApplicationContext;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+import javax.inject.Named;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * User Security Policy.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Service( "userSecurityPolicy" )
+public class DefaultUserSecurityPolicy
+ implements UserSecurityPolicy
+{
+ private static final String ENABLEMENT_KEY = "UserSecurityPolicy" + ":ENABLED";
+
+ public static final String PASSWORD_RETENTION_COUNT = "security.policy.password.previous.count";
+
+ public static final String LOGIN_ATTEMPT_COUNT = "security.policy.allowed.login.attempt";
+
+ public static final String PASSWORD_EXPIRATION_ENABLED = "security.policy.password.expiration.enabled";
+
+ public static final String PASSWORD_EXPIRATION = "security.policy.password.expiration.days";
+
+ public static final String PASSWORD_ENCODER = "security.policy.password.encoder";
+
+ public static final String UNLOCKABLE_ACCOUNTS = "security.policy.unlockable.accounts";
+
+ private static final Logger log = LoggerFactory.getLogger( DefaultUserSecurityPolicy.class );
+
+ private PasswordRule defaultPasswordRule = new MustHavePasswordRule();
+
+ @Inject
+ @Named( value = "userConfiguration" )
+ private UserConfiguration config;
+
+ @Inject
+ @Named( value = "passwordEncoder#sha256" )
+ private PasswordEncoder passwordEncoder;
+
+ @Inject
+ @Named( value = "userValidationSettings" )
+ private UserValidationSettings userValidationSettings;
+
+ @Inject
+ @Named( value = "cookieSettings#rememberMe" )
+ private CookieSettings rememberMeCookieSettings;
+
+ @Inject
+ @Named( value = "cookieSettings#signon" )
+ private CookieSettings signonCookieSettings;
+
+ // TODO use something more generic to be able to do change about container
+ @Inject
+ private ApplicationContext applicationContext;
+
+ /**
+ * The List of {@link PasswordRule} objects.
+ */
+ @Inject
+ private List<PasswordRule> rules = new ArrayList<PasswordRule>( 0 );
+
+ private int previousPasswordsCount;
+
+ private int loginAttemptCount;
+
+ private int passwordExpirationDays;
+
+ private boolean passwordExpirationEnabled;
+
+ private List<String> unlockableAccounts;
+
+
+ // ---------------------------------------
+ // Component lifecycle
+ // ---------------------------------------
+ // TODO move this to constructor
+ @SuppressWarnings( "unchecked" )
+ @PostConstruct
+ public void initialize()
+ {
+ configurePolicy();
+
+ configureEncoder();
+
+ // In some configurations, rules can be unset.
+ if ( rules == null )
+ {
+ // Set rules to prevent downstream NPE.
+ rules = new ArrayList<PasswordRule>( 1 );
+ }
+
+ if ( rules.isEmpty() )
+ {
+ // there should be at least one rule
+ addPasswordRule( defaultPasswordRule );
+ }
+ }
+
+ private void configureEncoder()
+ {
+ String encoder = config.getString( PASSWORD_ENCODER );
+
+ if ( encoder != null )
+ {
+ this.passwordEncoder = applicationContext.getBean( "passwordEncoder#" + encoder, PasswordEncoder.class );
+ }
+ }
+
+ private void configurePolicy()
+ {
+ this.previousPasswordsCount = config.getInt( PASSWORD_RETENTION_COUNT );
+ this.loginAttemptCount = config.getInt( LOGIN_ATTEMPT_COUNT );
+ this.passwordExpirationEnabled = config.getBoolean( PASSWORD_EXPIRATION_ENABLED );
+ this.passwordExpirationDays = config.getInt( PASSWORD_EXPIRATION );
+ this.unlockableAccounts = config.getList( UNLOCKABLE_ACCOUNTS );
+ }
+
+
+ public String getId()
+ {
+ return "Default User Security Policy";
+ }
+
+ public int getPreviousPasswordsCount()
+ {
+ return previousPasswordsCount;
+ }
+
+ public List<String> getUnlockableAccounts()
+ {
+ if ( unlockableAccounts == null )
+ {
+ unlockableAccounts = new ArrayList<String>( 0 );
+ }
+ return unlockableAccounts;
+ }
+
+ /**
+ * Sets a list of accounts which should never be locked by security policy
+ *
+ * @param unlockableAccounts
+ */
+ public void setUnlockableAccounts( List<String> unlockableAccounts )
+ {
+ this.unlockableAccounts = unlockableAccounts;
+ }
+
+ /**
+ * Sets the count of previous passwords that should be tracked.
+ *
+ * @param count the count of previous passwords to track.
+ */
+ public void setPreviousPasswordsCount( int count )
+ {
+ this.previousPasswordsCount = count;
+ }
+
+ public int getLoginAttemptCount()
+ {
+ return loginAttemptCount;
+ }
+
+ public void setLoginAttemptCount( int count )
+ {
+ this.loginAttemptCount = count;
+ }
+
+ /**
+ * Get the password encoder to be used for password operations
+ *
+ * @return the encoder
+ */
+ public PasswordEncoder getPasswordEncoder()
+ {
+ return passwordEncoder;
+ }
+
+ public boolean isEnabled()
+ {
+ Boolean bool = (Boolean) PolicyContext.getContext().get( ENABLEMENT_KEY );
+ return bool == null || bool.booleanValue();
+ }
+
+ public void setEnabled( boolean enabled )
+ {
+ PolicyContext.getContext().put( ENABLEMENT_KEY, Boolean.valueOf( enabled ) );
+ }
+
+ /**
+ * Add a Specific Rule to the Password Rules List.
+ *
+ * @param rule the rule to add.
+ */
+ public void addPasswordRule( PasswordRule rule )
+ {
+ // TODO: check for duplicates? if so, check should only be based on Rule class name.
+
+ rule.setUserSecurityPolicy( this );
+ this.rules.add( rule );
+ }
+
+ /**
+ * Get the Password Rules List.
+ *
+ * @return the list of {@link PasswordRule} objects.
+ */
+ public List<PasswordRule> getPasswordRules()
+ {
+ return this.rules;
+ }
+
+ /**
+ * Set the Password Rules List.
+ *
+ * @param rules the list of {@link PasswordRule} objects.
+ */
+ public void setPasswordRules( List<PasswordRule> rules )
+ {
+ this.rules.clear();
+
+ if ( rules == null )
+ {
+ return;
+ }
+
+ // Intentionally iterating to ensure policy settings in provided rules.
+
+ for ( PasswordRule rule : rules )
+ {
+ addPasswordRule( rule );
+ }
+ }
+
+ public void extensionPasswordExpiration( User user )
+ throws MustChangePasswordException
+ {
+ if ( passwordExpirationEnabled && !getUnlockableAccounts().contains( user.getUsername() ) )
+ {
+ Calendar expirationDate = Calendar.getInstance();
+ expirationDate.setTime( user.getLastPasswordChange() );
+ expirationDate.add( Calendar.DAY_OF_MONTH, passwordExpirationDays );
+ Calendar now = Calendar.getInstance();
+
+ if ( now.after( expirationDate ) )
+ {
+ log.info( "User '{}' flagged for password expiry (expired on: {})", user.getUsername(),
+ expirationDate );
+ user.setPasswordChangeRequired( true );
+ throw new MustChangePasswordException( "Password Expired, You must change your password.", user );
+ }
+ }
+ }
+
+ public void extensionExcessiveLoginAttempts( User user )
+ throws AccountLockedException
+ {
+ if ( !getUnlockableAccounts().contains( user.getUsername() ) )
+ {
+ int attempt = user.getCountFailedLoginAttempts();
+ attempt++;
+ user.setCountFailedLoginAttempts( attempt );
+
+ if ( attempt >= loginAttemptCount )
+ {
+ log.info( "User '{}' locked due to excessive login attempts: {}", user.getUsername(), attempt );
+ user.setLocked( true );
+ throw new AccountLockedException( "Account " + user.getUsername() + " is locked.", user );
+ }
+ }
+ }
+
+ public void extensionChangePassword( User user )
+ throws PasswordRuleViolationException
+ {
+ extensionChangePassword( user, false );
+ }
+
+ public void extensionChangePassword( User user, boolean passwordChangeRequired )
+ throws PasswordRuleViolationException
+ {
+ validatePassword( user );
+
+ // set the current encoded password.
+ user.setEncodedPassword( passwordEncoder.encodePassword( user.getPassword() ) );
+ user.setPassword( null );
+
+ // push new password onto list of previous password.
+ List<String> previousPasswords = new ArrayList<String>( 1 );
+ previousPasswords.add( user.getEncodedPassword() );
+
+ if ( !user.getPreviousEncodedPasswords().isEmpty() )
+ {
+ int oldCount = Math.min( previousPasswordsCount - 1, user.getPreviousEncodedPasswords().size() );
+ //modified sublist start index as the previous value results to nothing being added to the list.
+ List<String> sublist = user.getPreviousEncodedPasswords().subList( 0, oldCount );
+ previousPasswords.addAll( sublist );
+ }
+
+ user.setPreviousEncodedPasswords( previousPasswords );
+ user.setPasswordChangeRequired( passwordChangeRequired );
+
+ // Update timestamp for password change.
+ user.setLastPasswordChange( new Date() );
+ }
+
+ public void validatePassword( User user )
+ throws PasswordRuleViolationException
+ {
+ if ( isEnabled() )
+ {
+ PasswordRuleViolations violations = new PasswordRuleViolations();
+
+ for ( PasswordRule rule : this.rules )
+ {
+ if ( rule.isEnabled() )
+ {
+ if ( rule.requiresSecurityPolicy() )
+ {
+ rule.setUserSecurityPolicy( this );
+ }
+
+ rule.testPassword( violations, user );
+ }
+ }
+
+ if ( violations.hasViolations() )
+ {
+ PasswordRuleViolationException exception = new PasswordRuleViolationException();
+ exception.setViolations( violations );
+ throw exception;
+ }
+ }
+
+ // If you got this far, then ensure that the password is never null.
+ if ( user.getPassword() == null )
+ {
+ user.setPassword( "" );
+ }
+ }
+
+ public int getPasswordExpirationDays()
+ {
+ return passwordExpirationDays;
+ }
+
+ public void setPasswordExpirationDays( int passwordExpiry )
+ {
+ this.passwordExpirationDays = passwordExpiry;
+ }
+
+ public UserValidationSettings getUserValidationSettings()
+ {
+ return userValidationSettings;
+ }
+
+ public void setUserValidationSettings( UserValidationSettings settings )
+ {
+ this.userValidationSettings = settings;
+ }
+
+ public CookieSettings getRememberMeCookieSettings()
+ {
+ return rememberMeCookieSettings;
+ }
+
+ public CookieSettings getSignonCookieSettings()
+ {
+ return signonCookieSettings;
+ }
+
+ public UserConfiguration getConfig()
+ {
+ return config;
+ }
+
+ public void setConfig( UserConfiguration config )
+ {
+ this.config = config;
+ }
+
+
+ public void setPasswordEncoder( PasswordEncoder passwordEncoder )
+ {
+ this.passwordEncoder = passwordEncoder;
+ }
+
+ public void setRememberMeCookieSettings( CookieSettings rememberMeCookieSettings )
+ {
+ this.rememberMeCookieSettings = rememberMeCookieSettings;
+ }
+
+ public void setSignonCookieSettings( CookieSettings signonCookieSettings )
+ {
+ this.signonCookieSettings = signonCookieSettings;
+ }
+
+ public void setRules( List<PasswordRule> rules )
+ {
+ this.rules = rules;
+ }
+
+ public void setDefaultPasswordRule( PasswordRule defaultPasswordRule )
+ {
+ this.defaultPasswordRule = defaultPasswordRule;
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/DefaultUserSecurityPolicy.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/DefaultUserSecurityPolicy.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/DefaultUserValidationSettings.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/DefaultUserValidationSettings.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/DefaultUserValidationSettings.java (added)
+++ archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/DefaultUserValidationSettings.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,66 @@
+package org.codehaus.plexus.redback.policy;
+
+/*
+ * 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.configuration.UserConfiguration;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+
+/**
+ * DefaultUserValidationSettings
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Service("userValidationSettings")
+public class DefaultUserValidationSettings
+ implements UserValidationSettings
+{
+ @Resource (name="userConfiguration")
+ private UserConfiguration config;
+
+ private boolean emailValidationRequired;
+
+ private int emailValidationTimeout;
+
+ private String emailSubject;
+
+ public boolean isEmailValidationRequired()
+ {
+ return emailValidationRequired;
+ }
+
+ public int getEmailValidationTimeout()
+ {
+ return emailValidationTimeout;
+ }
+
+ public String getEmailSubject()
+ {
+ return emailSubject;
+ }
+
+ @PostConstruct
+ public void initialize()
+ {
+ this.emailValidationRequired = config.getBoolean( "email.validation.required" );
+ this.emailValidationTimeout = config.getInt( "email.validation.timeout" );
+ this.emailSubject = config.getString( "email.validation.subject" );
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/DefaultUserValidationSettings.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/DefaultUserValidationSettings.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/MustChangePasswordException.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/MustChangePasswordException.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/MustChangePasswordException.java (added)
+++ archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/MustChangePasswordException.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,42 @@
+package org.codehaus.plexus.redback.policy;
+
+import org.codehaus.plexus.redback.users.User;
+
+/*
+ * 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.
+ */
+
+/**
+ * MustChangePasswordException
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class MustChangePasswordException
+ extends PolicyViolationException
+{
+ private final User user;
+
+ public MustChangePasswordException( String message, User user )
+ {
+ super( message );
+ this.user = user;
+ }
+
+ public User getUser()
+ {
+ return user;
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/MustChangePasswordException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/MustChangePasswordException.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordEncoder.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordEncoder.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordEncoder.java (added)
+++ archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordEncoder.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,141 @@
+package org.codehaus.plexus.redback.policy;
+
+/*
+ * 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.
+ */
+
+/**
+ * <p>
+ * Interface for performing authentication operations on a password.
+ * </p>
+ *
+ * <p>Javadoc about encoding and salts copied from Acegi Security.</p>
+ *
+ * @author colin sampaleanu
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public interface PasswordEncoder
+{
+
+ /**
+ * <p>
+ * Sets the system wide salt to use in the encoder.
+ * </p>
+ *
+ * <p>
+ * The specified salt will potentially be used by the implementation to "salt" the initial value before
+ * encoding. A salt is usually a user-specific value which is added to the password before the digest is computed.
+ * This means that computation of digests for common dictionary words will be different than those in the backend
+ * store, because the dictionary word digests will not reflect the addition of the salt. If a per-user salt is
+ * used (rather than a system-wide salt), it also means users with the same password will have different digest
+ * encoded passwords in the backend store.
+ * </p>
+ *
+ * @param salt the salt to use as a default for the encoder.
+ */
+ void setSystemSalt( Object salt );
+
+ /**
+ * <p>
+ * Encodes the specified raw password with an implementation specific algorithm, using the system wide salt.
+ * </p>
+ *
+ * <p>
+ * This will generally be a one-way message digest such as MD5 or SHA, but may also be a plaintext
+ * variant which does no encoding at all, but rather returns the same password it was fed. The latter is useful to
+ * plug in when the original password must be stored as-is.
+ * </p>
+ *
+ * @param rawPass the password to encode
+ *
+ * @return encoded password
+ */
+ String encodePassword( String rawPass );
+
+ /**
+ * <p>
+ * Encodes the specified raw password with an implementation specific algorithm, using user specific salt.
+ * </p>
+ *
+ * <p>
+ * This will generally be a one-way message digest such as MD5 or SHA, but may also be a plaintext
+ * variant which does no encoding at all, but rather returns the same password it was fed. The latter is useful to
+ * plug in when the original password must be stored as-is.
+ * </p>
+ *
+ * <p>
+ * The specified salt will potentially be used by the implementation to "salt" the initial value before
+ * encoding. A salt is usually a user-specific value which is added to the password before the digest is computed.
+ * This means that computation of digests for common dictionary words will be different than those in the backend
+ * store, because the dictionary word digests will not reflect the addition of the salt. If a per-user salt is
+ * used (rather than a system-wide salt), it also means users with the same password will have different digest
+ * encoded passwords in the backend store.
+ * </p>
+ *
+ * @param rawPass the password to encode
+ * @param salt optionally used by the implementation to "salt" the raw password before encoding.
+ * A <code>null</code> value is legal.
+ * @return encoded password
+ */
+ String encodePassword( String rawPass, Object salt );
+
+
+ /**
+ * <p>
+ * Validates a specified "raw" password against an encoded password, using the system wide salt.
+ * </p>
+ *
+ * <p>
+ * The encoded password should have previously been generated by {@link #encodePassword(String)}.
+ * This method will encode the <code>rawPass</code> (using the system wide <code>salt</code>), and then
+ * compared it with the presented <code>encPass</code>.
+ * </p>
+ *
+ * <p>
+ * For an explanation of salts, please refer to {@link #setSystemSalt(Object)}.
+ * </p>
+ *
+ * @param encPass a pre-encoded password
+ * @param rawPass a raw password to encode and compare against the pre-encoded password
+ *
+ * @return true if the password is valid , false otherwise
+ */
+ boolean isPasswordValid( String encPass, String rawPass );
+
+ /**
+ * <p>
+ * Validates a specified "raw" password against an encoded password, using a user specific salt.
+ * </p>
+ *
+ * <p>
+ * The encoded password should have previously been generated by {@link #encodePassword(String,
+ * Object)}. This method will encode the <code>rawPass</code> (using the optional <code>salt</code>), and then
+ * compared it with the presented <code>encPass</code>.
+ * </p>
+ *
+ * <p>
+ * For a discussion of salts, please refer to {@link #encodePassword(String, Object)}.
+ * </p>
+ *
+ * @param encPass a pre-encoded password
+ * @param rawPass a raw password to encode and compare against the pre-encoded password
+ * @param salt optionally used by the implementation to "salt" the raw password before encoding. A
+ * <code>null</code> value is legal.
+ *
+ * @return true if the password is valid , false otherwise
+ */
+ boolean isPasswordValid( String encPass, String rawPass, Object salt );
+}
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordEncoder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordEncoder.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordEncodingException.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordEncodingException.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordEncodingException.java (added)
+++ archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordEncodingException.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,47 @@
+package org.codehaus.plexus.redback.policy;
+
+/*
+ * 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.
+ */
+
+/**
+ * Password Encoding Exception.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class PasswordEncodingException
+ extends RuntimeException
+{
+ public PasswordEncodingException()
+ {
+ super();
+ }
+
+ public PasswordEncodingException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+
+ public PasswordEncodingException( String message )
+ {
+ super( message );
+ }
+
+ public PasswordEncodingException( Throwable cause )
+ {
+ super( cause );
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordEncodingException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordEncodingException.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordRule.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordRule.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordRule.java (added)
+++ archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordRule.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,59 @@
+package org.codehaus.plexus.redback.policy;
+
+/*
+ * 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.users.User;
+
+/**
+ * A Password Rule
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public interface PasswordRule
+{
+
+ /**
+ * Tests if rule is enabled (or not)
+ */
+ boolean isEnabled();
+
+ /**
+ * Sets the User Security Policy to use.
+ *
+ * The policy is set once per instance of a PasswordRule object.
+ *
+ * @param policy the policy to use.
+ */
+ void setUserSecurityPolicy(UserSecurityPolicy policy);
+
+
+ /**
+ * true if the security policy has been set on the rule
+ *
+ * @return boolean
+ */
+ boolean requiresSecurityPolicy();
+
+ /**
+ * Tests the {@link User#getPassword()} for a valid password, based on rule.
+ *
+ * @param violations the place to add any password rule violations that this rule has discovered.
+ * @param user the User to test.
+ */
+ void testPassword( PasswordRuleViolations violations, User user );
+}
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordRule.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordRule.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordRuleViolationException.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordRuleViolationException.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordRuleViolationException.java (added)
+++ archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordRuleViolationException.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,60 @@
+package org.codehaus.plexus.redback.policy;
+
+/*
+ * 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.
+ */
+
+/**
+ * Password Rule Violations Exception
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class PasswordRuleViolationException
+ extends RuntimeException
+{
+ private static final long serialVersionUID = -4686338829234880328L;
+
+ private PasswordRuleViolations violations;
+
+ public PasswordRuleViolationException()
+ {
+ }
+
+ public PasswordRuleViolationException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+
+ public PasswordRuleViolationException( String message )
+ {
+ super( message );
+ }
+
+ public PasswordRuleViolationException( Throwable cause )
+ {
+ super( cause );
+ }
+
+ public PasswordRuleViolations getViolations()
+ {
+ return violations;
+ }
+
+ public void setViolations( PasswordRuleViolations violations )
+ {
+ this.violations = violations;
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordRuleViolationException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordRuleViolationException.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordRuleViolations.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordRuleViolations.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordRuleViolations.java (added)
+++ archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordRuleViolations.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,122 @@
+package org.codehaus.plexus.redback.policy;
+
+/*
+ * 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.users.Messages;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Password Rule Violations
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class PasswordRuleViolations
+{
+ private List<MessageReference> violations;
+
+ public class MessageReference
+ {
+ String key;
+
+ String[] args;
+
+ public String getKey()
+ {
+ return key;
+ }
+
+ public String[] getArgs()
+ {
+ return args;
+ }
+ }
+
+ /**
+ * Construct a Password Rule Violations object.
+ */
+ public PasswordRuleViolations()
+ {
+ violations = new ArrayList<MessageReference>( 0 );
+ }
+
+ /**
+ * Empty out the list of violations.
+ */
+ public void reset()
+ {
+ violations.clear();
+ }
+
+ /**
+ * Add a violation to the underlying list.
+ *
+ * @param key the bundle/localization key for the message.
+ */
+ public void addViolation( String key )
+ {
+ addViolation( key, null );
+ }
+
+ /**
+ * Add a violation to the underlying list.
+ *
+ * @param key the bundle/localization key for the message.
+ * @param args the arguments for the message.
+ */
+ public void addViolation( String key, String[] args )
+ {
+ MessageReference mesgref = new MessageReference();
+ mesgref.key = key;
+ mesgref.args = args;
+ violations.add( mesgref );
+ }
+
+ /**
+ * Get the List of Violations as localized and post-processed {@link String}s.
+ *
+ * @return the List of {@link String} objects.
+ */
+ public List<String> getLocalizedViolations()
+ {
+ List<String> msgs = new ArrayList<String>( violations.size() );
+
+ for ( MessageReference msgref : violations )
+ {
+ msgs.add( Messages.getString( msgref.key, msgref.args ) );
+ }
+
+ return msgs;
+ }
+
+ /**
+ * Simple test to see if there are any violations.
+ *
+ * @return true if there are any violations.
+ */
+ public boolean hasViolations()
+ {
+ return !violations.isEmpty();
+ }
+
+ public List<MessageReference> getViolations()
+ {
+ return violations;
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordRuleViolations.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PasswordRuleViolations.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PolicyContext.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PolicyContext.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PolicyContext.java (added)
+++ archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PolicyContext.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,75 @@
+package org.codehaus.plexus.redback.policy;
+
+/*
+ * 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 java.util.HashMap;
+import java.util.Map;
+
+/**
+ * PolicyContext - A Thread Local Context.
+ * Useful for managing policy operations on a thread local point of view.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class PolicyContext
+{
+ static ThreadLocal<PolicyContext> policyContext = new PolicyContextThreadLocal();
+
+ Map<Object, Object> context;
+
+ public PolicyContext( Map<Object, Object> map )
+ {
+ context = map;
+ }
+
+ public static void setContext( PolicyContext context )
+ {
+ policyContext.set( context );
+ }
+
+ public static PolicyContext getContext()
+ {
+ PolicyContext ctx = (PolicyContext) policyContext.get();
+ if ( ctx == null )
+ {
+ ctx = new PolicyContext( new HashMap<Object, Object>() );
+ setContext( ctx );
+ }
+
+ return ctx;
+ }
+
+ public Object get( Object key )
+ {
+ return context.get( key );
+ }
+
+ public void put( Object key, Object value )
+ {
+ context.put( key, value );
+ }
+
+ private static class PolicyContextThreadLocal
+ extends ThreadLocal<PolicyContext>
+ {
+ protected PolicyContext initialValue()
+ {
+ return new PolicyContext( new HashMap<Object, Object>() );
+ }
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PolicyContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PolicyContext.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PolicyViolationException.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PolicyViolationException.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PolicyViolationException.java (added)
+++ archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PolicyViolationException.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,48 @@
+package org.codehaus.plexus.redback.policy;
+
+/*
+ * 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.
+ */
+
+/**
+ * PolicyViolationException
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class PolicyViolationException
+ extends Exception
+{
+
+ public PolicyViolationException()
+ {
+ super();
+ }
+
+ public PolicyViolationException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+
+ public PolicyViolationException( String message )
+ {
+ super( message );
+ }
+
+ public PolicyViolationException( Throwable cause )
+ {
+ super( cause );
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PolicyViolationException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/PolicyViolationException.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/RememberMeCookieSettings.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/RememberMeCookieSettings.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/RememberMeCookieSettings.java (added)
+++ archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/RememberMeCookieSettings.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,48 @@
+package org.codehaus.plexus.redback.policy;
+
+/*
+ * 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.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+
+/**
+ * RememberMeCookieSettings
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Service("cookieSettings#rememberMe")
+public class RememberMeCookieSettings
+ extends AbstractCookieSettings
+{
+ private boolean enabled;
+
+ public boolean isEnabled()
+ {
+ return enabled;
+ }
+
+ @PostConstruct
+ public void initialize()
+ {
+ this.cookieTimeout = config.getInt( "security.rememberme.timeout" );
+ this.domain = config.getString( "security.rememberme.domain" );
+ this.path = config.getString( "security.rememberme.path" );
+ this.enabled = config.getBoolean( "security.rememberme.enabled" );
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/RememberMeCookieSettings.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/RememberMeCookieSettings.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/SignonCookieSettings.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/SignonCookieSettings.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/SignonCookieSettings.java (added)
+++ archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/SignonCookieSettings.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,46 @@
+package org.codehaus.plexus.redback.policy;
+
+/*
+ * Copyright 2006-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.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+
+/**
+ * SignonCookieSettings
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Service("cookieSettings#signon")
+public class SignonCookieSettings
+ extends AbstractCookieSettings
+{
+ @PostConstruct
+ public void initialize()
+ {
+ // cookie timeouts in the configuration settings is labeled to be in minutes, so adjust to minutes
+ cookieTimeout = config.getInt( "security.signon.timeout" ) * 60;
+ domain = config.getString( "security.signon.domain" );
+ path = config.getString( "security.signon.path" );
+ }
+
+ public boolean isEnabled()
+ {
+ return true;
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/SignonCookieSettings.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-policy/src/main/java/org/codehaus/plexus/redback/policy/SignonCookieSettings.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision