From 2348016ffa859bc54dc53c22ff3f433c40d4df3f Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sat, 7 Apr 2012 22:18:08 +0000 Subject: package move to o.a.a.r module redback-keys-memory git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1310889 13f79535-47bb-0310-9956-ffa450edef68 --- .../keys/memory/MemoryAuthenticationKey.java | 109 ++++++++++++++++++ .../redback/keys/memory/MemoryKeyManager.java | 126 +++++++++++++++++++++ .../keys/memory/MemoryAuthenticationKey.java | 109 ------------------ .../redback/keys/memory/MemoryKeyManager.java | 125 -------------------- .../src/main/resources/META-INF/spring-context.xml | 2 +- .../redback/keys/memory/MemoryKeyManagerTest.java | 50 ++++++++ .../redback/keys/memory/MemoryKeyManagerTest.java | 50 -------- 7 files changed, 286 insertions(+), 285 deletions(-) create mode 100644 redback-keys/redback-keys-providers/redback-keys-memory/src/main/java/org/apache/archiva/redback/keys/memory/MemoryAuthenticationKey.java create mode 100644 redback-keys/redback-keys-providers/redback-keys-memory/src/main/java/org/apache/archiva/redback/keys/memory/MemoryKeyManager.java delete mode 100644 redback-keys/redback-keys-providers/redback-keys-memory/src/main/java/org/codehaus/plexus/redback/keys/memory/MemoryAuthenticationKey.java delete mode 100644 redback-keys/redback-keys-providers/redback-keys-memory/src/main/java/org/codehaus/plexus/redback/keys/memory/MemoryKeyManager.java create mode 100644 redback-keys/redback-keys-providers/redback-keys-memory/src/test/java/org/apache/archiva/redback/keys/memory/MemoryKeyManagerTest.java delete mode 100644 redback-keys/redback-keys-providers/redback-keys-memory/src/test/java/org/codehaus/plexus/redback/keys/memory/MemoryKeyManagerTest.java (limited to 'redback-keys') diff --git a/redback-keys/redback-keys-providers/redback-keys-memory/src/main/java/org/apache/archiva/redback/keys/memory/MemoryAuthenticationKey.java b/redback-keys/redback-keys-providers/redback-keys-memory/src/main/java/org/apache/archiva/redback/keys/memory/MemoryAuthenticationKey.java new file mode 100644 index 000000000..fb0b6d0eb --- /dev/null +++ b/redback-keys/redback-keys-providers/redback-keys-memory/src/main/java/org/apache/archiva/redback/keys/memory/MemoryAuthenticationKey.java @@ -0,0 +1,109 @@ +package org.apache.archiva.redback.keys.memory; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.redback.keys.AuthenticationKey; + +import java.util.Date; + +/** + * MemoryAuthenticationKey + * + * @author Joakim Erdfelt + * @version $Id$ + */ +public class MemoryAuthenticationKey + implements AuthenticationKey +{ + private String key; + + private String forPrincipal; + + private String purpose; + + private Date dateCreated; + + private Date dateExpires; + + public Date getDateCreated() + { + return dateCreated; + } + + public Date getDateExpires() + { + return dateExpires; + } + + public String getForPrincipal() + { + return forPrincipal; + } + + public String getKey() + { + return key; + } + + public String getPurpose() + { + return purpose; + } + + public void setDateCreated( Date dateCreated ) + { + this.dateCreated = dateCreated; + } + + public void setDateExpires( Date dateExpires ) + { + this.dateExpires = dateExpires; + } + + public void setForPrincipal( String forPrincipal ) + { + this.forPrincipal = forPrincipal; + } + + public void setKey( String key ) + { + this.key = key; + } + + public void setPurpose( String purpose ) + { + this.purpose = purpose; + } + + public String toString() + { + StringBuffer sb = new StringBuffer(); + + sb.append( "MemoryAuthenticationKey[" ); + sb.append( "key=" ).append( key ); + sb.append( ",forPrincipal=" ).append( forPrincipal ); + sb.append( ",purpose=" ).append( purpose ); + sb.append( ",dateCreated=" ).append( dateCreated ); + sb.append( ",dateExpired=" ).append( dateExpires ); + sb.append( ']' ); + + return sb.toString(); + } +} diff --git a/redback-keys/redback-keys-providers/redback-keys-memory/src/main/java/org/apache/archiva/redback/keys/memory/MemoryKeyManager.java b/redback-keys/redback-keys-providers/redback-keys-memory/src/main/java/org/apache/archiva/redback/keys/memory/MemoryKeyManager.java new file mode 100644 index 000000000..6db386445 --- /dev/null +++ b/redback-keys/redback-keys-providers/redback-keys-memory/src/main/java/org/apache/archiva/redback/keys/memory/MemoryKeyManager.java @@ -0,0 +1,126 @@ +package org.apache.archiva.redback.keys.memory; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.redback.keys.AbstractKeyManager; +import org.apache.archiva.redback.keys.AuthenticationKey; +import org.apache.archiva.redback.keys.KeyManagerException; +import org.apache.archiva.redback.keys.KeyNotFoundException; +import org.apache.archiva.redback.keys.memory.MemoryAuthenticationKey; +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 Joakim Erdfelt + * @version $Id$ + */ +@Service("keyManager#memory") +public class MemoryKeyManager + extends AbstractKeyManager +{ + private Map keys = new HashMap(); + + 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 getAllKeys() + { + return new ArrayList( 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"; + } +} diff --git a/redback-keys/redback-keys-providers/redback-keys-memory/src/main/java/org/codehaus/plexus/redback/keys/memory/MemoryAuthenticationKey.java b/redback-keys/redback-keys-providers/redback-keys-memory/src/main/java/org/codehaus/plexus/redback/keys/memory/MemoryAuthenticationKey.java deleted file mode 100644 index ead07ca59..000000000 --- a/redback-keys/redback-keys-providers/redback-keys-memory/src/main/java/org/codehaus/plexus/redback/keys/memory/MemoryAuthenticationKey.java +++ /dev/null @@ -1,109 +0,0 @@ -package org.codehaus.plexus.redback.keys.memory; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.redback.keys.AuthenticationKey; - -import java.util.Date; - -/** - * MemoryAuthenticationKey - * - * @author Joakim Erdfelt - * @version $Id$ - */ -public class MemoryAuthenticationKey - implements AuthenticationKey -{ - private String key; - - private String forPrincipal; - - private String purpose; - - private Date dateCreated; - - private Date dateExpires; - - public Date getDateCreated() - { - return dateCreated; - } - - public Date getDateExpires() - { - return dateExpires; - } - - public String getForPrincipal() - { - return forPrincipal; - } - - public String getKey() - { - return key; - } - - public String getPurpose() - { - return purpose; - } - - public void setDateCreated( Date dateCreated ) - { - this.dateCreated = dateCreated; - } - - public void setDateExpires( Date dateExpires ) - { - this.dateExpires = dateExpires; - } - - public void setForPrincipal( String forPrincipal ) - { - this.forPrincipal = forPrincipal; - } - - public void setKey( String key ) - { - this.key = key; - } - - public void setPurpose( String purpose ) - { - this.purpose = purpose; - } - - public String toString() - { - StringBuffer sb = new StringBuffer(); - - sb.append( "MemoryAuthenticationKey[" ); - sb.append( "key=" ).append( key ); - sb.append( ",forPrincipal=" ).append( forPrincipal ); - sb.append( ",purpose=" ).append( purpose ); - sb.append( ",dateCreated=" ).append( dateCreated ); - sb.append( ",dateExpired=" ).append( dateExpires ); - sb.append( ']' ); - - return sb.toString(); - } -} diff --git a/redback-keys/redback-keys-providers/redback-keys-memory/src/main/java/org/codehaus/plexus/redback/keys/memory/MemoryKeyManager.java b/redback-keys/redback-keys-providers/redback-keys-memory/src/main/java/org/codehaus/plexus/redback/keys/memory/MemoryKeyManager.java deleted file mode 100644 index 4823f8133..000000000 --- a/redback-keys/redback-keys-providers/redback-keys-memory/src/main/java/org/codehaus/plexus/redback/keys/memory/MemoryKeyManager.java +++ /dev/null @@ -1,125 +0,0 @@ -package org.codehaus.plexus.redback.keys.memory; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.redback.keys.AbstractKeyManager; -import org.apache.archiva.redback.keys.AuthenticationKey; -import org.apache.archiva.redback.keys.KeyManagerException; -import org.apache.archiva.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 Joakim Erdfelt - * @version $Id$ - */ -@Service("keyManager#memory") -public class MemoryKeyManager - extends AbstractKeyManager -{ - private Map keys = new HashMap(); - - 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 getAllKeys() - { - return new ArrayList( 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"; - } -} diff --git a/redback-keys/redback-keys-providers/redback-keys-memory/src/main/resources/META-INF/spring-context.xml b/redback-keys/redback-keys-providers/redback-keys-memory/src/main/resources/META-INF/spring-context.xml index a6cf8ab67..c314c5d8b 100644 --- a/redback-keys/redback-keys-providers/redback-keys-memory/src/main/resources/META-INF/spring-context.xml +++ b/redback-keys/redback-keys-providers/redback-keys-memory/src/main/resources/META-INF/spring-context.xml @@ -29,6 +29,6 @@ + base-package="org.apache.archiva.redback.keys.memory"/> \ No newline at end of file diff --git a/redback-keys/redback-keys-providers/redback-keys-memory/src/test/java/org/apache/archiva/redback/keys/memory/MemoryKeyManagerTest.java b/redback-keys/redback-keys-providers/redback-keys-memory/src/test/java/org/apache/archiva/redback/keys/memory/MemoryKeyManagerTest.java new file mode 100644 index 000000000..256cfd24f --- /dev/null +++ b/redback-keys/redback-keys-providers/redback-keys-memory/src/test/java/org/apache/archiva/redback/keys/memory/MemoryKeyManagerTest.java @@ -0,0 +1,50 @@ +package org.apache.archiva.redback.keys.memory; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.redback.keys.KeyManager; +import org.codehaus.plexus.redback.keys.KeyManagerTestCase; +import org.junit.Before; + +import javax.inject.Inject; +import javax.inject.Named; + +/** + * MemoryKeyManagerTest + * + * @author Joakim Erdfelt + * @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 ); + } + +} diff --git a/redback-keys/redback-keys-providers/redback-keys-memory/src/test/java/org/codehaus/plexus/redback/keys/memory/MemoryKeyManagerTest.java b/redback-keys/redback-keys-providers/redback-keys-memory/src/test/java/org/codehaus/plexus/redback/keys/memory/MemoryKeyManagerTest.java deleted file mode 100644 index e1a502e03..000000000 --- a/redback-keys/redback-keys-providers/redback-keys-memory/src/test/java/org/codehaus/plexus/redback/keys/memory/MemoryKeyManagerTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.codehaus.plexus.redback.keys.memory; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.redback.keys.KeyManager; -import org.codehaus.plexus.redback.keys.KeyManagerTestCase; -import org.junit.Before; - -import javax.inject.Inject; -import javax.inject.Named; - -/** - * MemoryKeyManagerTest - * - * @author Joakim Erdfelt - * @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 ); - } - -} -- cgit v1.2.3