From 62efc70bd27c0ddb8bd01c0f67b0c96646aaaea5 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Tue, 27 Sep 2016 23:13:03 +0200 Subject: [PATCH 01/30] Adding JPA implementation of users and rbac provider Uses OpenJPA --- pom.xml | 14 +- redback-common/pom.xml | 1 + redback-common/redback-common-jpa/pom.xml | 57 +++ .../resources/META-INF/persistence-hsqldb.xml | 41 ++ .../main/resources/META-INF/persistence.xml | 36 ++ redback-rbac/redback-rbac-providers/pom.xml | 1 + .../redback-rbac-jpa/pom.xml | 70 +++ .../redback/rbac/jpa/JpaRbacManager.java | 452 ++++++++++++++++++ .../redback/rbac/jpa/model/JpaOperation.java | 91 ++++ .../redback/rbac/jpa/model/JpaPermission.java | 123 +++++ .../redback/rbac/jpa/model/JpaResource.java | 91 ++++ .../redback/rbac/jpa/model/JpaRole.java | 172 +++++++ .../rbac/jpa/model/JpaUserAssignment.java | 97 ++++ .../redback/rbac/jpa/JpaRbacManagerTest.java | 132 +++++ .../src/test/resources/spring-context.xml | 40 ++ .../src/test/resources/test.properties | 22 + redback-users/redback-users-providers/pom.xml | 1 + .../redback-users-jpa/pom.xml | 68 +++ .../redback/users/jpa/JpaUserManager.java | 307 ++++++++++++ .../redback/users/jpa/JpaUserQuery.java | 123 +++++ .../redback/users/jpa/model/JpaUser.java | 206 ++++++++ .../redback/users/jpa/JpaUserManagerTest.java | 86 ++++ .../src/test/resources/spring-context.xml | 50 ++ .../src/test/resources/test.properties | 22 + .../test/AbstractUserManagerTestCase.java | 2 + 25 files changed, 2304 insertions(+), 1 deletion(-) create mode 100644 redback-common/redback-common-jpa/pom.xml create mode 100644 redback-common/redback-common-jpa/src/main/resources/META-INF/persistence-hsqldb.xml create mode 100644 redback-common/redback-common-jpa/src/main/resources/META-INF/persistence.xml create mode 100644 redback-rbac/redback-rbac-providers/redback-rbac-jpa/pom.xml create mode 100644 redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java create mode 100644 redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaOperation.java create mode 100644 redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaPermission.java create mode 100644 redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaResource.java create mode 100644 redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaRole.java create mode 100644 redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaUserAssignment.java create mode 100644 redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/test/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManagerTest.java create mode 100644 redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/test/resources/spring-context.xml create mode 100644 redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/test/resources/test.properties create mode 100644 redback-users/redback-users-providers/redback-users-jpa/pom.xml create mode 100644 redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/JpaUserManager.java create mode 100644 redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/JpaUserQuery.java create mode 100644 redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/model/JpaUser.java create mode 100644 redback-users/redback-users-providers/redback-users-jpa/src/test/java/org/apache/archiva/redback/users/jpa/JpaUserManagerTest.java create mode 100644 redback-users/redback-users-providers/redback-users-jpa/src/test/resources/spring-context.xml create mode 100644 redback-users/redback-users-providers/redback-users-jpa/src/test/resources/test.properties diff --git a/pom.xml b/pom.xml index fa30ae55..3e218ee0 100644 --- a/pom.xml +++ b/pom.xml @@ -78,6 +78,8 @@ UTF-8 true 3.0.3 + 2.4.1 + + + + redback-common + org.apache.archiva.redback + 2.5-SNAPSHOT + + 4.0.0 + + redback-common-jpa + jar + Redback :: JPA Common Package + + + + org.apache.archiva.redback + redback-rbac-model + + + org.apache.archiva.redback + redback-users-api + + + + org.apache.openjpa + openjpa + ${openjpa.version} + + + org.hsqldb + hsqldb + test + + + + + \ No newline at end of file diff --git a/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence-hsqldb.xml b/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence-hsqldb.xml new file mode 100644 index 00000000..a78444e0 --- /dev/null +++ b/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence-hsqldb.xml @@ -0,0 +1,41 @@ + + + + + org.apache.openjpa.persistence.PersistenceProviderImpl + java:comp/env/jdbc/redbackjpa + org.apache.archiva.redback.users.jpa.model.JpaUser + org.apache.archiva.redback.rbac.jpa.model.JpaOperation + org.apache.archiva.redback.rbac.jpa.model.JpaResource + org.apache.archiva.redback.rbac.jpa.model.JpaPermission + org.apache.archiva.redback.rbac.jpa.model.JpaRole + org.apache.archiva.redback.rbac.jpa.model.JpaUserAssignment + + + + + + + + + + + diff --git a/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence.xml b/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence.xml new file mode 100644 index 00000000..46878e88 --- /dev/null +++ b/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,36 @@ + + + + + org.apache.openjpa.persistence.PersistenceProviderImpl + java:comp/env/jdbc/redbackjpa + org.apache.archiva.redback.users.jpa.model.JpaUser + org.apache.archiva.redback.rbac.jpa.model.JpaOperation + org.apache.archiva.redback.rbac.jpa.model.JpaResource + org.apache.archiva.redback.rbac.jpa.model.JpaPermission + org.apache.archiva.redback.rbac.jpa.model.JpaRole + org.apache.archiva.redback.rbac.jpa.model.JpaUserAssignment + + + + + + diff --git a/redback-rbac/redback-rbac-providers/pom.xml b/redback-rbac/redback-rbac-providers/pom.xml index 0edb4970..a94d451d 100644 --- a/redback-rbac/redback-rbac-providers/pom.xml +++ b/redback-rbac/redback-rbac-providers/pom.xml @@ -32,5 +32,6 @@ redback-rbac-memory redback-rbac-cached redback-rbac-ldap + redback-rbac-jpa diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/pom.xml b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/pom.xml new file mode 100644 index 00000000..77045ab9 --- /dev/null +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/pom.xml @@ -0,0 +1,70 @@ + + + + + redback-rbac-providers + org.apache.archiva.redback + 2.5-SNAPSHOT + + 4.0.0 + + redback-rbac-jpa + jar + Redback :: RBAC Provider :: JPA + + + + org.apache.archiva.redback + redback-rbac-model + + + org.springframework + spring-context-support + + + javax.annotation + jsr250-api + + + org.apache.archiva.redback + redback-rbac-tests + test + + + org.apache.archiva.redback + redback-common-jpa + + + + org.apache.openjpa + openjpa + ${openjpa.version} + + + org.hsqldb + hsqldb + test + + + + + \ No newline at end of file diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java new file mode 100644 index 00000000..ced9104b --- /dev/null +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java @@ -0,0 +1,452 @@ +package org.apache.archiva.redback.rbac.jpa; + +/* + * 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.rbac.*; +import org.apache.archiva.redback.rbac.jpa.model.*; +import org.apache.openjpa.persistence.Type; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import javax.persistence.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; + +/** + * Created by martin on 20.09.16. + */ +@Service("rbacManager#jpa") +public class JpaRbacManager extends AbstractRBACManager { + + + @PersistenceContext(unitName = "redback-jpa") + EntityManager em; + + + private AtomicBoolean initialized = new AtomicBoolean(false); + + + public void setEntityManager(EntityManager em) { + this.em = em; + } + + + + @Override + public Role createRole(String name) { + JpaRole role = new JpaRole(); + role.setName(name); + return role; + } + + @Override + public Role saveRole(Role role) throws RbacObjectInvalidException, RbacManagerException { + RBACObjectAssertions.assertValid( role ); + final EntityManager em = getEm(); + em.getTransaction().begin(); + em.persist(role); + + em.getTransaction().commit(); + fireRbacRoleSaved(role); + for (Permission perm : role.getPermissions()) { + fireRbacPermissionSaved(perm); + } + return role; + } + + @Override + public void saveRoles(Collection roles) throws RbacObjectInvalidException, RbacManagerException { + if ( roles == null ) + { + // Nothing to do. + return; + } + + final EntityManager em = getEm(); + em.getTransaction().begin(); + for (Role role : roles ) { + RBACObjectAssertions.assertValid(role); + em.persist(role); + } + em.getTransaction().commit(); + for (Role role : roles) { + fireRbacRoleSaved(role); + } + } + + @Override + public Role getRole(String roleName) throws RbacObjectNotFoundException, RbacManagerException { + final EntityManager em = getEm(); + TypedQuery q = em.createQuery("SELECT r FROM JpaRole r WHERE r.name = :rolename", JpaRole.class); + q.setParameter("rolename",roleName); + return q.getSingleResult(); + } + + @Override + public List getAllRoles() throws RbacManagerException { + final EntityManager em = getEm(); + Query q = em.createQuery("SELECT r FROM JpaRole r"); + return q.getResultList(); + } + + @Override + public void removeRole(Role role) throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException { + RBACObjectAssertions.assertValid(role); + if (!(role instanceof JpaRole)) { + throw new RbacObjectInvalidException("Role object is not instance of JpaRole"); + } + if ( role.isPermanent() ) + { + throw new RbacPermanentException( "Unable to delete permanent role [" + role.getName() + "]" ); + } + final EntityManager em = getEm(); + em.getTransaction().begin(); + JpaRole myRole = em.find(JpaRole.class, role.getName()); + if (myRole == null) { + throw new RbacObjectNotFoundException("Role not found "+role.getName()); + } + myRole.setPermissions(new ArrayList()); + em.remove(myRole); + em.getTransaction().commit(); + fireRbacRoleRemoved(myRole); + } + + @Override + public Permission createPermission(String name) throws RbacManagerException { + JpaPermission permission = new JpaPermission(); + permission.setName(name); + return permission; + } + + @Override + public Permission createPermission(String name, String operationName, String resourceIdentifier) throws RbacManagerException { + JpaPermission permission = new JpaPermission(); + permission.setName(name); + Operation op; + try { + op = getOperation(operationName); + } catch (RbacObjectNotFoundException ex) { + op = createOperation(operationName); + } + permission.setOperation(op); + Resource res; + try { + res = getResource(resourceIdentifier); + } catch (RbacObjectNotFoundException ex) { + res = createResource(resourceIdentifier); + } + permission.setResource(res); + return permission; + } + + @Override + public Permission savePermission(Permission permission) throws RbacObjectInvalidException, RbacManagerException { + RBACObjectAssertions.assertValid(permission); + if (!(permission instanceof JpaPermission)) { + throw new RbacObjectInvalidException("The permission object ist not instance of JpaPermission"); + } + final EntityManager em = getEm(); + em.getTransaction().begin(); + em.persist(permission); + em.getTransaction().commit(); + fireRbacPermissionSaved(permission); + return permission; + } + + @Override + public Permission getPermission(String permissionName) throws RbacObjectNotFoundException, RbacManagerException { + final EntityManager em = getEm(); + TypedQuery q = em.createQuery("SELECT p FROM JpaPermission p WHERE p.name=:name", Permission.class); + q.setParameter("name",permissionName); + Permission res = q.getSingleResult(); + if (res==null) { + throw new RbacObjectNotFoundException("Permission "+permissionName+" not found"); + } + return res; + } + + @Override + public List getAllPermissions() throws RbacManagerException { + final EntityManager em = getEm(); + TypedQuery q = em.createQuery("SELECT p FROM JpaPermission p",JpaPermission.class); + return (List)(List)q.getResultList(); + } + + @Override + public void removePermission(Permission permission) throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException { + RBACObjectAssertions.assertValid(permission); + if (!(permission instanceof JpaPermission)) { + throw new RbacObjectInvalidException("The permission object is not JpaPermission object"); + } + if ( permission.isPermanent() ) + { + throw new RbacPermanentException( "Unable to delete permanent permission [" + permission.getName() + "]" ); + } + final EntityManager em = getEm(); + em.getTransaction().begin(); + Permission p = em.find(JpaPermission.class, permission.getName()); + if (p == null) { + throw new RbacObjectNotFoundException("Permission " + permission.getName() + " not found"); + } + em.remove(p); + em.getTransaction().commit(); + fireRbacPermissionRemoved(p); + } + + @Override + public Operation createOperation(String name) throws RbacManagerException { + JpaOperation op = new JpaOperation(); + op.setName(name); + return op; + } + + @Override + public Operation saveOperation(Operation operation) throws RbacObjectInvalidException, RbacManagerException { + RBACObjectAssertions.assertValid(operation); + if (!(operation instanceof JpaOperation)) { + throw new RbacObjectInvalidException("Operation is not JpaOperation object"); + } + final EntityManager em = getEm(); + em.getTransaction().begin(); + em.persist(operation); + em.getTransaction().commit(); + return operation; + } + + @Override + public Operation getOperation(String operationName) throws RbacObjectNotFoundException, RbacManagerException { + final EntityManager em = getEm(); + Operation op = em.find(JpaOperation.class,operationName); + if(op==null) { + throw new RbacObjectNotFoundException("Operation "+operationName+" not found"); + } + return op; + } + + @Override + public List getAllOperations() throws RbacManagerException { + final EntityManager em = getEm(); + Query q = em.createQuery("SELECT o FROM JpaOperation o"); + return q.getResultList(); + } + + @Override + public void removeOperation(Operation operation) throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException { + RBACObjectAssertions.assertValid(operation); + if (!(operation instanceof JpaOperation)) { + throw new RbacObjectInvalidException("Operation is not JpaOperation object"); + } + if ( operation.isPermanent() ) + { + throw new RbacPermanentException( "Unable to delete permanent operation [" + operation.getName() + "]" ); + } + final EntityManager em = getEm(); + em.getTransaction().begin(); + Operation op = em.find(JpaOperation.class, operation.getName()); + if (op==null) { + throw new RbacObjectNotFoundException("Operation not found "+operation.getName()); + } + em.remove(op); + em.getTransaction().commit(); + + } + + @Override + public Resource createResource(String identifier) throws RbacManagerException { + JpaResource resource = new JpaResource(); + resource.setIdentifier(identifier); + return resource; + } + + @Override + public Resource saveResource(Resource resource) throws RbacObjectInvalidException, RbacManagerException { + RBACObjectAssertions.assertValid(resource); + if (!(resource instanceof JpaResource)) { + throw new RbacObjectInvalidException("Resource is not JpaResource"); + } + final EntityManager em = getEm(); + em.getTransaction().begin(); + em.persist(resource); + em.getTransaction().commit(); + return resource; + } + + @Override + public Resource getResource(String resourceIdentifier) throws RbacObjectNotFoundException, RbacManagerException { + final EntityManager em = getEm(); + Resource r = em.find(JpaResource.class,resourceIdentifier); + if (r==null) { + throw new RbacObjectNotFoundException("Resource "+resourceIdentifier+" not found"); + } + return r; + } + + @Override + public List getAllResources() throws RbacManagerException { + final EntityManager em = getEm(); + TypedQuery q = em.createQuery("SELECT r FROM JpaResource r",JpaResource.class); + return (List)(List)q.getResultList(); + } + + @Override + public void removeResource(Resource resource) throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException { + RBACObjectAssertions.assertValid(resource); + if (!(resource instanceof JpaResource)) { + throw new RbacObjectInvalidException("Resource is not JpaResource"); + } + if (resource.isPermanent()) { + throw new RbacObjectInvalidException("Unable to delete permanent resource ["+resource.getIdentifier()+ "]"); + } + final EntityManager em = getEm(); + em.getTransaction().begin(); + Resource res = em.find(JpaResource.class, resource.getIdentifier()); + if (res==null) { + throw new RbacObjectNotFoundException("Resource "+resource.getIdentifier()+" not found"); + } + em.remove(res); + em.getTransaction().commit(); + } + + @Override + public UserAssignment createUserAssignment(String principal) throws RbacManagerException { + JpaUserAssignment ua = new JpaUserAssignment(); + ua.setPrincipal(principal); + return ua; + } + + @Override + public UserAssignment saveUserAssignment(UserAssignment userAssignment) throws RbacObjectInvalidException, RbacManagerException { + RBACObjectAssertions.assertValid(userAssignment); + if (!(userAssignment instanceof JpaUserAssignment)) { + throw new RbacObjectInvalidException("Cannto save object that is not JpaUserAssignment"); + } + final EntityManager em = getEm(); + em.getTransaction().begin(); + em.persist(userAssignment); + em.getTransaction().commit(); + fireRbacUserAssignmentSaved(userAssignment); + return userAssignment; + } + + @Override + public UserAssignment getUserAssignment(String principal) throws RbacObjectNotFoundException, RbacManagerException { + final EntityManager em = getEm(); + UserAssignment ua = em.find(JpaUserAssignment.class, principal); + if (ua==null) { + throw new RbacObjectNotFoundException("User assignment not found "+principal); + } + return ua; + } + + @Override + public List getAllUserAssignments() throws RbacManagerException { + final EntityManager em = getEm(); + Query q = em.createQuery("SELECT ua FROM JpaUserAssignment ua"); + return q.getResultList(); + } + + @Override + public List getUserAssignmentsForRoles(Collection roleNames) throws RbacManagerException { + final EntityManager em = getEm(); + Query q = em.createQuery("SELECT ua FROM JpaUserAssignment ua, ua.roleNames rn WHERE rn IN :rolenames"); + q.setParameter("rolenames",roleNames); + return q.getResultList(); + } + + @Override + public void removeUserAssignment(UserAssignment userAssignment) throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException { + RBACObjectAssertions.assertValid(userAssignment); + if (userAssignment.isPermanent()) { + throw new RbacObjectInvalidException("Cannot remove permanent object "+userAssignment.getPrincipal()); + } + final EntityManager em = getEm(); + em.getTransaction().begin(); + UserAssignment ua = em.find(UserAssignment.class, userAssignment.getPrincipal()); + if (ua==null) { + throw new RbacObjectNotFoundException("User assignment not found "+userAssignment.getPrincipal()); + } + em.remove(ua); + em.getTransaction().commit(); + fireRbacUserAssignmentRemoved(userAssignment); + } + + @Override + public void eraseDatabase() { + final EntityManager em = getEm(); + // Deletion is a bit tricky, because the JPA bulk delete queries do not cascade + // or keep foreign keys into account. + em.getTransaction().begin(); + TypedQuery tqp = em.createQuery("SELECT r FROM JpaPermission r",JpaPermission.class); + for(JpaPermission p : tqp.getResultList()) { + p.setOperation(null); + p.setResource(null); + } + TypedQuery tqr = em.createQuery("SELECT r FROM JpaRole r",JpaRole.class); + for (JpaRole r : tqr.getResultList()) { + r.getPermissions().clear(); + } + em.flush(); + TypedQuery tqo = em.createQuery("SELECT o FROM JpaOperation o",JpaOperation.class); + for(JpaOperation o : tqo.getResultList()) { + em.remove(o); + } + TypedQuery tqre = em.createQuery("SELECT re FROM JpaResource re",JpaResource.class); + for(JpaResource re : tqre.getResultList()) { + em.remove(re); + } + for (JpaPermission p : tqp.getResultList()) { + em.remove(p); + } + for (JpaRole r : tqr.getResultList()) { + em.remove(r); + } + TypedQuery tqu = em.createQuery("SELECT ua FROM JpaUserAssignment ua", JpaUserAssignment.class); + for(JpaUserAssignment ua : tqu.getResultList()) { + em.remove(ua); + } + em.getTransaction().commit(); + + + } + + @Override + public String getDescriptionKey() { + return "archiva.redback.rbacmanager.jpa"; + } + + @Override + public boolean isReadOnly() { + return false; + } + + private EntityManager getEm() { + if (initialized.compareAndSet(false, true)) { + Query q = em.createQuery("SELECT COUNT(r.name) FROM JpaRole r"); + boolean dbInit = q.getFirstResult()==0; + fireRbacInit(dbInit); + } + return em; + } + + +} diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaOperation.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaOperation.java new file mode 100644 index 00000000..66a41a15 --- /dev/null +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaOperation.java @@ -0,0 +1,91 @@ +package org.apache.archiva.redback.rbac.jpa.model; + +/* + * 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.rbac.Operation; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import java.io.Serializable; + +/** + * Created by martin on 25.09.16. + */ +@Entity +@Table(name="SECURITY_OPERATIONS") +public class JpaOperation implements Operation, Serializable { + + @Id + @Column(name="NAME") + private String name; + @Column(name="DESCRIPTION") + private String description; + @Column(name="PERMANENT") + private boolean permanent; + + + @Override + public String getName() { + return name; + } + + @Override + public void setName(String name) { + this.name = name; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public void setDescription(String description) { + this.description = description; + } + + @Override + public boolean isPermanent() { + return permanent; + } + + @Override + public void setPermanent(boolean permanent) { + this.permanent = permanent; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + JpaOperation that = (JpaOperation) o; + + return name.equals(that.name); + + } + + @Override + public int hashCode() { + return name.hashCode(); + } +} diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaPermission.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaPermission.java new file mode 100644 index 00000000..4ac69896 --- /dev/null +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaPermission.java @@ -0,0 +1,123 @@ +package org.apache.archiva.redback.rbac.jpa.model; + +/* + * 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.rbac.Operation; +import org.apache.archiva.redback.rbac.Permission; +import org.apache.archiva.redback.rbac.Resource; +import org.apache.archiva.redback.rbac.jpa.JpaRbacManager; + +import javax.persistence.*; +import java.io.Serializable; + +/** + * Created by martin on 25.09.16. + */ +@Entity +@Table(name="SECURITY_PERMISSIONS") +public class JpaPermission implements Permission,Serializable { + + @Id + @Column(name="NAME") + private String name; + @Column(name="DESCRIPTION") + private String description; + @Column(name="PERMANENT") + private boolean permanent; + @ManyToOne(cascade = CascadeType.PERSIST) + @JoinColumn( + name="OPERATION_NAME_OID", + referencedColumnName = "NAME" + ) + private JpaOperation operation; + @ManyToOne(cascade = CascadeType.PERSIST) + @JoinColumn( + name="RESOURCE_IDENTIFIER_OID", + referencedColumnName = "IDENTIFIER" + ) + private JpaResource resource; + + + @Override + public String getName() { + return name; + } + + @Override + public void setName(String name) { + this.name = name; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public void setDescription(String description) { + this.description = description; + } + + @Override + public boolean isPermanent() { + return permanent; + } + + @Override + public void setPermanent(boolean permanent) { + this.permanent = permanent; + } + + @Override + public Operation getOperation() { + return operation; + } + + @Override + public void setOperation(Operation operation) { + this.operation = (JpaOperation)operation; + } + + @Override + public Resource getResource() { + return resource; + } + + @Override + public void setResource(Resource resource) { + this.resource = (JpaResource)resource; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + JpaPermission that = (JpaPermission) o; + + return name.equals(that.name); + + } + + @Override + public int hashCode() { + return name.hashCode(); + } +} diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaResource.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaResource.java new file mode 100644 index 00000000..fc7ee777 --- /dev/null +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaResource.java @@ -0,0 +1,91 @@ +package org.apache.archiva.redback.rbac.jpa.model; + +/* + * 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.rbac.Resource; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import java.io.Serializable; + +/** + * Created by martin on 25.09.16. + */ +@Entity +@Table(name="SECURITY_RESOURCES") +public class JpaResource implements Resource, Serializable { + + @Id + @Column(name="IDENTIFIER") + private String identifier; + @Column(name="PATTERN") + private boolean pattern; + @Column(name="PERMANENT") + private boolean permanent; + + + @Override + public String getIdentifier() { + return identifier; + } + + @Override + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + @Override + public boolean isPattern() { + return pattern; + } + + @Override + public void setPattern(boolean pattern) { + this.pattern = pattern; + } + + @Override + public boolean isPermanent() { + return permanent; + } + + @Override + public void setPermanent(boolean permanent) { + this.permanent = permanent; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + JpaResource that = (JpaResource) o; + + return identifier.equals(that.identifier); + + } + + @Override + public int hashCode() { + return identifier.hashCode(); + } +} diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaRole.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaRole.java new file mode 100644 index 00000000..1f8a62c6 --- /dev/null +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaRole.java @@ -0,0 +1,172 @@ +package org.apache.archiva.redback.rbac.jpa.model; + +/* + * 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.rbac.AbstractRole; +import org.apache.archiva.redback.rbac.Permission; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by martin on 25.09.16. + */ +@Entity +@Table( + name="SECURITY_ROLES" +) +public class JpaRole extends AbstractRole implements Serializable { + + @Id + @Column(name="NAME") + private String name; + @Column(name="DESCRIPTION") + private String description; + @Column(name="ASSIGNABLE") + private boolean assignable; + @Column(name="PERMANENT") + private boolean permanent; + @ManyToMany(cascade = CascadeType.PERSIST) + @JoinTable( + name="SECURITY_ROLE_PERMISSION_MAP", + joinColumns={ @JoinColumn(name="NAME_OID", referencedColumnName="NAME") }, + inverseJoinColumns = { + @JoinColumn(name="NAME_EID",referencedColumnName = "NAME") + } + ) + List permissions = new ArrayList(); + + @ElementCollection + @CollectionTable( + name="SECURITY_ROLE_CHILDROLE_MAP", + joinColumns = { + @JoinColumn(name="NAME_OID",referencedColumnName = "NAME") + } + ) + List childRoleNames = new ArrayList(); + + + + @Override + public void addPermission(Permission permission) { + if (permission instanceof JpaPermission) { + this.permissions.add((JpaPermission) permission); + } + + } + + @Override + public void addChildRoleName(String name) { + this.childRoleNames.add(name); + } + + @Override + public List getChildRoleNames() { + return childRoleNames; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public String getName() { + return name; + } + + @Override + public List getPermissions() { + // Maybe better to create a new list? + return (List)(List)permissions; + } + + @Override + public boolean isAssignable() { + return assignable; + } + + @Override + public void removePermission(Permission permission) { + this.permissions.remove(permission); + } + + @Override + public void setAssignable(boolean assignable) { + this.assignable=assignable; + } + + @Override + public void setChildRoleNames(List names) { + this.childRoleNames.clear(); + this.childRoleNames.addAll(names); + } + + @Override + public void setDescription(String description) { + this.description=description; + + } + + @Override + public void setName(String name) { + this.name=name; + + } + + @Override + public void setPermissions(List permissions) { + this.permissions.clear(); + for (Permission p : permissions) { + if (p instanceof JpaPermission) { + permissions.add(p); + } + } + } + + @Override + public boolean isPermanent() { + return permanent; + } + + @Override + public void setPermanent(boolean permanent) { + this.permanent=permanent; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + + JpaRole jpaRole = (JpaRole) o; + + return name.equals(jpaRole.name); + + } + + @Override + public int hashCode() { + return name.hashCode(); + } +} diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaUserAssignment.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaUserAssignment.java new file mode 100644 index 00000000..39e0b2d3 --- /dev/null +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaUserAssignment.java @@ -0,0 +1,97 @@ +package org.apache.archiva.redback.rbac.jpa.model; + +/* + * 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.rbac.AbstractUserAssignment; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by Martin Stockhammer on 26.09.16. + */ +@Entity +@Table(name="SECURITY_USER_ASSIGNMENTS") +public class JpaUserAssignment extends AbstractUserAssignment implements Serializable { + + + @Id + @Column(name="PRINCIPAL") + private String principal; + @ElementCollection + @Column(name="STRING_ELE") + @CollectionTable( + name="SECURITY_USERASSIGNMENT_MAP", + joinColumns = { + @JoinColumn(name = "PRINCIPAL_OID", referencedColumnName = "PRINCIPAL") + } + ) + private List roleNames = new ArrayList(); + @Column(name="PERMANENT") + private boolean permanent = false; + + @Override + public String getPrincipal() { + return principal; + } + + @Override + public void setPrincipal(String principal) { + this.principal = principal; + } + + @Override + public List getRoleNames() { + return roleNames; + } + + @Override + public void setRoleNames(List roleNames) { + this.roleNames = roleNames; + } + + @Override + public boolean isPermanent() { + return permanent; + } + + @Override + public void setPermanent(boolean permanent) { + this.permanent = permanent; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + JpaUserAssignment that = (JpaUserAssignment) o; + + return principal.equals(that.principal); + + } + + @Override + public int hashCode() { + return principal.hashCode(); + } +} diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/test/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManagerTest.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/test/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManagerTest.java new file mode 100644 index 00000000..3c5bc9fa --- /dev/null +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/test/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManagerTest.java @@ -0,0 +1,132 @@ +package org.apache.archiva.redback.rbac.jpa; + +/* + * 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.common.jdo.test.StoreManagerDebug; +import org.apache.archiva.redback.rbac.RbacManagerException; +import org.apache.archiva.redback.tests.AbstractRbacManagerTestCase; +import org.junit.Before; +import org.springframework.test.annotation.DirtiesContext; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; +import java.io.InputStream; +import java.util.Properties; + +/** + * JdoRbacManagerTest: + * + * @author Jesse McConnell + * @author Joakim Erdfelt + */ +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) +public class JpaRbacManagerTest + extends AbstractRbacManagerTestCase +{ + + @Inject + @Named(value = "rbacManager#jpa") + JpaRbacManager rbacManager; + + public static int EVENTCOUNT = 2; + + @Override + public void assertEventCount() + { + assertEquals( EVENTCOUNT, eventTracker.initCount ); + } + + /** + * Creates a new RbacStore which contains no data. + */ + @Before + public void setUp() + throws Exception + { + + super.setUp(); + Properties props = new Properties(); + InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("test.properties"); + assert is!=null; + props.load(is); + is.close(); + EntityManagerFactory emf = Persistence.createEntityManagerFactory("redback-jpa",props); + + log.info("test setup"); + rbacManager.setEntityManager(emf.createEntityManager()); + super.setRbacManager(rbacManager); + assertNotNull(rbacManager); + log.info("injected rbac manager "+rbacManager); + + } + + + @Override + public void testGetAssignedRoles() + throws RbacManagerException + { + super.testGetAssignedRoles(); + } + + @Override + public void testGetAssignedPermissionsDeep() + throws RbacManagerException + { + super.testGetAssignedPermissionsDeep(); + } + + @Override + protected void afterSetup() + { + super.afterSetup(); + } + + @Override + public void testLargeApplicationInit() + throws RbacManagerException + { + this.clearCache(); + super.testLargeApplicationInit(); + } + + @Override + public void testGetRolesDeep() + throws RbacManagerException + { + this.clearCache(); + super.testGetRolesDeep(); + } + + + @Override + public void testStoreInitialization() + throws Exception + { + this.clearCache(); + rbacManager.eraseDatabase(); + eventTracker.rbacInit( true ); + super.testStoreInitialization(); + assertEquals( EVENTCOUNT, eventTracker.initCount ); + } + + +} diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/test/resources/spring-context.xml b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/test/resources/spring-context.xml new file mode 100644 index 00000000..abee0b5a --- /dev/null +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/test/resources/spring-context.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/test/resources/test.properties b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/test/resources/test.properties new file mode 100644 index 00000000..df848c45 --- /dev/null +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/test/resources/test.properties @@ -0,0 +1,22 @@ +# 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. +openjpa.ConnectionURL=jdbc:hsqldb:mem:reback-jpa +openjpa.ConnectionDriverName=org.hsqldb.jdbcDriver +openjpa.ConnectionUserName=sa +openjpa.ConnectionPassword= +openjp.Log=DefaultLevel=WARN,Tool=INFO +openjpa.jdbc.SynchronizeMappings=buildSchema(ForeignKeys=true) \ No newline at end of file diff --git a/redback-users/redback-users-providers/pom.xml b/redback-users/redback-users-providers/pom.xml index 9ddab02c..4a906482 100644 --- a/redback-users/redback-users-providers/pom.xml +++ b/redback-users/redback-users-providers/pom.xml @@ -39,5 +39,6 @@ redback-users-jdo redback-users-ldap redback-users-configurable + redback-users-jpa diff --git a/redback-users/redback-users-providers/redback-users-jpa/pom.xml b/redback-users/redback-users-providers/redback-users-jpa/pom.xml new file mode 100644 index 00000000..2606b712 --- /dev/null +++ b/redback-users/redback-users-providers/redback-users-jpa/pom.xml @@ -0,0 +1,68 @@ + + + + + redback-users-providers + org.apache.archiva.redback + 2.5-SNAPSHOT + + 4.0.0 + + redback-users-jpa + jar + Redback :: Users Provider :: JPA + + + + org.springframework + spring-context-support + + + javax.annotation + jsr250-api + + + org.apache.archiva.redback + redback-policy + + + org.apache.archiva.redback + redback-common-jpa + + + org.apache.openjpa + openjpa + ${openjpa.version} + + + + org.hsqldb + hsqldb + test + + + org.apache.archiva.redback + redback-users-tests + test + + + \ No newline at end of file diff --git a/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/JpaUserManager.java b/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/JpaUserManager.java new file mode 100644 index 00000000..c4c83f60 --- /dev/null +++ b/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/JpaUserManager.java @@ -0,0 +1,307 @@ +package org.apache.archiva.redback.users.jpa; + +/* + * 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.policy.UserSecurityPolicy; +import org.apache.archiva.redback.users.*; +import org.apache.archiva.redback.users.jpa.model.JpaUser; +import org.apache.commons.lang.StringUtils; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import javax.persistence.*; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; + +/** + * Created by martin on 20.09.16. + */ +@org.springframework.stereotype.Service("userManager#jpa") +public class JpaUserManager extends AbstractUserManager { + + + @PersistenceContext(unitName = "redback-jpa") + EntityManager em; + + @Inject + private UserSecurityPolicy userSecurityPolicy; + + // JpaUserManager is a singleton and initialization should be thread safe + private AtomicBoolean initialized = new AtomicBoolean(false); + + + public void setEntityManager(EntityManager em) { + this.em = em; + } + + @Override + public boolean isReadOnly() { + return false; + } + + @Override + public String getId() { + return "jpa"; + } + + private EntityManager getEm() { + if (initialized.compareAndSet(false,true)) { + Query q = em.createQuery("SELECT COUNT(u.username) FROM JpaUser u"); + boolean dbInit = q.getFirstResult()==0; + fireUserManagerInit(dbInit); + } + return em; + } + + + @Override + public User createUser(String username, String fullName, String emailAddress) throws UserManagerException { + + JpaUser user = new JpaUser(); + user.setUsername(username); + user.setFullName(fullName); + user.setEmail(emailAddress); + return user; + } + + @Override + public UserQuery createUserQuery() { + return new JpaUserQuery(); + } + + @Override + public List getUsers() throws UserManagerException { + final EntityManager em = getEm(); + Query q= em.createQuery("SELECT x from JpaUser x"); + return q.getResultList(); + } + + @Override + public List getUsers(boolean orderAscending) throws UserManagerException { + final EntityManager em = getEm(); + final String orderFlag = orderAscending ? "ASC" : "DESC"; + Query q = em.createQuery("SELECT u FROM JpaUser u ORDER BY u.username "+orderFlag); + return q.getResultList(); + } + + @Override + public User addUser(User user) throws UserManagerException { + EntityManager em = getEm(); + if ( !( user instanceof JpaUser ) ) + { + throw new UserManagerException( "Unable to Add User. User object " + user.getClass().getName() + + " is not an instance of " + JpaUser.class.getName() ); + } + + if ( StringUtils.isEmpty( user.getUsername() ) ) + { + throw new IllegalStateException( + Messages.getString( "user.manager.cannot.add.user.without.username" ) ); //$NON-NLS-1$ + } + + userSecurityPolicy.extensionChangePassword( user ); + + fireUserManagerUserAdded( user ); + + // TODO: find a better solution + // workaround for avoiding the admin from providing another password on the next login after the + // admin account has been created + // extensionChangePassword by default sets the password change status to false + if ( "admin".equals( user.getUsername() ) ) + { + user.setPasswordChangeRequired( false ); + } + else + { + user.setPasswordChangeRequired( true ); + } + em.getTransaction().begin(); + em.persist((JpaUser)user); + em.getTransaction().commit(); + return user; + } + + @Override + public User updateUser(User user) throws UserNotFoundException, UserManagerException { + return updateUser(user, false); + } + + @Override + public User findUser(String username) throws UserNotFoundException, UserManagerException { + if (username==null) { + throw new UserNotFoundException("Username was "); + } + final EntityManager em = getEm(); + TypedQuery q = em.createQuery("SELECT u FROM JpaUser u WHERE LOWER(u.username)=:uname", JpaUser.class); + q.setParameter("uname",username.toLowerCase()); + User result; + try { + result = q.getSingleResult(); + } catch (NoResultException ex ) { + throw new UserNotFoundException(ex); + } + return result; + } + + @Override + public User findUser(String username, boolean useCache) throws UserNotFoundException, UserManagerException { + return findUser(username); + } + + @Override + public List findUsersByUsernameKey(String usernameKey, boolean orderAscending) throws UserManagerException { + return findUsers("username",usernameKey,"username",orderAscending); + } + + @Override + public List findUsersByFullNameKey(String fullNameKey, boolean orderAscending) throws UserManagerException { + return findUsers("fullName",fullNameKey,"username",orderAscending); + } + + @Override + public List findUsersByEmailKey(String emailKey, boolean orderAscending) throws UserManagerException { + return findUsers("email",emailKey,"username", orderAscending); + } + + @Override + public List findUsersByQuery(final UserQuery queryParam) throws UserManagerException { + final EntityManager em = getEm(); + final JpaUserQuery query = (JpaUserQuery)queryParam; + String orderByAttribute = ""; + if (UserQuery.ORDER_BY_EMAIL.equals(query.getOrderBy())) { + orderByAttribute="email"; + } else if (UserQuery.ORDER_BY_FULLNAME.equals(query.getOrderBy())) { + orderByAttribute="fullName"; + } else if (UserQuery.ORDER_BY_USERNAME.equals(query.getOrderBy())) { + orderByAttribute="username"; + } else { + throw new IllegalArgumentException("Unknown order attribute "+query.getOrderBy()); + } + StringBuilder sb = new StringBuilder("SELECT u FROM JpaUser u "); + if (query.hasUsername()||query.hasFullName()||query.hasEmail()) { + sb.append("WHERE "); + } + boolean checkBefore = false; + if (query.hasUsername()) { + sb.append("LOWER(u.username) LIKE :username "); + checkBefore=true; + } + if (query.hasEmail()) { + if (checkBefore) { + sb.append("AND "); + } + checkBefore=true; + sb.append("LOWER(u.email) LIKE :email "); + } + if (query.hasFullName()) { + if (checkBefore) { + sb.append("AND "); + } + sb.append("LOWER(u.fullName) LIKE :fullname "); + } + if (query.getOrderBy()!=null && !"".equals(query.getOrderBy())) { + sb.append("ORDER BY u.").append(orderByAttribute).append(query.isAscending() ? " ASC" : " DESC"); + } + TypedQuery q = em.createQuery(sb.toString(), User.class); + if (query.hasUsername()) { + q.setParameter("username", "%"+query.getUsername().toLowerCase()+"%"); + } + if (query.hasEmail()) { + q.setParameter("email", "%"+query.getEmail().toLowerCase()+"%"); + } + if (query.hasFullName()) { + q.setParameter("fullname", "%"+query.getFullName().toLowerCase()+"%"); + } + q.setFirstResult((int)query.getFirstResult()).setMaxResults((int)query.getMaxResults()); + return q.getResultList(); + } + + private List findUsers(final String attribute, final String pattern, + final String orderAttribute, final boolean orderAscending) { + final EntityManager em = getEm(); + StringBuilder sb = new StringBuilder("SELECT u FROM JpaUser u WHERE LOWER(u."); + sb.append(attribute).append(") LIKE :patternvalue ORDER BY u.").append(orderAttribute); + sb.append(orderAscending ? " ASC" : " DESC"); + TypedQuery q = em.createQuery(sb.toString(),User.class); + q.setParameter("patternvalue","%"+pattern.toLowerCase()+"%"); + return q.getResultList(); + } + + @Override + public boolean userExists(String principal) throws UserManagerException { + EntityManager em = getEm(); + JpaUser user = em.find(JpaUser.class, principal); + return user != null; + } + + + + @Override + public void deleteUser(String username) throws UserNotFoundException, UserManagerException { + final EntityManager em = getEm(); + User u = findUser(username); + if (u.isPermanent()) { + throw new PermanentUserException("User "+username+" cannot be deleted"); + } + em.getTransaction().begin(); + em.remove(u); + em.getTransaction().commit(); + fireUserManagerUserRemoved(u); + } + + @Override + public void addUserUnchecked(User user) throws UserManagerException { + + } + + @Override + public void eraseDatabase() { + EntityManager em = getEm(); + em.getTransaction().begin(); + Query q = em.createQuery("DELETE FROM JpaUser u"); + q.executeUpdate(); + em.getTransaction().commit(); + } + + @Override + public User updateUser(User user, boolean passwordChangeRequired) throws UserNotFoundException, UserManagerException { + if ( StringUtils.isNotEmpty( user.getPassword() ) ) + { + userSecurityPolicy.extensionChangePassword( user, passwordChangeRequired ); + } + final EntityManager em = getEm(); + em.getTransaction().begin(); + em.persist((JpaUser)user); + em.getTransaction().commit(); + fireUserManagerUserUpdated(user); + return user; + } + + @Override + public String getDescriptionKey() { + return null; + } + + + + +} diff --git a/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/JpaUserQuery.java b/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/JpaUserQuery.java new file mode 100644 index 00000000..d48a59ce --- /dev/null +++ b/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/JpaUserQuery.java @@ -0,0 +1,123 @@ +package org.apache.archiva.redback.users.jpa; + +/* + * 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.users.UserQuery; + +import java.util.Arrays; + +/** + * Created by martin on 23.09.16. + */ +public class JpaUserQuery implements UserQuery { + + private String username; + private String email; + private String fullName; + private long firstResult=0; + private long maxResults=Integer.MAX_VALUE; + private boolean ascending=true; + + private String orderBy="username"; + + @Override + public String getUsername() { + return username; + } + + @Override + public void setUsername(String username) { + this.username = username; + } + + public boolean hasUsername() { + return username != null && !"".equals(username); + } + + @Override + public String getEmail() { + return email; + } + + @Override + public void setEmail(String email) { + this.email = email; + } + + public boolean hasEmail() { + return email!=null && !"".equals(email); + } + + @Override + public String getFullName() { + return fullName; + } + + @Override + public void setFullName(String fullName) { + this.fullName = fullName; + } + + public boolean hasFullName() { + return fullName!=null && !"".equals(fullName); + } + + @Override + public long getFirstResult() { + return firstResult; + } + + public void setFirstResult(int firstResult) { + this.firstResult = firstResult; + } + + @Override + public long getMaxResults() { + return maxResults; + } + + public void setMaxResults(int maxResults) { + this.maxResults = maxResults; + } + + @Override + public boolean isAscending() { + return ascending; + } + + @Override + public void setAscending(boolean ascending) { + this.ascending = ascending; + } + + + @Override + public String getOrderBy() { + return orderBy; + } + + @Override + public void setOrderBy(String orderBy) { + if (!UserQuery.ALLOWED_ORDER_FIELDS.contains(orderBy)) { + throw new IllegalArgumentException("Order attribute not allowed: "+orderBy); + } + this.orderBy = orderBy; + } +} diff --git a/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/model/JpaUser.java b/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/model/JpaUser.java new file mode 100644 index 00000000..04f441e0 --- /dev/null +++ b/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/model/JpaUser.java @@ -0,0 +1,206 @@ +package org.apache.archiva.redback.users.jpa.model; + +/* + * 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 javax.persistence.ElementCollection; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * Created by martin on 20.09.16. + */ +@Entity +@Table(name="JDOUSER") +public class JpaUser implements org.apache.archiva.redback.users.User { + + @Id + private String username; + + private String fullName; + private String email; + private String encodedPassword; + private Date lastPasswordChange; + @ElementCollection + private List previousEncodedPasswords = new ArrayList(); + private boolean permanent; + private boolean locked; + private boolean passwordChangeRequired; + private boolean validated; + private int countFailedLoginAttempts; + private Date accountCreationDate; + private Date lastLoginDate; + private String rawPassword; + + + @Override + public String getUsername() { + return username; + } + + @Override + public void setUsername(String name) { + this.username = name; + } + + @Override + public String getFullName() { + return fullName; + } + + @Override + public void setFullName(String name) { + this.fullName = name; + } + + @Override + public String getEmail() { + return email; + } + + @Override + public void setEmail(String address) { + this.email = address; + } + + @Override + public String getPassword() { + return rawPassword; + } + + @Override + public void setPassword(String rawPassword) { + this.rawPassword = rawPassword; + } + + @Override + public String getEncodedPassword() { + return encodedPassword; + } + + @Override + public void setEncodedPassword(String encodedPassword) { + this.encodedPassword = encodedPassword; + } + + @Override + public Date getLastPasswordChange() { + return lastPasswordChange; + } + + @Override + public void setLastPasswordChange(Date passwordChangeDate) { + this.lastPasswordChange = lastPasswordChange; + } + + @Override + public List getPreviousEncodedPasswords() { + return previousEncodedPasswords; + } + + @Override + public void setPreviousEncodedPasswords(List encodedPasswordList) { + this.previousEncodedPasswords.clear(); + this.previousEncodedPasswords.addAll(encodedPasswordList); + } + + @Override + public void addPreviousEncodedPassword(String encodedPassword) { + this.previousEncodedPasswords.add(encodedPassword); + } + + @Override + public boolean isPermanent() { + return permanent; + } + + @Override + public void setPermanent(boolean permanent) { + this.permanent = permanent; + } + + @Override + public boolean isLocked() { + return locked; + } + + @Override + public void setLocked(boolean locked) { + this.locked = locked; + } + + @Override + public boolean isPasswordChangeRequired() { + return passwordChangeRequired; + } + + @Override + public void setPasswordChangeRequired(boolean changeRequired) { + this.passwordChangeRequired = changeRequired; + } + + @Override + public boolean isValidated() { + return validated; + } + + @Override + public void setValidated(boolean valid) { + this.validated = valid; + } + + @Override + public int getCountFailedLoginAttempts() { + return countFailedLoginAttempts; + } + + @Override + public void setCountFailedLoginAttempts(int count) { + this.countFailedLoginAttempts = count; + } + + @Override + public Date getAccountCreationDate() { + return accountCreationDate; + } + + @Override + public void setAccountCreationDate(Date date) { + this.accountCreationDate = date; + } + + @Override + public Date getLastLoginDate() { + return lastLoginDate; + } + + @Override + public void setLastLoginDate(Date date) { + this.lastLoginDate = date; + } + + @Override + public String getUserManagerId() { + return null; + } +} diff --git a/redback-users/redback-users-providers/redback-users-jpa/src/test/java/org/apache/archiva/redback/users/jpa/JpaUserManagerTest.java b/redback-users/redback-users-providers/redback-users-jpa/src/test/java/org/apache/archiva/redback/users/jpa/JpaUserManagerTest.java new file mode 100644 index 00000000..4556755f --- /dev/null +++ b/redback-users/redback-users-providers/redback-users-jpa/src/test/java/org/apache/archiva/redback/users/jpa/JpaUserManagerTest.java @@ -0,0 +1,86 @@ +package org.apache.archiva.redback.users.jpa; + +/* + * 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.policy.UserSecurityPolicy; +import org.apache.archiva.redback.users.User; +import org.apache.archiva.redback.users.UserManager; +import org.apache.archiva.redback.users.provider.test.AbstractUserManagerTestCase; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Before; +import org.junit.Test; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +/** + * Created by martin on 21.09.16. + */ + +public class JpaUserManagerTest extends AbstractUserManagerTestCase { + + Log log = LogFactory.getLog(JpaUserManagerTest.class); + + @Inject + @Named("userManager#jpa") + JpaUserManager jpaUserManager; + + + @Inject + private UserSecurityPolicy securityPolicy; + + @Before + @Override + public void setUp() throws Exception { + + super.setUp(); + Properties props = new Properties(); + InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("test.properties"); + assert is!=null; + props.load(is); + is.close(); + EntityManagerFactory emf = Persistence.createEntityManagerFactory("redback-jpa",props); + + log.info("test setup"); + jpaUserManager.setEntityManager(emf.createEntityManager()); + super.setUserManager(jpaUserManager); + assertNotNull(jpaUserManager); + log.info("injected usermanager "+jpaUserManager); + + // create the factory defined by the "openjpa" entity-manager entry + + } + + @Test + public void testInit() { + jpaUserManager.initialize(); + } + + + + +} diff --git a/redback-users/redback-users-providers/redback-users-jpa/src/test/resources/spring-context.xml b/redback-users/redback-users-providers/redback-users-jpa/src/test/resources/spring-context.xml new file mode 100644 index 00000000..4d7802ed --- /dev/null +++ b/redback-users/redback-users-providers/redback-users-jpa/src/test/resources/spring-context.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + ]]> + + + + + + + \ No newline at end of file diff --git a/redback-users/redback-users-providers/redback-users-jpa/src/test/resources/test.properties b/redback-users/redback-users-providers/redback-users-jpa/src/test/resources/test.properties new file mode 100644 index 00000000..df848c45 --- /dev/null +++ b/redback-users/redback-users-providers/redback-users-jpa/src/test/resources/test.properties @@ -0,0 +1,22 @@ +# 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. +openjpa.ConnectionURL=jdbc:hsqldb:mem:reback-jpa +openjpa.ConnectionDriverName=org.hsqldb.jdbcDriver +openjpa.ConnectionUserName=sa +openjpa.ConnectionPassword= +openjp.Log=DefaultLevel=WARN,Tool=INFO +openjpa.jdbc.SynchronizeMappings=buildSchema(ForeignKeys=true) \ No newline at end of file diff --git a/redback-users/redback-users-tests/src/main/java/org/apache/archiva/redback/users/provider/test/AbstractUserManagerTestCase.java b/redback-users/redback-users-tests/src/main/java/org/apache/archiva/redback/users/provider/test/AbstractUserManagerTestCase.java index 6da8ac8d..d293bda5 100644 --- a/redback-users/redback-users-tests/src/main/java/org/apache/archiva/redback/users/provider/test/AbstractUserManagerTestCase.java +++ b/redback-users/redback-users-tests/src/main/java/org/apache/archiva/redback/users/provider/test/AbstractUserManagerTestCase.java @@ -97,10 +97,12 @@ public class AbstractUserManagerTestCase throws UserManagerException { + assertNotNull(userManager); getUserManager().eraseDatabase(); getEventTracker().userManagerInit( true ); assertNotNull( getUserManager() ); + assertNotNull(userManager.getUsers()); assertEquals( "New UserManager should contain no users. " + userManager.getUsers(), 0, userManager.getUsers().size() ); } From 9e09e8f0cffcfbe419780e943304e3d2dbd4947a Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Fri, 30 Sep 2016 22:36:39 +0200 Subject: [PATCH 02/30] Removing datasource from test persistence config --- .../src/main/resources/META-INF/persistence-hsqldb.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence-hsqldb.xml b/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence-hsqldb.xml index a78444e0..6f37758b 100644 --- a/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence-hsqldb.xml +++ b/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence-hsqldb.xml @@ -20,7 +20,6 @@ org.apache.openjpa.persistence.PersistenceProviderImpl - java:comp/env/jdbc/redbackjpa org.apache.archiva.redback.users.jpa.model.JpaUser org.apache.archiva.redback.rbac.jpa.model.JpaOperation org.apache.archiva.redback.rbac.jpa.model.JpaResource From f3bcedfdf824fc3d90dc35b51b7a863ebd421f49 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Fri, 30 Sep 2016 22:37:22 +0200 Subject: [PATCH 03/30] Setting database schema names from JDO --- .../redback/users/jpa/JpaUserManager.java | 35 ++++++++++++++++--- .../redback/users/jpa/model/JpaUser.java | 23 +++++++++++- .../src/main/resources/spring-context.xml | 31 ++++++++++++++++ .../redback/users/jpa/JpaUserManagerTest.java | 1 - 4 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 redback-users/redback-users-providers/redback-users-jpa/src/main/resources/spring-context.xml diff --git a/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/JpaUserManager.java b/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/JpaUserManager.java index c4c83f60..448552d9 100644 --- a/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/JpaUserManager.java +++ b/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/JpaUserManager.java @@ -75,7 +75,6 @@ public class JpaUserManager extends AbstractUserManager { @Override public User createUser(String username, String fullName, String emailAddress) throws UserManagerException { - JpaUser user = new JpaUser(); user.setUsername(username); user.setFullName(fullName); @@ -270,6 +269,27 @@ public class JpaUserManager extends AbstractUserManager { @Override public void addUserUnchecked(User user) throws UserManagerException { + log.info("addUserUnchecked "+user.getUsername()); + if ( !( user instanceof JpaUser ) ) + { + throw new UserManagerException( "Unable to Add User. User object " + user.getClass().getName() + + " is not an instance of " + JpaUser.class.getName() ); + } + + if ( org.codehaus.plexus.util.StringUtils.isEmpty( user.getUsername() ) ) + { + throw new IllegalStateException( + Messages.getString( "user.manager.cannot.add.user.without.username" ) ); //$NON-NLS-1$ + } + + em.getTransaction().begin(); + TypedQuery q = em.createQuery("SELECT u FROM JpaUser u", JpaUser.class); + for (JpaUser u : q.getResultList()) { + log.info("USER FOUND: "+u.getUsername()); + } + log.info("NEW USER "+user.getUsername()); + em.persist((JpaUser)user); + em.getTransaction().commit(); } @@ -277,9 +297,16 @@ public class JpaUserManager extends AbstractUserManager { public void eraseDatabase() { EntityManager em = getEm(); em.getTransaction().begin(); - Query q = em.createQuery("DELETE FROM JpaUser u"); - q.executeUpdate(); + TypedQuery q = em.createQuery("SELECT u FROM JpaUser u", JpaUser.class); + for (JpaUser u : q.getResultList()) { + u.getPreviousEncodedPasswords().clear(); + } + em.flush(); + Query qd = em.createQuery("DELETE FROM JpaUser u"); + qd.executeUpdate(); em.getTransaction().commit(); + em.clear(); + } @Override @@ -298,7 +325,7 @@ public class JpaUserManager extends AbstractUserManager { @Override public String getDescriptionKey() { - return null; + return "archiva.redback.usermanager.jpa"; } diff --git a/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/model/JpaUser.java b/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/model/JpaUser.java index 04f441e0..cfdaa4e4 100644 --- a/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/model/JpaUser.java +++ b/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/model/JpaUser.java @@ -19,9 +19,13 @@ package org.apache.archiva.redback.users.jpa.model; * under the License. */ +import javax.persistence.CollectionTable; +import javax.persistence.Column; import javax.persistence.ElementCollection; import javax.persistence.Entity; import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OrderColumn; import javax.persistence.Table; import java.util.ArrayList; import java.util.Date; @@ -35,21 +39,38 @@ import java.util.List; public class JpaUser implements org.apache.archiva.redback.users.User { @Id + @Column(name="USERNAME") private String username; - + @Column(name="FULL_NAME") private String fullName; + @Column(name="EMAIL") private String email; + @Column(name="ENCODED_PASSWORD") private String encodedPassword; + @Column(name="LAST_PASSWORD_CHANGE") private Date lastPasswordChange; @ElementCollection + @OrderColumn(name="INTEGER_IDX") + @Column(name="STRING_ELE") + @CollectionTable(name="JDOUSER_PREVIOUSENCODEDPASSWORDS", + joinColumns = @JoinColumn(name = "USERNAME_OID", referencedColumnName = "USERNAME") + ) private List previousEncodedPasswords = new ArrayList(); + @Column(name="PERMANENT") private boolean permanent; + @Column(name="LOCKED") private boolean locked; + @Column(name="PASSWORD_CHANGE_REQUIRED") private boolean passwordChangeRequired; + @Column(name="VALIDATED") private boolean validated; + @Column(name="COUNT_FAILED_LOGIN_ATTEMPTS") private int countFailedLoginAttempts; + @Column(name="ACCOUNT_CREATION_DATE") private Date accountCreationDate; + @Column(name="LAST_LOGIN_DATE") private Date lastLoginDate; + @Column(name="USER_PASSSWORD") private String rawPassword; diff --git a/redback-users/redback-users-providers/redback-users-jpa/src/main/resources/spring-context.xml b/redback-users/redback-users-providers/redback-users-jpa/src/main/resources/spring-context.xml new file mode 100644 index 00000000..a56a2188 --- /dev/null +++ b/redback-users/redback-users-providers/redback-users-jpa/src/main/resources/spring-context.xml @@ -0,0 +1,31 @@ + + + + + + + + \ No newline at end of file diff --git a/redback-users/redback-users-providers/redback-users-jpa/src/test/java/org/apache/archiva/redback/users/jpa/JpaUserManagerTest.java b/redback-users/redback-users-providers/redback-users-jpa/src/test/java/org/apache/archiva/redback/users/jpa/JpaUserManagerTest.java index 4556755f..75cda6da 100644 --- a/redback-users/redback-users-providers/redback-users-jpa/src/test/java/org/apache/archiva/redback/users/jpa/JpaUserManagerTest.java +++ b/redback-users/redback-users-providers/redback-users-jpa/src/test/java/org/apache/archiva/redback/users/jpa/JpaUserManagerTest.java @@ -65,7 +65,6 @@ public class JpaUserManagerTest extends AbstractUserManagerTestCase { is.close(); EntityManagerFactory emf = Persistence.createEntityManagerFactory("redback-jpa",props); - log.info("test setup"); jpaUserManager.setEntityManager(emf.createEntityManager()); super.setUserManager(jpaUserManager); assertNotNull(jpaUserManager); From 30c3441cd4ed3083d9469a81fed47ced2ad9bdfb Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Fri, 30 Sep 2016 22:38:08 +0200 Subject: [PATCH 04/30] Adding order columns to persistence schema --- .../archiva/redback/rbac/jpa/JpaRbacManager.java | 1 + .../archiva/redback/rbac/jpa/model/JpaRole.java | 3 +++ .../redback/rbac/jpa/model/JpaUserAssignment.java | 12 ++++++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java index ced9104b..80580e45 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java @@ -425,6 +425,7 @@ public class JpaRbacManager extends AbstractRBACManager { em.remove(ua); } em.getTransaction().commit(); + em.clear(); } diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaRole.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaRole.java index 1f8a62c6..98c4bf2d 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaRole.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaRole.java @@ -21,6 +21,7 @@ package org.apache.archiva.redback.rbac.jpa.model; import org.apache.archiva.redback.rbac.AbstractRole; import org.apache.archiva.redback.rbac.Permission; +import org.springframework.core.annotation.Order; import javax.persistence.*; import java.io.Serializable; @@ -46,6 +47,7 @@ public class JpaRole extends AbstractRole implements Serializable { @Column(name="PERMANENT") private boolean permanent; @ManyToMany(cascade = CascadeType.PERSIST) + @OrderColumn(name="INTEGER_IDX") @JoinTable( name="SECURITY_ROLE_PERMISSION_MAP", joinColumns={ @JoinColumn(name="NAME_OID", referencedColumnName="NAME") }, @@ -56,6 +58,7 @@ public class JpaRole extends AbstractRole implements Serializable { List permissions = new ArrayList(); @ElementCollection + @OrderColumn(name="INTEGER_IDX") @CollectionTable( name="SECURITY_ROLE_CHILDROLE_MAP", joinColumns = { diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaUserAssignment.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaUserAssignment.java index 39e0b2d3..65ed8af0 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaUserAssignment.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaUserAssignment.java @@ -21,7 +21,14 @@ package org.apache.archiva.redback.rbac.jpa.model; import org.apache.archiva.redback.rbac.AbstractUserAssignment; -import javax.persistence.*; +import javax.persistence.CollectionTable; +import javax.persistence.Column; +import javax.persistence.ElementCollection; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OrderColumn; +import javax.persistence.Table; import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -39,8 +46,9 @@ public class JpaUserAssignment extends AbstractUserAssignment implements Seriali private String principal; @ElementCollection @Column(name="STRING_ELE") + @OrderColumn(name="INTEGER_IDX") @CollectionTable( - name="SECURITY_USERASSIGNMENT_MAP", + name="SECURITY_USERASSIGNMENT_ROLENAMES", joinColumns = { @JoinColumn(name = "PRINCIPAL_OID", referencedColumnName = "PRINCIPAL") } From 4586b826d98e966908d45d69479fd119b791d894 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Sun, 2 Oct 2016 19:25:20 +0200 Subject: [PATCH 05/30] Fixing path of spring context file --- .../src/main/resources/{ => META-INF}/spring-context.xml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename redback-users/redback-users-providers/redback-users-jpa/src/main/resources/{ => META-INF}/spring-context.xml (100%) diff --git a/redback-users/redback-users-providers/redback-users-jpa/src/main/resources/spring-context.xml b/redback-users/redback-users-providers/redback-users-jpa/src/main/resources/META-INF/spring-context.xml similarity index 100% rename from redback-users/redback-users-providers/redback-users-jpa/src/main/resources/spring-context.xml rename to redback-users/redback-users-providers/redback-users-jpa/src/main/resources/META-INF/spring-context.xml From ac89b6bb2db684760bd5581803c584a48f32f4e7 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Sun, 2 Oct 2016 20:14:10 +0200 Subject: [PATCH 06/30] Adding final flag to jpa implementations --- .../org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java | 5 ++++- .../apache/archiva/redback/users/jpa/JpaUserManager.java | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java index 80580e45..184df40e 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java @@ -449,5 +449,8 @@ public class JpaRbacManager extends AbstractRBACManager { return em; } - + @Override + public boolean isFinalImplementation() { + return true; + } } diff --git a/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/JpaUserManager.java b/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/JpaUserManager.java index 448552d9..33fa7b6d 100644 --- a/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/JpaUserManager.java +++ b/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/JpaUserManager.java @@ -329,6 +329,8 @@ public class JpaUserManager extends AbstractUserManager { } - - + @Override + public boolean isFinalImplementation() { + return true; + } } From f8ee2af82544524942e63d46be65ccd108e1f9d6 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Sun, 2 Oct 2016 20:14:34 +0200 Subject: [PATCH 07/30] Adding explicit dependencies for JPA user/rbac implementations --- redback-integrations/redback-common-integrations/pom.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/redback-integrations/redback-common-integrations/pom.xml b/redback-integrations/redback-common-integrations/pom.xml index 34921ce0..656dcf2a 100644 --- a/redback-integrations/redback-common-integrations/pom.xml +++ b/redback-integrations/redback-common-integrations/pom.xml @@ -81,6 +81,14 @@ org.apache.archiva.redback redback-users-ldap + + org.apache.archiva.redback + redback-users-jpa + + + org.apache.archiva.redback + redback-rbac-jpa + org.apache.archiva.redback redback-users-configurable From d785f13635e112ea2e898eacd7795297d86ae898 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Sun, 2 Oct 2016 20:15:26 +0200 Subject: [PATCH 08/30] Adding spring context for rbac module --- .../resources/META-INF/spring-context.xml | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/resources/META-INF/spring-context.xml diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/resources/META-INF/spring-context.xml b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/resources/META-INF/spring-context.xml new file mode 100644 index 00000000..937e21dd --- /dev/null +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/resources/META-INF/spring-context.xml @@ -0,0 +1,30 @@ + + + + + + + \ No newline at end of file From e217190250560c62b9d5c1cefcf236d9cdf6e111 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Sun, 2 Oct 2016 20:15:49 +0200 Subject: [PATCH 09/30] Adding version for dependencies --- pom.xml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pom.xml b/pom.xml index 3e218ee0..975be68e 100644 --- a/pom.xml +++ b/pom.xml @@ -221,6 +221,11 @@ redback-users-jdo ${project.version} + + org.apache.archiva.redback + redback-users-jpa + ${project.version} + org.apache.archiva.redback redback-users-memory @@ -276,6 +281,11 @@ redback-rbac-jdo ${project.version} + + org.apache.archiva.redback + redback-rbac-jpa + ${project.version} + org.apache.archiva.redback redback-rbac-role-manager From 7e83bebcec58429d9eb3ae9573280db9676a2cf7 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Mon, 3 Oct 2016 19:36:13 +0200 Subject: [PATCH 10/30] Adding flag for authenticator to avoid autowiring exceptions Adds a isValid() method to the authenticator to avoid exceptions during initialization. --- .../authentication/AbstractAuthenticator.java | 8 +++++++- .../redback/authentication/Authenticator.java | 2 ++ .../DefaultAuthenticationManager.java | 2 +- .../authentication/ldap/LdapBindAuthenticator.java | 5 +++++ .../ConfigurableLdapConnectionFactory.java | 13 ++++++++++++- .../ldap/connection/LdapConnectionFactory.java | 2 ++ 6 files changed, 29 insertions(+), 3 deletions(-) diff --git a/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/AbstractAuthenticator.java b/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/AbstractAuthenticator.java index 1c80bc3c..80d1918f 100644 --- a/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/AbstractAuthenticator.java +++ b/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/AbstractAuthenticator.java @@ -24,9 +24,15 @@ package org.apache.archiva.redback.authentication; public abstract class AbstractAuthenticator implements Authenticator { + protected boolean valid = false; + public void initialize() throws AuthenticationException { - // no op + valid = true; + } + + public boolean isValid() { + return valid; } } diff --git a/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/Authenticator.java b/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/Authenticator.java index 6efe11ca..ce997573 100644 --- a/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/Authenticator.java +++ b/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/Authenticator.java @@ -38,4 +38,6 @@ public interface Authenticator throws AccountLockedException, AuthenticationException, MustChangePasswordException; void initialize() throws AuthenticationException; + + boolean isValid(); } diff --git a/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/DefaultAuthenticationManager.java b/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/DefaultAuthenticationManager.java index d5342bff..bda32762 100644 --- a/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/DefaultAuthenticationManager.java +++ b/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/DefaultAuthenticationManager.java @@ -92,7 +92,7 @@ public class DefaultAuthenticationManager List authnResultErrors = new ArrayList(); for ( Authenticator authenticator : authenticators ) { - if ( authenticator.supportsDataSource( source ) ) + if ( authenticator.isValid() && authenticator.supportsDataSource( source ) ) { AuthenticationResult authResult = authenticator.authenticate( source ); List authenticationFailureCauses = diff --git a/redback-authentication/redback-authentication-providers/redback-authentication-ldap/src/main/java/org/apache/archiva/redback/authentication/ldap/LdapBindAuthenticator.java b/redback-authentication/redback-authentication-providers/redback-authentication-ldap/src/main/java/org/apache/archiva/redback/authentication/ldap/LdapBindAuthenticator.java index 648b2f9b..fedae347 100644 --- a/redback-authentication/redback-authentication-providers/redback-authentication-ldap/src/main/java/org/apache/archiva/redback/authentication/ldap/LdapBindAuthenticator.java +++ b/redback-authentication/redback-authentication-providers/redback-authentication-ldap/src/main/java/org/apache/archiva/redback/authentication/ldap/LdapBindAuthenticator.java @@ -208,4 +208,9 @@ public class LdapBindAuthenticator log.warn( "skip exception closing naming search result {}", e.getMessage() ); } } + + @Override + public boolean isValid() { + return connectionFactory.isValid(); + } } diff --git a/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/ConfigurableLdapConnectionFactory.java b/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/ConfigurableLdapConnectionFactory.java index 4aab487d..2340cc5e 100644 --- a/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/ConfigurableLdapConnectionFactory.java +++ b/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/ConfigurableLdapConnectionFactory.java @@ -21,6 +21,8 @@ package org.apache.archiva.redback.common.ldap.connection; import org.apache.archiva.redback.configuration.UserConfiguration; import org.apache.archiva.redback.configuration.UserConfigurationKeys; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; @@ -41,6 +43,8 @@ public class ConfigurableLdapConnectionFactory implements LdapConnectionFactory { + private final Logger log = LoggerFactory.getLogger(ConfigurableLdapConnectionFactory.class); + private String hostname; private int port; @@ -61,6 +65,8 @@ public class ConfigurableLdapConnectionFactory private LdapConnectionConfiguration ldapConnectionConfiguration; + private boolean valid = false; + @Inject @Named(value = "userConfiguration#default") @@ -90,10 +96,11 @@ public class ConfigurableLdapConnectionFactory ldapConnectionConfiguration.setAuthenticationMethod( userConf.getString( UserConfigurationKeys.LDAP_AUTHENTICATION_METHOD, authenticationMethod ) ); ldapConnectionConfiguration.setExtraProperties( extraProperties ); + valid = true; } catch ( InvalidNameException e ) { - throw new RuntimeException( "Error while initializing connection factory.", e ); + log.error("Error during initialization of LdapConnectionFactory "+e.getMessage(),e); } } @@ -266,4 +273,8 @@ public class ConfigurableLdapConnectionFactory { this.userConf = userConf; } + + public boolean isValid() { + return valid; + } } diff --git a/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/LdapConnectionFactory.java b/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/LdapConnectionFactory.java index d81b3e23..4d6ec030 100644 --- a/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/LdapConnectionFactory.java +++ b/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/LdapConnectionFactory.java @@ -51,4 +51,6 @@ public interface LdapConnectionFactory void initialize(); + public boolean isValid(); + } From 8d9f47436ed7d1e76c5f14b4e0af4c90275f056c Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Sun, 9 Oct 2016 21:13:18 +0200 Subject: [PATCH 11/30] JPA bytecode enhancement --- .../main/resources/META-INF/persistence.xml | 6 +- .../redback-rbac-jpa/pom.xml | 107 +++++++++++------ .../redback-users-jpa/pom.xml | 111 +++++++++++------- 3 files changed, 144 insertions(+), 80 deletions(-) diff --git a/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence.xml b/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence.xml index 46878e88..817eb201 100644 --- a/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence.xml +++ b/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence.xml @@ -20,7 +20,7 @@ org.apache.openjpa.persistence.PersistenceProviderImpl - java:comp/env/jdbc/redbackjpa + java:comp/env/jdbc/redbackjpa org.apache.archiva.redback.users.jpa.model.JpaUser org.apache.archiva.redback.rbac.jpa.model.JpaOperation org.apache.archiva.redback.rbac.jpa.model.JpaResource @@ -28,9 +28,11 @@ org.apache.archiva.redback.rbac.jpa.model.JpaRole org.apache.archiva.redback.rbac.jpa.model.JpaUserAssignment - + + + diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/pom.xml b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/pom.xml index 77045ab9..ba1c0bd9 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/pom.xml +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/pom.xml @@ -20,51 +20,82 @@ - - redback-rbac-providers - org.apache.archiva.redback - 2.5-SNAPSHOT - - 4.0.0 + + redback-rbac-providers + org.apache.archiva.redback + 2.5-SNAPSHOT + + 4.0.0 - redback-rbac-jpa + redback-rbac-jpa jar Redback :: RBAC Provider :: JPA - - - org.apache.archiva.redback - redback-rbac-model - - - org.springframework - spring-context-support - - - javax.annotation - jsr250-api - - - org.apache.archiva.redback - redback-rbac-tests - test - - - org.apache.archiva.redback - redback-common-jpa - + + + org.apache.archiva.redback + redback-rbac-model + + + org.springframework + spring-context-support + + + javax.annotation + jsr250-api + + + org.apache.archiva.redback + redback-rbac-tests + test + + + org.apache.archiva.redback + redback-common-jpa + - + + org.apache.openjpa + openjpa + ${openjpa.version} + + + org.hsqldb + hsqldb + test + + + + + + + org.apache.openjpa + openjpa-maven-plugin + 2.4.1 + + **/model/*.class + true + true + + + + enhancer + process-classes + + enhance + + + + + org.apache.openjpa openjpa + ${openjpa.version} - - - org.hsqldb - hsqldb - test - - - + + + + + \ No newline at end of file diff --git a/redback-users/redback-users-providers/redback-users-jpa/pom.xml b/redback-users/redback-users-providers/redback-users-jpa/pom.xml index 2606b712..4d237187 100644 --- a/redback-users/redback-users-providers/redback-users-jpa/pom.xml +++ b/redback-users/redback-users-providers/redback-users-jpa/pom.xml @@ -20,49 +20,80 @@ - - redback-users-providers - org.apache.archiva.redback - 2.5-SNAPSHOT - - 4.0.0 + + redback-users-providers + org.apache.archiva.redback + 2.5-SNAPSHOT + + 4.0.0 - redback-users-jpa - jar - Redback :: Users Provider :: JPA + redback-users-jpa + jar + Redback :: Users Provider :: JPA - - - org.springframework - spring-context-support - - - javax.annotation - jsr250-api - - - org.apache.archiva.redback - redback-policy - - - org.apache.archiva.redback - redback-common-jpa - - + + + org.springframework + spring-context-support + + + javax.annotation + jsr250-api + + + org.apache.archiva.redback + redback-policy + + + org.apache.archiva.redback + redback-common-jpa + + + org.apache.openjpa + openjpa + ${openjpa.version} + + + + org.hsqldb + hsqldb + test + + + org.apache.archiva.redback + redback-users-tests + test + + + + + + org.apache.openjpa + openjpa-maven-plugin + 2.4.1 + + **/model/*.class + true + true + + + + enhancer + process-classes + + enhance + + + + + org.apache.openjpa openjpa + ${openjpa.version} - - - - org.hsqldb - hsqldb - test - - - org.apache.archiva.redback - redback-users-tests - test - - + + + + + \ No newline at end of file From 8fd7112762fabffa0e00a493d2afaceb079c3fec Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Fri, 14 Oct 2016 21:39:36 +0200 Subject: [PATCH 12/30] Changing transaction handling --- .../main/resources/META-INF/persistence.xml | 2 +- .../redback-users-jpa/pom.xml | 5 +++ .../redback/users/jpa/JpaUserManager.java | 33 +++++++++++-------- .../redback/users/jpa/model/JpaUser.java | 4 +-- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence.xml b/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence.xml index 817eb201..5c1fa801 100644 --- a/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence.xml +++ b/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence.xml @@ -32,7 +32,7 @@ - + diff --git a/redback-users/redback-users-providers/redback-users-jpa/pom.xml b/redback-users/redback-users-providers/redback-users-jpa/pom.xml index 4d237187..29c24f45 100644 --- a/redback-users/redback-users-providers/redback-users-jpa/pom.xml +++ b/redback-users/redback-users-providers/redback-users-jpa/pom.xml @@ -53,6 +53,11 @@ openjpa ${openjpa.version} + + org.springframework + spring-tx + ${springVersion} + org.hsqldb diff --git a/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/JpaUserManager.java b/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/JpaUserManager.java index 33fa7b6d..4429ed88 100644 --- a/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/JpaUserManager.java +++ b/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/JpaUserManager.java @@ -23,12 +23,14 @@ import org.apache.archiva.redback.policy.UserSecurityPolicy; import org.apache.archiva.redback.users.*; import org.apache.archiva.redback.users.jpa.model.JpaUser; import org.apache.commons.lang.StringUtils; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.PostConstruct; import javax.inject.Inject; import javax.persistence.*; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; +import java.util.Date; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; @@ -102,6 +104,7 @@ public class JpaUserManager extends AbstractUserManager { return q.getResultList(); } + @Transactional @Override public User addUser(User user) throws UserManagerException { EntityManager em = getEm(); @@ -133,12 +136,14 @@ public class JpaUserManager extends AbstractUserManager { { user.setPasswordChangeRequired( true ); } - em.getTransaction().begin(); + if (user.getLastPasswordChange()==null) { + user.setLastPasswordChange(new Date()); + } em.persist((JpaUser)user); - em.getTransaction().commit(); return user; } + @Transactional @Override public User updateUser(User user) throws UserNotFoundException, UserManagerException { return updateUser(user, false); @@ -254,6 +259,7 @@ public class JpaUserManager extends AbstractUserManager { + @Transactional @Override public void deleteUser(String username) throws UserNotFoundException, UserManagerException { final EntityManager em = getEm(); @@ -261,12 +267,11 @@ public class JpaUserManager extends AbstractUserManager { if (u.isPermanent()) { throw new PermanentUserException("User "+username+" cannot be deleted"); } - em.getTransaction().begin(); em.remove(u); - em.getTransaction().commit(); fireUserManagerUserRemoved(u); } + @Transactional @Override public void addUserUnchecked(User user) throws UserManagerException { log.info("addUserUnchecked "+user.getUsername()); @@ -282,21 +287,19 @@ public class JpaUserManager extends AbstractUserManager { Messages.getString( "user.manager.cannot.add.user.without.username" ) ); //$NON-NLS-1$ } - em.getTransaction().begin(); TypedQuery q = em.createQuery("SELECT u FROM JpaUser u", JpaUser.class); for (JpaUser u : q.getResultList()) { log.info("USER FOUND: "+u.getUsername()); } log.info("NEW USER "+user.getUsername()); em.persist((JpaUser)user); - em.getTransaction().commit(); } + @Transactional @Override public void eraseDatabase() { EntityManager em = getEm(); - em.getTransaction().begin(); TypedQuery q = em.createQuery("SELECT u FROM JpaUser u", JpaUser.class); for (JpaUser u : q.getResultList()) { u.getPreviousEncodedPasswords().clear(); @@ -304,23 +307,27 @@ public class JpaUserManager extends AbstractUserManager { em.flush(); Query qd = em.createQuery("DELETE FROM JpaUser u"); qd.executeUpdate(); - em.getTransaction().commit(); em.clear(); } + @Transactional @Override public User updateUser(User user, boolean passwordChangeRequired) throws UserNotFoundException, UserManagerException { + if ( !( user instanceof JpaUser ) ) + { + throw new UserManagerException( "Unable to update user. User object " + user.getClass().getName() + + " is not an instance of " + JpaUser.class.getName() ); + } if ( StringUtils.isNotEmpty( user.getPassword() ) ) { userSecurityPolicy.extensionChangePassword( user, passwordChangeRequired ); } + JpaUser jpaUser = (JpaUser) user; final EntityManager em = getEm(); - em.getTransaction().begin(); - em.persist((JpaUser)user); - em.getTransaction().commit(); - fireUserManagerUserUpdated(user); - return user; + jpaUser = em.merge(jpaUser); + fireUserManagerUserUpdated(jpaUser); + return jpaUser; } @Override diff --git a/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/model/JpaUser.java b/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/model/JpaUser.java index cfdaa4e4..9b00c8e3 100644 --- a/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/model/JpaUser.java +++ b/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/model/JpaUser.java @@ -131,7 +131,7 @@ public class JpaUser implements org.apache.archiva.redback.users.User { @Override public void setLastPasswordChange(Date passwordChangeDate) { - this.lastPasswordChange = lastPasswordChange; + this.lastPasswordChange = passwordChangeDate; } @Override @@ -222,6 +222,6 @@ public class JpaUser implements org.apache.archiva.redback.users.User { @Override public String getUserManagerId() { - return null; + return "jpa"; } } From c4fc7ffc730e941c8cc3746d111cbb3116f018f4 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Wed, 19 Oct 2016 23:28:28 +0200 Subject: [PATCH 13/30] Adding Transaction annotation and fixing tests --- .../redback-users-jpa/src/test/resources/test.properties | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/redback-users/redback-users-providers/redback-users-jpa/src/test/resources/test.properties b/redback-users/redback-users-providers/redback-users-jpa/src/test/resources/test.properties index df848c45..24569233 100644 --- a/redback-users/redback-users-providers/redback-users-jpa/src/test/resources/test.properties +++ b/redback-users/redback-users-providers/redback-users-jpa/src/test/resources/test.properties @@ -14,9 +14,4 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -openjpa.ConnectionURL=jdbc:hsqldb:mem:reback-jpa -openjpa.ConnectionDriverName=org.hsqldb.jdbcDriver -openjpa.ConnectionUserName=sa -openjpa.ConnectionPassword= -openjp.Log=DefaultLevel=WARN,Tool=INFO -openjpa.jdbc.SynchronizeMappings=buildSchema(ForeignKeys=true) \ No newline at end of file + From 6f7fa9056264ae7ce98192cdb0946dce97ab65a2 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Fri, 21 Oct 2016 20:11:47 +0200 Subject: [PATCH 14/30] Add transaction annotation and dependencies --- pom.xml | 10 ++ .../redback-common-integrations/pom.xml | 8 -- .../redback-rbac-jpa/pom.xml | 9 +- .../redback/rbac/jpa/JpaRbacManager.java | 98 ++++++++++--------- .../redback/rbac/jpa/model/JpaPermission.java | 4 +- .../redback/rbac/jpa/model/JpaRole.java | 4 +- .../rbac/jpa/model/JpaUserAssignment.java | 3 +- .../redback/rbac/jpa/JpaRbacManagerTest.java | 22 +++-- .../src/test/resources/spring-context.xml | 31 +++++- .../src/test/resources/test.properties | 7 +- .../redback-users-jpa/pom.xml | 5 + .../redback/users/jpa/JpaUserManager.java | 3 +- .../redback/users/jpa/model/JpaUser.java | 36 ++++++- .../redback/users/jpa/JpaUserManagerTest.java | 32 +++--- .../src/test/resources/spring-context.xml | 32 +++++- 15 files changed, 207 insertions(+), 97 deletions(-) diff --git a/pom.xml b/pom.xml index 975be68e..cdb4c899 100644 --- a/pom.xml +++ b/pom.xml @@ -533,6 +533,16 @@ spring-test ${springVersion} + + org.springframework + spring-tx + ${springVersion} + + + org.springframework + spring-orm + ${springVersion} + javax.annotation jsr250-api diff --git a/redback-integrations/redback-common-integrations/pom.xml b/redback-integrations/redback-common-integrations/pom.xml index 656dcf2a..34921ce0 100644 --- a/redback-integrations/redback-common-integrations/pom.xml +++ b/redback-integrations/redback-common-integrations/pom.xml @@ -81,14 +81,6 @@ org.apache.archiva.redback redback-users-ldap - - org.apache.archiva.redback - redback-users-jpa - - - org.apache.archiva.redback - redback-rbac-jpa - org.apache.archiva.redback redback-users-configurable diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/pom.xml b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/pom.xml index ba1c0bd9..665af806 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/pom.xml +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/pom.xml @@ -53,7 +53,14 @@ org.apache.archiva.redback redback-common-jpa - + + org.springframework + spring-tx + + + org.springframework + spring-orm + org.apache.openjpa openjpa diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java index 184df40e..86895661 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java @@ -23,6 +23,7 @@ import org.apache.archiva.redback.rbac.*; import org.apache.archiva.redback.rbac.jpa.model.*; import org.apache.openjpa.persistence.Type; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.PostConstruct; import javax.inject.Inject; @@ -59,21 +60,26 @@ public class JpaRbacManager extends AbstractRBACManager { return role; } + @Transactional @Override public Role saveRole(Role role) throws RbacObjectInvalidException, RbacManagerException { RBACObjectAssertions.assertValid( role ); final EntityManager em = getEm(); - em.getTransaction().begin(); - em.persist(role); - - em.getTransaction().commit(); - fireRbacRoleSaved(role); - for (Permission perm : role.getPermissions()) { + Role mergedRole = em.merge(role); + fireRbacRoleSaved(mergedRole); + for (Permission perm : mergedRole.getPermissions()) { fireRbacPermissionSaved(perm); } - return role; + return mergedRole; } + @Transactional + @Override + public void addChildRole(Role role, Role childRole) throws RbacObjectInvalidException, RbacManagerException { + super.addChildRole(role, childRole); + } + + @Transactional @Override public void saveRoles(Collection roles) throws RbacObjectInvalidException, RbacManagerException { if ( roles == null ) @@ -83,17 +89,17 @@ public class JpaRbacManager extends AbstractRBACManager { } final EntityManager em = getEm(); - em.getTransaction().begin(); + List merged = new ArrayList(); for (Role role : roles ) { RBACObjectAssertions.assertValid(role); - em.persist(role); + merged.add(em.merge(role)); } - em.getTransaction().commit(); - for (Role role : roles) { + for (Role role : merged) { fireRbacRoleSaved(role); } } + @Override public Role getRole(String roleName) throws RbacObjectNotFoundException, RbacManagerException { final EntityManager em = getEm(); @@ -109,6 +115,7 @@ public class JpaRbacManager extends AbstractRBACManager { return q.getResultList(); } + @Transactional @Override public void removeRole(Role role) throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException { RBACObjectAssertions.assertValid(role); @@ -120,14 +127,12 @@ public class JpaRbacManager extends AbstractRBACManager { throw new RbacPermanentException( "Unable to delete permanent role [" + role.getName() + "]" ); } final EntityManager em = getEm(); - em.getTransaction().begin(); JpaRole myRole = em.find(JpaRole.class, role.getName()); if (myRole == null) { throw new RbacObjectNotFoundException("Role not found "+role.getName()); } myRole.setPermissions(new ArrayList()); em.remove(myRole); - em.getTransaction().commit(); fireRbacRoleRemoved(myRole); } @@ -159,6 +164,7 @@ public class JpaRbacManager extends AbstractRBACManager { return permission; } + @Transactional @Override public Permission savePermission(Permission permission) throws RbacObjectInvalidException, RbacManagerException { RBACObjectAssertions.assertValid(permission); @@ -166,11 +172,9 @@ public class JpaRbacManager extends AbstractRBACManager { throw new RbacObjectInvalidException("The permission object ist not instance of JpaPermission"); } final EntityManager em = getEm(); - em.getTransaction().begin(); - em.persist(permission); - em.getTransaction().commit(); - fireRbacPermissionSaved(permission); - return permission; + Permission savedPermission = em.merge(permission); + fireRbacPermissionSaved(savedPermission); + return savedPermission; } @Override @@ -192,6 +196,7 @@ public class JpaRbacManager extends AbstractRBACManager { return (List)(List)q.getResultList(); } + @Transactional @Override public void removePermission(Permission permission) throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException { RBACObjectAssertions.assertValid(permission); @@ -203,13 +208,11 @@ public class JpaRbacManager extends AbstractRBACManager { throw new RbacPermanentException( "Unable to delete permanent permission [" + permission.getName() + "]" ); } final EntityManager em = getEm(); - em.getTransaction().begin(); - Permission p = em.find(JpaPermission.class, permission.getName()); + JpaPermission p = em.find(JpaPermission.class, permission.getName()); if (p == null) { throw new RbacObjectNotFoundException("Permission " + permission.getName() + " not found"); } em.remove(p); - em.getTransaction().commit(); fireRbacPermissionRemoved(p); } @@ -220,6 +223,7 @@ public class JpaRbacManager extends AbstractRBACManager { return op; } + @Transactional @Override public Operation saveOperation(Operation operation) throws RbacObjectInvalidException, RbacManagerException { RBACObjectAssertions.assertValid(operation); @@ -227,10 +231,8 @@ public class JpaRbacManager extends AbstractRBACManager { throw new RbacObjectInvalidException("Operation is not JpaOperation object"); } final EntityManager em = getEm(); - em.getTransaction().begin(); - em.persist(operation); - em.getTransaction().commit(); - return operation; + Operation savedOperation = em.merge(operation); + return savedOperation; } @Override @@ -250,6 +252,7 @@ public class JpaRbacManager extends AbstractRBACManager { return q.getResultList(); } + @Transactional @Override public void removeOperation(Operation operation) throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException { RBACObjectAssertions.assertValid(operation); @@ -261,14 +264,11 @@ public class JpaRbacManager extends AbstractRBACManager { throw new RbacPermanentException( "Unable to delete permanent operation [" + operation.getName() + "]" ); } final EntityManager em = getEm(); - em.getTransaction().begin(); - Operation op = em.find(JpaOperation.class, operation.getName()); + JpaOperation op = em.find(JpaOperation.class, operation.getName()); if (op==null) { throw new RbacObjectNotFoundException("Operation not found "+operation.getName()); } em.remove(op); - em.getTransaction().commit(); - } @Override @@ -278,6 +278,7 @@ public class JpaRbacManager extends AbstractRBACManager { return resource; } + @Transactional @Override public Resource saveResource(Resource resource) throws RbacObjectInvalidException, RbacManagerException { RBACObjectAssertions.assertValid(resource); @@ -285,10 +286,17 @@ public class JpaRbacManager extends AbstractRBACManager { throw new RbacObjectInvalidException("Resource is not JpaResource"); } final EntityManager em = getEm(); - em.getTransaction().begin(); - em.persist(resource); - em.getTransaction().commit(); - return resource; + Resource savedResource = em.merge(resource); + return savedResource; + } + + // Overriding to add the transactional attribute here + @Transactional + @Override + public Resource getGlobalResource() + throws RbacManagerException + { + return super.getGlobalResource(); } @Override @@ -308,6 +316,7 @@ public class JpaRbacManager extends AbstractRBACManager { return (List)(List)q.getResultList(); } + @Transactional @Override public void removeResource(Resource resource) throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException { RBACObjectAssertions.assertValid(resource); @@ -318,13 +327,11 @@ public class JpaRbacManager extends AbstractRBACManager { throw new RbacObjectInvalidException("Unable to delete permanent resource ["+resource.getIdentifier()+ "]"); } final EntityManager em = getEm(); - em.getTransaction().begin(); - Resource res = em.find(JpaResource.class, resource.getIdentifier()); + JpaResource res = em.find(JpaResource.class, resource.getIdentifier()); if (res==null) { throw new RbacObjectNotFoundException("Resource "+resource.getIdentifier()+" not found"); } em.remove(res); - em.getTransaction().commit(); } @Override @@ -334,6 +341,7 @@ public class JpaRbacManager extends AbstractRBACManager { return ua; } + @Transactional @Override public UserAssignment saveUserAssignment(UserAssignment userAssignment) throws RbacObjectInvalidException, RbacManagerException { RBACObjectAssertions.assertValid(userAssignment); @@ -341,11 +349,9 @@ public class JpaRbacManager extends AbstractRBACManager { throw new RbacObjectInvalidException("Cannto save object that is not JpaUserAssignment"); } final EntityManager em = getEm(); - em.getTransaction().begin(); - em.persist(userAssignment); - em.getTransaction().commit(); - fireRbacUserAssignmentSaved(userAssignment); - return userAssignment; + UserAssignment savedAssignment = em.merge(userAssignment); + fireRbacUserAssignmentSaved(savedAssignment); + return savedAssignment; } @Override @@ -373,6 +379,7 @@ public class JpaRbacManager extends AbstractRBACManager { return q.getResultList(); } + @Transactional @Override public void removeUserAssignment(UserAssignment userAssignment) throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException { RBACObjectAssertions.assertValid(userAssignment); @@ -380,22 +387,20 @@ public class JpaRbacManager extends AbstractRBACManager { throw new RbacObjectInvalidException("Cannot remove permanent object "+userAssignment.getPrincipal()); } final EntityManager em = getEm(); - em.getTransaction().begin(); - UserAssignment ua = em.find(UserAssignment.class, userAssignment.getPrincipal()); + JpaUserAssignment ua = em.find(JpaUserAssignment.class, userAssignment.getPrincipal()); if (ua==null) { throw new RbacObjectNotFoundException("User assignment not found "+userAssignment.getPrincipal()); } em.remove(ua); - em.getTransaction().commit(); fireRbacUserAssignmentRemoved(userAssignment); } + @Transactional @Override public void eraseDatabase() { final EntityManager em = getEm(); // Deletion is a bit tricky, because the JPA bulk delete queries do not cascade // or keep foreign keys into account. - em.getTransaction().begin(); TypedQuery tqp = em.createQuery("SELECT r FROM JpaPermission r",JpaPermission.class); for(JpaPermission p : tqp.getResultList()) { p.setOperation(null); @@ -424,10 +429,9 @@ public class JpaRbacManager extends AbstractRBACManager { for(JpaUserAssignment ua : tqu.getResultList()) { em.remove(ua); } - em.getTransaction().commit(); + em.flush(); em.clear(); - } @Override diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaPermission.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaPermission.java index 4ac69896..1e83d2b9 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaPermission.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaPermission.java @@ -41,13 +41,13 @@ public class JpaPermission implements Permission,Serializable { private String description; @Column(name="PERMANENT") private boolean permanent; - @ManyToOne(cascade = CascadeType.PERSIST) + @ManyToOne(cascade = CascadeType.ALL) @JoinColumn( name="OPERATION_NAME_OID", referencedColumnName = "NAME" ) private JpaOperation operation; - @ManyToOne(cascade = CascadeType.PERSIST) + @ManyToOne(cascade = CascadeType.ALL) @JoinColumn( name="RESOURCE_IDENTIFIER_OID", referencedColumnName = "IDENTIFIER" diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaRole.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaRole.java index 98c4bf2d..5a7cdc7e 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaRole.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaRole.java @@ -46,7 +46,7 @@ public class JpaRole extends AbstractRole implements Serializable { private boolean assignable; @Column(name="PERMANENT") private boolean permanent; - @ManyToMany(cascade = CascadeType.PERSIST) + @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @OrderColumn(name="INTEGER_IDX") @JoinTable( name="SECURITY_ROLE_PERMISSION_MAP", @@ -57,7 +57,7 @@ public class JpaRole extends AbstractRole implements Serializable { ) List permissions = new ArrayList(); - @ElementCollection + @ElementCollection(fetch = FetchType.EAGER) @OrderColumn(name="INTEGER_IDX") @CollectionTable( name="SECURITY_ROLE_CHILDROLE_MAP", diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaUserAssignment.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaUserAssignment.java index 65ed8af0..f0b3d542 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaUserAssignment.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaUserAssignment.java @@ -25,6 +25,7 @@ import javax.persistence.CollectionTable; import javax.persistence.Column; import javax.persistence.ElementCollection; import javax.persistence.Entity; +import javax.persistence.FetchType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OrderColumn; @@ -44,7 +45,7 @@ public class JpaUserAssignment extends AbstractUserAssignment implements Seriali @Id @Column(name="PRINCIPAL") private String principal; - @ElementCollection + @ElementCollection(fetch = FetchType.EAGER) @Column(name="STRING_ELE") @OrderColumn(name="INTEGER_IDX") @CollectionTable( diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/test/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManagerTest.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/test/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManagerTest.java index 3c5bc9fa..cfc34f46 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/test/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManagerTest.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/test/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManagerTest.java @@ -20,10 +20,12 @@ package org.apache.archiva.redback.rbac.jpa; */ import org.apache.archiva.redback.common.jdo.test.StoreManagerDebug; +import org.apache.archiva.redback.rbac.RBACManager; import org.apache.archiva.redback.rbac.RbacManagerException; import org.apache.archiva.redback.tests.AbstractRbacManagerTestCase; import org.junit.Before; import org.springframework.test.annotation.DirtiesContext; +import org.springframework.transaction.annotation.Transactional; import javax.inject.Inject; import javax.inject.Named; @@ -39,13 +41,15 @@ import java.util.Properties; * @author Joakim Erdfelt */ @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) +@Transactional public class JpaRbacManagerTest extends AbstractRbacManagerTestCase { @Inject @Named(value = "rbacManager#jpa") - JpaRbacManager rbacManager; + RBACManager rbacManager; + public static int EVENTCOUNT = 2; @@ -64,15 +68,15 @@ public class JpaRbacManagerTest { super.setUp(); - Properties props = new Properties(); - InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("test.properties"); - assert is!=null; - props.load(is); - is.close(); - EntityManagerFactory emf = Persistence.createEntityManagerFactory("redback-jpa",props); - +// Properties props = new Properties(); +// InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("test.properties"); +// assert is!=null; +// props.load(is); +// is.close(); +// EntityManagerFactory emf = Persistence.createEntityManagerFactory("redback-jpa",props); +// log.info("test setup"); - rbacManager.setEntityManager(emf.createEntityManager()); + // rbacManager.setEntityManager(emf.createEntityManager()); super.setRbacManager(rbacManager); assertNotNull(rbacManager); log.info("injected rbac manager "+rbacManager); diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/test/resources/spring-context.xml b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/test/resources/spring-context.xml index abee0b5a..0f09c8a9 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/test/resources/spring-context.xml +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/test/resources/spring-context.xml @@ -20,11 +20,11 @@ --> + http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> @@ -37,4 +37,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/test/resources/test.properties b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/test/resources/test.properties index df848c45..24569233 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/test/resources/test.properties +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/test/resources/test.properties @@ -14,9 +14,4 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -openjpa.ConnectionURL=jdbc:hsqldb:mem:reback-jpa -openjpa.ConnectionDriverName=org.hsqldb.jdbcDriver -openjpa.ConnectionUserName=sa -openjpa.ConnectionPassword= -openjp.Log=DefaultLevel=WARN,Tool=INFO -openjpa.jdbc.SynchronizeMappings=buildSchema(ForeignKeys=true) \ No newline at end of file + diff --git a/redback-users/redback-users-providers/redback-users-jpa/pom.xml b/redback-users/redback-users-providers/redback-users-jpa/pom.xml index 29c24f45..a73e9f25 100644 --- a/redback-users/redback-users-providers/redback-users-jpa/pom.xml +++ b/redback-users/redback-users-providers/redback-users-jpa/pom.xml @@ -58,6 +58,11 @@ spring-tx ${springVersion} + + org.springframework + spring-orm + ${springVersion} + org.hsqldb diff --git a/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/JpaUserManager.java b/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/JpaUserManager.java index 4429ed88..f60088b9 100644 --- a/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/JpaUserManager.java +++ b/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/JpaUserManager.java @@ -23,6 +23,7 @@ import org.apache.archiva.redback.policy.UserSecurityPolicy; import org.apache.archiva.redback.users.*; import org.apache.archiva.redback.users.jpa.model.JpaUser; import org.apache.commons.lang.StringUtils; +import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.PostConstruct; @@ -37,7 +38,7 @@ import java.util.concurrent.atomic.AtomicBoolean; /** * Created by martin on 20.09.16. */ -@org.springframework.stereotype.Service("userManager#jpa") +@Service("userManager#jpa") public class JpaUserManager extends AbstractUserManager { diff --git a/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/model/JpaUser.java b/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/model/JpaUser.java index 9b00c8e3..f1c79e20 100644 --- a/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/model/JpaUser.java +++ b/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/model/JpaUser.java @@ -23,6 +23,7 @@ import javax.persistence.CollectionTable; import javax.persistence.Column; import javax.persistence.ElementCollection; import javax.persistence.Entity; +import javax.persistence.FetchType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OrderColumn; @@ -49,7 +50,7 @@ public class JpaUser implements org.apache.archiva.redback.users.User { private String encodedPassword; @Column(name="LAST_PASSWORD_CHANGE") private Date lastPasswordChange; - @ElementCollection + @ElementCollection(fetch = FetchType.EAGER) @OrderColumn(name="INTEGER_IDX") @Column(name="STRING_ELE") @CollectionTable(name="JDOUSER_PREVIOUSENCODEDPASSWORDS", @@ -136,18 +137,28 @@ public class JpaUser implements org.apache.archiva.redback.users.User { @Override public List getPreviousEncodedPasswords() { + if (previousEncodedPasswords==null) { + setPreviousEncodedPasswords(new ArrayList()); + } + assert previousEncodedPasswords != null; return previousEncodedPasswords; } @Override public void setPreviousEncodedPasswords(List encodedPasswordList) { - this.previousEncodedPasswords.clear(); - this.previousEncodedPasswords.addAll(encodedPasswordList); + if (previousEncodedPasswords==null) { + previousEncodedPasswords = new ArrayList(); + } + previousEncodedPasswords.clear(); + previousEncodedPasswords.addAll(encodedPasswordList); } @Override public void addPreviousEncodedPassword(String encodedPassword) { - this.previousEncodedPasswords.add(encodedPassword); + if (previousEncodedPasswords==null) { + previousEncodedPasswords = new ArrayList(); + } + previousEncodedPasswords.add(encodedPassword); } @Override @@ -224,4 +235,21 @@ public class JpaUser implements org.apache.archiva.redback.users.User { public String getUserManagerId() { return "jpa"; } + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + JpaUser jpaUser = (JpaUser) o; + + return username.equals(jpaUser.username); + + } + + @Override + public int hashCode() { + return username.hashCode(); + } } diff --git a/redback-users/redback-users-providers/redback-users-jpa/src/test/java/org/apache/archiva/redback/users/jpa/JpaUserManagerTest.java b/redback-users/redback-users-providers/redback-users-jpa/src/test/java/org/apache/archiva/redback/users/jpa/JpaUserManagerTest.java index 75cda6da..97726979 100644 --- a/redback-users/redback-users-providers/redback-users-jpa/src/test/java/org/apache/archiva/redback/users/jpa/JpaUserManagerTest.java +++ b/redback-users/redback-users-providers/redback-users-jpa/src/test/java/org/apache/archiva/redback/users/jpa/JpaUserManagerTest.java @@ -22,11 +22,22 @@ package org.apache.archiva.redback.users.jpa; import org.apache.archiva.redback.policy.UserSecurityPolicy; import org.apache.archiva.redback.users.User; import org.apache.archiva.redback.users.UserManager; +import org.apache.archiva.redback.users.UserManagerException; +import org.apache.archiva.redback.users.UserNotFoundException; +import org.apache.archiva.redback.users.jpa.model.JpaUser; import org.apache.archiva.redback.users.provider.test.AbstractUserManagerTestCase; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.transaction.TransactionConfiguration; +import org.springframework.transaction.annotation.Transactional; import javax.inject.Inject; import javax.inject.Named; @@ -40,14 +51,17 @@ import java.util.Properties; /** * Created by martin on 21.09.16. */ - +@Transactional public class JpaUserManagerTest extends AbstractUserManagerTestCase { Log log = LogFactory.getLog(JpaUserManagerTest.class); @Inject @Named("userManager#jpa") - JpaUserManager jpaUserManager; + UserManager jpaUserManager; + + @Inject + EntityManagerFactory entityManagerFactory; @Inject @@ -58,28 +72,20 @@ public class JpaUserManagerTest extends AbstractUserManagerTestCase { public void setUp() throws Exception { super.setUp(); - Properties props = new Properties(); - InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("test.properties"); - assert is!=null; - props.load(is); - is.close(); - EntityManagerFactory emf = Persistence.createEntityManagerFactory("redback-jpa",props); - - jpaUserManager.setEntityManager(emf.createEntityManager()); - super.setUserManager(jpaUserManager); assertNotNull(jpaUserManager); + super.setUserManager(jpaUserManager); log.info("injected usermanager "+jpaUserManager); - // create the factory defined by the "openjpa" entity-manager entry - } @Test public void testInit() { + assertNotNull(jpaUserManager); jpaUserManager.initialize(); } + } diff --git a/redback-users/redback-users-providers/redback-users-jpa/src/test/resources/spring-context.xml b/redback-users/redback-users-providers/redback-users-jpa/src/test/resources/spring-context.xml index 4d7802ed..b67e1e98 100644 --- a/redback-users/redback-users-providers/redback-users-jpa/src/test/resources/spring-context.xml +++ b/redback-users/redback-users-providers/redback-users-jpa/src/test/resources/spring-context.xml @@ -21,10 +21,11 @@ + http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> @@ -47,4 +48,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 994c7cb42fbbb30a98c43678ae3d396d5857d17c Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Fri, 21 Oct 2016 22:09:32 +0200 Subject: [PATCH 15/30] Fix maven dependencies --- .../redback-rbac-providers/redback-rbac-cached/pom.xml | 4 ++++ redback-users/redback-users-providers/pom.xml | 2 +- .../redback-users-providers/redback-users-cached/pom.xml | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-cached/pom.xml b/redback-rbac/redback-rbac-providers/redback-rbac-cached/pom.xml index d3b64bd9..bb25053c 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-cached/pom.xml +++ b/redback-rbac/redback-rbac-providers/redback-rbac-cached/pom.xml @@ -68,6 +68,10 @@ org.apache.archiva.redback redback-rbac-jdo + + org.apache.archiva.redback + redback-rbac-jpa + org.apache.archiva.redback redback-rbac-memory diff --git a/redback-users/redback-users-providers/pom.xml b/redback-users/redback-users-providers/pom.xml index 4a906482..1172f625 100644 --- a/redback-users/redback-users-providers/pom.xml +++ b/redback-users/redback-users-providers/pom.xml @@ -39,6 +39,6 @@ redback-users-jdo redback-users-ldap redback-users-configurable - redback-users-jpa + redback-users-jpa diff --git a/redback-users/redback-users-providers/redback-users-cached/pom.xml b/redback-users/redback-users-providers/redback-users-cached/pom.xml index f56654ef..b64fe22e 100644 --- a/redback-users/redback-users-providers/redback-users-cached/pom.xml +++ b/redback-users/redback-users-providers/redback-users-cached/pom.xml @@ -60,6 +60,10 @@ org.apache.archiva.redback redback-users-jdo + + org.apache.archiva.redback + redback-users-jpa + org.apache.archiva.redback redback-users-tests From 45b429e7788d4eeabd76ed9d366de0763a74a2d7 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Tue, 25 Oct 2016 15:52:26 +0200 Subject: [PATCH 16/30] Add jpa config to test spring contexts --- .../src/test/resources/spring-context.xml | 30 ++++++++++++++- .../src/test/resources/spring-context.xml | 37 ++++++++++++++++++- .../src/test/resources/spring-context.xml | 35 +++++++++++++++++- .../src/test/resources/spring-context.xml | 36 +++++++++++++++++- .../src/test/resources/spring-context.xml | 36 +++++++++++++++++- .../src/test/resources/spring-context.xml | 35 +++++++++++++++++- .../src/test/resources/spring-context.xml | 36 +++++++++++++++++- .../src/test/resources/spring-context.xml | 34 ++++++++++++++++- .../src/test/resources/spring-context.xml | 34 ++++++++++++++++- .../src/test/resources/spring-context.xml | 35 +++++++++++++++++- .../src/test/resources/spring-context.xml | 30 ++++++++++++++- .../src/test/resources/spring-context.xml | 30 ++++++++++++++- 12 files changed, 384 insertions(+), 24 deletions(-) diff --git a/redback-authentication/redback-authentication-providers/redback-authentication-users/src/test/resources/spring-context.xml b/redback-authentication/redback-authentication-providers/redback-authentication-users/src/test/resources/spring-context.xml index 0638e2ac..87b428c6 100644 --- a/redback-authentication/redback-authentication-providers/redback-authentication-users/src/test/resources/spring-context.xml +++ b/redback-authentication/redback-authentication-providers/redback-authentication-users/src/test/resources/spring-context.xml @@ -19,9 +19,9 @@ ~ under the License. --> @@ -35,4 +35,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/redback-authorization/redback-authorization-providers/redback-authorization-rbac/src/test/resources/spring-context.xml b/redback-authorization/redback-authorization-providers/redback-authorization-rbac/src/test/resources/spring-context.xml index ce2a5e10..8d846829 100644 --- a/redback-authorization/redback-authorization-providers/redback-authorization-rbac/src/test/resources/spring-context.xml +++ b/redback-authorization/redback-authorization-providers/redback-authorization-rbac/src/test/resources/spring-context.xml @@ -19,9 +19,9 @@ ~ under the License. --> @@ -46,4 +46,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/redback-data-management/src/test/resources/spring-context.xml b/redback-data-management/src/test/resources/spring-context.xml index b6fb123d..54b5521f 100644 --- a/redback-data-management/src/test/resources/spring-context.xml +++ b/redback-data-management/src/test/resources/spring-context.xml @@ -20,11 +20,11 @@ --> + http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> @@ -49,4 +49,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/redback-integrations/redback-common-integrations/src/test/resources/spring-context.xml b/redback-integrations/redback-common-integrations/src/test/resources/spring-context.xml index fc4f0ad0..099a82dc 100644 --- a/redback-integrations/redback-common-integrations/src/test/resources/spring-context.xml +++ b/redback-integrations/redback-common-integrations/src/test/resources/spring-context.xml @@ -20,11 +20,11 @@ --> + http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> @@ -57,4 +57,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/redback-integrations/redback-rest/redback-rest-services/src/test/resources/spring-context.xml b/redback-integrations/redback-rest/redback-rest-services/src/test/resources/spring-context.xml index 1aae21af..a790bf11 100644 --- a/redback-integrations/redback-rest/redback-rest-services/src/test/resources/spring-context.xml +++ b/redback-integrations/redback-rest/redback-rest-services/src/test/resources/spring-context.xml @@ -19,9 +19,9 @@ ~ under the License. --> + http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> @@ -46,4 +46,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-cached/src/test/resources/spring-context.xml b/redback-rbac/redback-rbac-providers/redback-rbac-cached/src/test/resources/spring-context.xml index 83f1084c..71c14e2f 100755 --- a/redback-rbac/redback-rbac-providers/redback-rbac-cached/src/test/resources/spring-context.xml +++ b/redback-rbac/redback-rbac-providers/redback-rbac-cached/src/test/resources/spring-context.xml @@ -19,9 +19,9 @@ ~ under the License. --> @@ -80,5 +80,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/resources/spring-context.xml b/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/resources/spring-context.xml index c7b54f03..34e8738e 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/resources/spring-context.xml +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/resources/spring-context.xml @@ -19,9 +19,9 @@ ~ under the License. --> + http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> @@ -41,6 +41,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/resources/spring-context.xml b/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/resources/spring-context.xml index 1018308f..beae9e07 100755 --- a/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/resources/spring-context.xml +++ b/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/resources/spring-context.xml @@ -20,11 +20,11 @@ --> @@ -123,5 +123,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/test/resources/spring-context.xml b/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/test/resources/spring-context.xml index 33592849..cec014ea 100755 --- a/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/test/resources/spring-context.xml +++ b/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/test/resources/spring-context.xml @@ -19,9 +19,9 @@ ~ under the License. --> + http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> @@ -47,6 +47,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/redback-rbac/redback-rbac-role-manager/src/test/resources/spring-context.xml b/redback-rbac/redback-rbac-role-manager/src/test/resources/spring-context.xml index 53d53435..9ba16d9b 100755 --- a/redback-rbac/redback-rbac-role-manager/src/test/resources/spring-context.xml +++ b/redback-rbac/redback-rbac-role-manager/src/test/resources/spring-context.xml @@ -19,9 +19,9 @@ ~ under the License. --> @@ -72,4 +72,35 @@ --> + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/redback-system/src/test/resources/spring-context.xml b/redback-system/src/test/resources/spring-context.xml index 3cb2eefc..2b4f86e8 100644 --- a/redback-system/src/test/resources/spring-context.xml +++ b/redback-system/src/test/resources/spring-context.xml @@ -19,9 +19,9 @@ ~ under the License. --> + http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> @@ -36,6 +36,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/redback-users/redback-users-providers/redback-users-cached/src/test/resources/spring-context.xml b/redback-users/redback-users-providers/redback-users-cached/src/test/resources/spring-context.xml index 5ad17aec..57a2c087 100644 --- a/redback-users/redback-users-providers/redback-users-cached/src/test/resources/spring-context.xml +++ b/redback-users/redback-users-providers/redback-users-cached/src/test/resources/spring-context.xml @@ -19,9 +19,9 @@ ~ under the License. --> @@ -46,4 +46,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From b6a3d0136023e2760356c642bf1d04a7f5df0abc Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Tue, 25 Oct 2016 15:53:59 +0200 Subject: [PATCH 17/30] Add exception handler --- .../archiva/redback/rbac/jpa/JpaRbacManager.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java index 86895661..ea219e99 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java @@ -373,10 +373,18 @@ public class JpaRbacManager extends AbstractRBACManager { @Override public List getUserAssignmentsForRoles(Collection roleNames) throws RbacManagerException { - final EntityManager em = getEm(); - Query q = em.createQuery("SELECT ua FROM JpaUserAssignment ua, ua.roleNames rn WHERE rn IN :rolenames"); - q.setParameter("rolenames",roleNames); - return q.getResultList(); + try { + final EntityManager em = getEm(); + Query q = em.createQuery("SELECT ua FROM JpaUserAssignment ua WHERE ua.roleNames IN :roles"); + q.setParameter("roles", roleNames); + return q.getResultList(); + } catch (Exception ex) { + log.error("Query failed: {}",ex.getMessage(),ex); + if (log.isDebugEnabled()) { + ex.printStackTrace(); + } + throw new RbacManagerException(ex.getMessage(),ex); + } } @Transactional From 542037431484d06a82edfd7d4a63cdf9df8e8f16 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Tue, 25 Oct 2016 15:55:07 +0200 Subject: [PATCH 18/30] Override method to activate transaction handling --- .../apache/archiva/redback/users/jpa/JpaUserManager.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/JpaUserManager.java b/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/JpaUserManager.java index f60088b9..ea81ac7e 100644 --- a/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/JpaUserManager.java +++ b/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/JpaUserManager.java @@ -341,4 +341,12 @@ public class JpaUserManager extends AbstractUserManager { public boolean isFinalImplementation() { return true; } + + + // Override to add transactional annotation + @Transactional + @Override + public User createGuestUser() throws UserManagerException { + return super.createGuestUser(); + } } From 13aa63a4e52d72c3a591cd9b7afe2534bf59eca9 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Fri, 4 Nov 2016 08:02:57 +0100 Subject: [PATCH 19/30] Add JPA Key Provider --- .../resources/META-INF/persistence-hsqldb.xml | 1 + .../main/resources/META-INF/persistence.xml | 1 + redback-keys/redback-keys-providers/pom.xml | 1 + .../redback-keys-jpa/pom.xml | 101 ++++++++++++ .../redback/keys/jpa/JpaKeyManager.java | 156 ++++++++++++++++++ .../keys/jpa/model/JpaAuthenticationKey.java | 88 ++++++++++ .../src/main/resources/spring-context.xml | 33 ++++ .../redback/keys/jpa/JpaKeyManagerTest.java | 65 ++++++++ .../src/test/resources/spring-context.xml | 61 +++++++ .../redback/keys/KeyManagerTestCase.java | 10 +- 10 files changed, 512 insertions(+), 5 deletions(-) create mode 100644 redback-keys/redback-keys-providers/redback-keys-jpa/pom.xml create mode 100644 redback-keys/redback-keys-providers/redback-keys-jpa/src/main/java/org/apache/archiva/redback/keys/jpa/JpaKeyManager.java create mode 100644 redback-keys/redback-keys-providers/redback-keys-jpa/src/main/java/org/apache/archiva/redback/keys/jpa/model/JpaAuthenticationKey.java create mode 100644 redback-keys/redback-keys-providers/redback-keys-jpa/src/main/resources/spring-context.xml create mode 100644 redback-keys/redback-keys-providers/redback-keys-jpa/src/test/java/org/apache/archiva/redback/keys/jpa/JpaKeyManagerTest.java create mode 100644 redback-keys/redback-keys-providers/redback-keys-jpa/src/test/resources/spring-context.xml diff --git a/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence-hsqldb.xml b/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence-hsqldb.xml index 6f37758b..82da347e 100644 --- a/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence-hsqldb.xml +++ b/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence-hsqldb.xml @@ -26,6 +26,7 @@ org.apache.archiva.redback.rbac.jpa.model.JpaPermission org.apache.archiva.redback.rbac.jpa.model.JpaRole org.apache.archiva.redback.rbac.jpa.model.JpaUserAssignment + org.apache.archiva.redback.keys.jpa.model.JpaAuthenticationKey diff --git a/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence.xml b/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence.xml index 5c1fa801..6d9f1afa 100644 --- a/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence.xml +++ b/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence.xml @@ -27,6 +27,7 @@ org.apache.archiva.redback.rbac.jpa.model.JpaPermission org.apache.archiva.redback.rbac.jpa.model.JpaRole org.apache.archiva.redback.rbac.jpa.model.JpaUserAssignment + org.apache.archiva.redback.keys.jpa.model.JpaAuthenticationKey diff --git a/redback-keys/redback-keys-providers/pom.xml b/redback-keys/redback-keys-providers/pom.xml index ee07fd95..4cc46abd 100644 --- a/redback-keys/redback-keys-providers/pom.xml +++ b/redback-keys/redback-keys-providers/pom.xml @@ -31,5 +31,6 @@ redback-keys-jdo redback-keys-memory redback-keys-cached + redback-keys-jpa diff --git a/redback-keys/redback-keys-providers/redback-keys-jpa/pom.xml b/redback-keys/redback-keys-providers/redback-keys-jpa/pom.xml new file mode 100644 index 00000000..f61e614b --- /dev/null +++ b/redback-keys/redback-keys-providers/redback-keys-jpa/pom.xml @@ -0,0 +1,101 @@ + + + + redback-keys-providers + org.apache.archiva.redback + 2.5-SNAPSHOT + + 4.0.0 + + redback-keys-jpa + jar + Redback :: Key Management Provider :: JPA + + + + org.apache.archiva.redback + redback-keys-api + + + + org.apache.archiva.redback + redback-common-jpa + + + + org.springframework + spring-context-support + + + javax.annotation + jsr250-api + + + + org.apache.archiva.redback + redback-keys-tests + test + + + org.apache.openjpa + openjpa + ${openjpa.version} + + + org.springframework + spring-tx + ${springVersion} + + + org.springframework + spring-orm + ${springVersion} + + + org.hsqldb + hsqldb + test + + + org.slf4j + slf4j-simple + test + + + + + + + org.apache.openjpa + openjpa-maven-plugin + 2.4.1 + + **/model/*.class + true + true + + + + enhancer + process-classes + + enhance + + + + + + org.apache.openjpa + openjpa + + ${openjpa.version} + + + + + + + + \ No newline at end of file diff --git a/redback-keys/redback-keys-providers/redback-keys-jpa/src/main/java/org/apache/archiva/redback/keys/jpa/JpaKeyManager.java b/redback-keys/redback-keys-providers/redback-keys-jpa/src/main/java/org/apache/archiva/redback/keys/jpa/JpaKeyManager.java new file mode 100644 index 00000000..ab4a001d --- /dev/null +++ b/redback-keys/redback-keys-providers/redback-keys-jpa/src/main/java/org/apache/archiva/redback/keys/jpa/JpaKeyManager.java @@ -0,0 +1,156 @@ +package org.apache.archiva.redback.keys.jpa; + +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.jpa.model.JpaAuthenticationKey; +import org.codehaus.plexus.util.StringUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.persistence.*; +import java.util.Calendar; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; + +/** + * Created by martin on 27.10.16. + */ +@Service( "keyManager#jpa" ) +public class JpaKeyManager extends AbstractKeyManager { + + @PersistenceContext(unitName = "redback-jpa") + EntityManager em; + + // JpaUserManager is a singleton and initialization should be thread safe + private AtomicBoolean initialized = new AtomicBoolean(false); + + public void setEntityManager(EntityManager em) { + this.em = em; + } + + private EntityManager getEm() { + if (initialized.compareAndSet(false,true)) { + Query q = em.createQuery("SELECT COUNT(u.key) FROM JpaAuthenticationKey u"); + boolean dbInit = q.getFirstResult()==0; + } + return em; + } + + public String getId() + { + return "JPA Key Manager - " + this.getClass().getName(); + } + + + @Override + @Transactional + public AuthenticationKey createKey( String principal, String purpose, int expirationMinutes ) + throws KeyManagerException + { + JpaAuthenticationKey authkey = new JpaAuthenticationKey(); + authkey.setKey( super.generateUUID() ); + authkey.setForPrincipal( principal ); + authkey.setPurpose( purpose ); + + Calendar now = getNowGMT(); + authkey.setDateCreated( now.getTime() ); + + if ( expirationMinutes >= 0 ) + { + Calendar expiration = getNowGMT(); + expiration.add( Calendar.MINUTE, expirationMinutes ); + authkey.setDateExpires( expiration.getTime() ); + } + + return addKey( authkey ); + } + + @Transactional + @Override + public AuthenticationKey addKey(AuthenticationKey key) { + final EntityManager em = getEm(); + AuthenticationKey mergedKey = em.merge((JpaAuthenticationKey)key); + return mergedKey; + } + + @Transactional + @Override + public void eraseDatabase() + { + final EntityManager em = getEm(); + Query q = em.createQuery("DELETE FROM JpaAuthenticationKey k"); + q.executeUpdate(); + } + + @Transactional + @Override + public AuthenticationKey findKey(final String key) throws KeyNotFoundException, KeyManagerException { + final EntityManager em = getEm(); + if ( StringUtils.isEmpty( key ) ) + { + throw new KeyNotFoundException( "Empty key not found." ); + } + + try + { + TypedQuery q = + em.createQuery("SELECT k FROM JpaAuthenticationKey k WHERE k.key = :key",JpaAuthenticationKey.class); + q.setParameter("key",key); + JpaAuthenticationKey authkey = q.getSingleResult(); + if ( authkey == null ) + { + throw new KeyNotFoundException( "Key [" + key + "] not found." ); + } + assertNotExpired( authkey ); + + return authkey; + } catch (NoResultException ex) { + throw new KeyNotFoundException("Key [" + key + "] not found."); + } catch (KeyNotFoundException ex) { + throw ex; + } catch (Throwable ex) { + log.error("Error while trying to retrieve JpaAuthenticationKey {}", key); + throw new KeyManagerException("Error while retrieving key "+key+": "+ex.getMessage(), ex); + } + } + + @Transactional + @Override + protected void assertNotExpired(AuthenticationKey authkey) throws KeyManagerException { + super.assertNotExpired(authkey); + } + + @Transactional + @Override + public void deleteKey(AuthenticationKey key) throws KeyManagerException { + final EntityManager em = getEm(); + em.remove((JpaAuthenticationKey)key); + } + + @Transactional + @Override + public void deleteKey(String key) throws KeyManagerException { + try { + JpaAuthenticationKey foundKey = (JpaAuthenticationKey)findKey(key); + em.remove(foundKey); + } catch (KeyNotFoundException ex) { + // Ignore + } catch (Exception ex) { + log.error("Error occured while trying to find key {}: {}", key, ex.getMessage()); + throw new KeyManagerException("Error while retrieving key "+key, ex); + } + } + + @Override + public List getAllKeys() { + final EntityManager em = getEm(); + Query q= em.createQuery("SELECT x from JpaAuthenticationKey x"); + return q.getResultList(); + } + + + + +} diff --git a/redback-keys/redback-keys-providers/redback-keys-jpa/src/main/java/org/apache/archiva/redback/keys/jpa/model/JpaAuthenticationKey.java b/redback-keys/redback-keys-providers/redback-keys-jpa/src/main/java/org/apache/archiva/redback/keys/jpa/model/JpaAuthenticationKey.java new file mode 100644 index 00000000..fba9952d --- /dev/null +++ b/redback-keys/redback-keys-providers/redback-keys-jpa/src/main/java/org/apache/archiva/redback/keys/jpa/model/JpaAuthenticationKey.java @@ -0,0 +1,88 @@ +package org.apache.archiva.redback.keys.jpa.model; + +import org.apache.archiva.redback.keys.AuthenticationKey; + +import javax.persistence.Column; +import javax.persistence.Id; +import javax.persistence.Table; +import java.util.Date; + +/** + * Created by martin on 27.10.16. + */ +@javax.persistence.Entity +@Table(name="JDOAUTHENTICATIONKEY") +public class JpaAuthenticationKey implements AuthenticationKey { + + @Column(name="AUTHKEY") + @Id + private String key; + + @Column(name="FOR_PRINCIPAL") + private String forPrincipal; + + @Column(name="PURPOSE") + private String purpose; + + @Column(name="DATE_CREATED") + private Date dateCreated; + + @Column(name="DATE_EXPIRES") + private Date dateExpires; + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getForPrincipal() { + return forPrincipal; + } + + public void setForPrincipal(String forPrincipal) { + this.forPrincipal = forPrincipal; + } + + public String getPurpose() { + return purpose; + } + + public void setPurpose(String purpose) { + this.purpose = purpose; + } + + public Date getDateCreated() { + return dateCreated; + } + + public void setDateCreated(Date dateCreated) { + this.dateCreated = dateCreated; + } + + public Date getDateExpires() { + return dateExpires; + } + + public void setDateExpires(Date dateExpires) { + this.dateExpires = dateExpires; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + JpaAuthenticationKey that = (JpaAuthenticationKey) o; + + return key.equals(that.key); + + } + + @Override + public int hashCode() { + return key.hashCode(); + } +} diff --git a/redback-keys/redback-keys-providers/redback-keys-jpa/src/main/resources/spring-context.xml b/redback-keys/redback-keys-providers/redback-keys-jpa/src/main/resources/spring-context.xml new file mode 100644 index 00000000..6d066fd3 --- /dev/null +++ b/redback-keys/redback-keys-providers/redback-keys-jpa/src/main/resources/spring-context.xml @@ -0,0 +1,33 @@ + + + + + + + + + \ No newline at end of file diff --git a/redback-keys/redback-keys-providers/redback-keys-jpa/src/test/java/org/apache/archiva/redback/keys/jpa/JpaKeyManagerTest.java b/redback-keys/redback-keys-providers/redback-keys-jpa/src/test/java/org/apache/archiva/redback/keys/jpa/JpaKeyManagerTest.java new file mode 100644 index 00000000..0c34fbf5 --- /dev/null +++ b/redback-keys/redback-keys-providers/redback-keys-jpa/src/test/java/org/apache/archiva/redback/keys/jpa/JpaKeyManagerTest.java @@ -0,0 +1,65 @@ +package org.apache.archiva.redback.keys.jpa; + +/* + * 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.apache.archiva.redback.keys.KeyManagerTestCase; +import org.junit.Before; +import org.junit.Test; +import org.springframework.transaction.annotation.Transactional; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.persistence.EntityManagerFactory; + +/** + * JdoKeyManagerTest + * + * @author Martin Stockhammer + * + */ +@Transactional +public class JpaKeyManagerTest + extends KeyManagerTestCase +{ + + @Inject + EntityManagerFactory entityManagerFactory; + + @Inject + @Named(value = "keyManager#jpa") + KeyManager keyManager; + + + @Before + public void setUp() + throws Exception { + + super.setUp(); + super.setKeyManager(keyManager); + + } + + @Test + public void initialize() { + assertNotNull(keyManager); + } + +} diff --git a/redback-keys/redback-keys-providers/redback-keys-jpa/src/test/resources/spring-context.xml b/redback-keys/redback-keys-providers/redback-keys-jpa/src/test/resources/spring-context.xml new file mode 100644 index 00000000..2dea1856 --- /dev/null +++ b/redback-keys/redback-keys-providers/redback-keys-jpa/src/test/resources/spring-context.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/redback-keys/redback-keys-tests/src/main/java/org/apache/archiva/redback/keys/KeyManagerTestCase.java b/redback-keys/redback-keys-tests/src/main/java/org/apache/archiva/redback/keys/KeyManagerTestCase.java index 1cf154f2..b3c0f3c7 100644 --- a/redback-keys/redback-keys-tests/src/main/java/org/apache/archiva/redback/keys/KeyManagerTestCase.java +++ b/redback-keys/redback-keys-tests/src/main/java/org/apache/archiva/redback/keys/KeyManagerTestCase.java @@ -23,10 +23,7 @@ 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; +import java.util.*; /** * KeyManagerTestCase @@ -115,11 +112,14 @@ public class KeyManagerTestCase assertEquals( "bar", created2.getForPrincipal() ); assertEquals( "Something", created2.getPurpose() ); - List keys = getKeyManager().getAllKeys(); + System.out.println("foo key "+created1.getKey()); + System.out.println("bar key "+created2.getKey()); + List keys = new ArrayList(getKeyManager().getAllKeys()); Collections.sort( keys, new Comparator() { public int compare( AuthenticationKey key1, AuthenticationKey key2 ) { + System.out.println("Compare "+key2.getForPrincipal()+key2.getKey()+" - "+key1.getForPrincipal()+key1.getKey()); return key2.getForPrincipal().compareTo( key1.getForPrincipal() ); } } ); From 78e37f700ac8594800773b47e944c02d1fdc728e Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Sun, 6 Nov 2016 12:47:23 +0100 Subject: [PATCH 20/30] Change comments --- .../redback-keys-jpa/pom.xml | 18 +++++++++++++++ .../redback/keys/jpa/JpaKeyManager.java | 22 ++++++++++++++++++- .../keys/jpa/model/JpaAuthenticationKey.java | 22 ++++++++++++++++++- .../redback/users/jpa/JpaUserManagerTest.java | 5 ++++- 4 files changed, 64 insertions(+), 3 deletions(-) diff --git a/redback-keys/redback-keys-providers/redback-keys-jpa/pom.xml b/redback-keys/redback-keys-providers/redback-keys-jpa/pom.xml index f61e614b..7f43e99e 100644 --- a/redback-keys/redback-keys-providers/redback-keys-jpa/pom.xml +++ b/redback-keys/redback-keys-providers/redback-keys-jpa/pom.xml @@ -1,4 +1,22 @@ + diff --git a/redback-keys/redback-keys-providers/redback-keys-jpa/src/main/java/org/apache/archiva/redback/keys/jpa/JpaKeyManager.java b/redback-keys/redback-keys-providers/redback-keys-jpa/src/main/java/org/apache/archiva/redback/keys/jpa/JpaKeyManager.java index ab4a001d..0a934b41 100644 --- a/redback-keys/redback-keys-providers/redback-keys-jpa/src/main/java/org/apache/archiva/redback/keys/jpa/JpaKeyManager.java +++ b/redback-keys/redback-keys-providers/redback-keys-jpa/src/main/java/org/apache/archiva/redback/keys/jpa/JpaKeyManager.java @@ -1,5 +1,21 @@ package org.apache.archiva.redback.keys.jpa; +/* + * Copyright 2001-2016 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.apache.archiva.redback.keys.AbstractKeyManager; import org.apache.archiva.redback.keys.AuthenticationKey; import org.apache.archiva.redback.keys.KeyManagerException; @@ -15,7 +31,11 @@ import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; /** - * Created by martin on 27.10.16. + * Key Manager Implementation for JPA. + * + * Uses an injected Entity Manager. + * + * @author Martin Stockhammer */ @Service( "keyManager#jpa" ) public class JpaKeyManager extends AbstractKeyManager { diff --git a/redback-keys/redback-keys-providers/redback-keys-jpa/src/main/java/org/apache/archiva/redback/keys/jpa/model/JpaAuthenticationKey.java b/redback-keys/redback-keys-providers/redback-keys-jpa/src/main/java/org/apache/archiva/redback/keys/jpa/model/JpaAuthenticationKey.java index fba9952d..f747d026 100644 --- a/redback-keys/redback-keys-providers/redback-keys-jpa/src/main/java/org/apache/archiva/redback/keys/jpa/model/JpaAuthenticationKey.java +++ b/redback-keys/redback-keys-providers/redback-keys-jpa/src/main/java/org/apache/archiva/redback/keys/jpa/model/JpaAuthenticationKey.java @@ -1,5 +1,21 @@ package org.apache.archiva.redback.keys.jpa.model; +/* + * Copyright 2001-2016 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.apache.archiva.redback.keys.AuthenticationKey; import javax.persistence.Column; @@ -8,7 +24,11 @@ import javax.persistence.Table; import java.util.Date; /** - * Created by martin on 27.10.16. + * Authentication Key implementation for JPA. + * + * The table names are set to match the JDO tables. + * + * @author Martin Stockhammer */ @javax.persistence.Entity @Table(name="JDOAUTHENTICATIONKEY") diff --git a/redback-users/redback-users-providers/redback-users-jpa/src/test/java/org/apache/archiva/redback/users/jpa/JpaUserManagerTest.java b/redback-users/redback-users-providers/redback-users-jpa/src/test/java/org/apache/archiva/redback/users/jpa/JpaUserManagerTest.java index 97726979..cf77aa5a 100644 --- a/redback-users/redback-users-providers/redback-users-jpa/src/test/java/org/apache/archiva/redback/users/jpa/JpaUserManagerTest.java +++ b/redback-users/redback-users-providers/redback-users-jpa/src/test/java/org/apache/archiva/redback/users/jpa/JpaUserManagerTest.java @@ -49,7 +49,10 @@ import java.util.Map; import java.util.Properties; /** - * Created by martin on 21.09.16. + * + * Test for the JPA User Manager + * + * @author Martin Stockhammer */ @Transactional public class JpaUserManagerTest extends AbstractUserManagerTestCase { From 7482c06fcd2f2426ef7c8c6206444533e295bd4f Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Wed, 16 Nov 2016 21:07:08 +0100 Subject: [PATCH 21/30] Fix schema settings --- .../redback/rbac/jpa/model/JpaOperation.java | 2 +- .../redback/rbac/jpa/model/JpaPermission.java | 2 +- .../redback/rbac/jpa/model/JpaResource.java | 4 ++-- .../redback/rbac/jpa/model/JpaRole.java | 13 ++++++----- .../rbac/jpa/model/JpaUserAssignment.java | 23 +++++++++++++++---- .../redback/users/jpa/model/JpaUser.java | 14 +++++------ 6 files changed, 37 insertions(+), 21 deletions(-) diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaOperation.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaOperation.java index 66a41a15..aaf0af7a 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaOperation.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaOperation.java @@ -39,7 +39,7 @@ public class JpaOperation implements Operation, Serializable { private String name; @Column(name="DESCRIPTION") private String description; - @Column(name="PERMANENT") + @Column(name="PERMANENT", nullable = false) private boolean permanent; diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaPermission.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaPermission.java index 1e83d2b9..218cbc7d 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaPermission.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaPermission.java @@ -39,7 +39,7 @@ public class JpaPermission implements Permission,Serializable { private String name; @Column(name="DESCRIPTION") private String description; - @Column(name="PERMANENT") + @Column(name="PERMANENT", nullable = false) private boolean permanent; @ManyToOne(cascade = CascadeType.ALL) @JoinColumn( diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaResource.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaResource.java index fc7ee777..dd2f3f42 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaResource.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaResource.java @@ -37,9 +37,9 @@ public class JpaResource implements Resource, Serializable { @Id @Column(name="IDENTIFIER") private String identifier; - @Column(name="PATTERN") + @Column(name="PATTERN", nullable = false) private boolean pattern; - @Column(name="PERMANENT") + @Column(name="PERMANENT", nullable = false) private boolean permanent; diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaRole.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaRole.java index 5a7cdc7e..425fa35c 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaRole.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaRole.java @@ -42,15 +42,15 @@ public class JpaRole extends AbstractRole implements Serializable { private String name; @Column(name="DESCRIPTION") private String description; - @Column(name="ASSIGNABLE") + @Column(name="ASSIGNABLE",nullable = false) private boolean assignable; - @Column(name="PERMANENT") + @Column(name="PERMANENT", nullable = false) private boolean permanent; @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) - @OrderColumn(name="INTEGER_IDX") + @OrderColumn(name="INTEGER_IDX", nullable = false) @JoinTable( name="SECURITY_ROLE_PERMISSION_MAP", - joinColumns={ @JoinColumn(name="NAME_OID", referencedColumnName="NAME") }, + joinColumns={ @JoinColumn(name="NAME_OID", referencedColumnName="NAME", nullable = false) }, inverseJoinColumns = { @JoinColumn(name="NAME_EID",referencedColumnName = "NAME") } @@ -58,11 +58,12 @@ public class JpaRole extends AbstractRole implements Serializable { List permissions = new ArrayList(); @ElementCollection(fetch = FetchType.EAGER) - @OrderColumn(name="INTEGER_IDX") + @OrderColumn(name="INTEGER_IDX",nullable = false) + @Column(name="STRING_ELE") @CollectionTable( name="SECURITY_ROLE_CHILDROLE_MAP", joinColumns = { - @JoinColumn(name="NAME_OID",referencedColumnName = "NAME") + @JoinColumn(name="NAME_OID",referencedColumnName = "NAME", nullable = false) } ) List childRoleNames = new ArrayList(); diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaUserAssignment.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaUserAssignment.java index f0b3d542..3b6853c8 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaUserAssignment.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaUserAssignment.java @@ -20,6 +20,7 @@ package org.apache.archiva.redback.rbac.jpa.model; */ import org.apache.archiva.redback.rbac.AbstractUserAssignment; +import org.apache.archiva.redback.rbac.UserAssignment; import javax.persistence.CollectionTable; import javax.persistence.Column; @@ -32,6 +33,7 @@ import javax.persistence.OrderColumn; import javax.persistence.Table; import java.io.Serializable; import java.util.ArrayList; +import java.util.Date; import java.util.List; /** @@ -39,7 +41,7 @@ import java.util.List; */ @Entity @Table(name="SECURITY_USER_ASSIGNMENTS") -public class JpaUserAssignment extends AbstractUserAssignment implements Serializable { +public class JpaUserAssignment extends AbstractUserAssignment implements UserAssignment,Serializable { @Id @@ -47,17 +49,20 @@ public class JpaUserAssignment extends AbstractUserAssignment implements Seriali private String principal; @ElementCollection(fetch = FetchType.EAGER) @Column(name="STRING_ELE") - @OrderColumn(name="INTEGER_IDX") + @OrderColumn(name="INTEGER_IDX", nullable = false) @CollectionTable( name="SECURITY_USERASSIGNMENT_ROLENAMES", joinColumns = { - @JoinColumn(name = "PRINCIPAL_OID", referencedColumnName = "PRINCIPAL") + @JoinColumn(name = "PRINCIPAL_OID", referencedColumnName = "PRINCIPAL", nullable = false) } ) private List roleNames = new ArrayList(); - @Column(name="PERMANENT") + @Column(name="PERMANENT", nullable = false) private boolean permanent = false; + @Column(name="LAST_UPDATED") + private Date timestamp; + @Override public String getPrincipal() { return principal; @@ -103,4 +108,14 @@ public class JpaUserAssignment extends AbstractUserAssignment implements Seriali public int hashCode() { return principal.hashCode(); } + + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + } diff --git a/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/model/JpaUser.java b/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/model/JpaUser.java index f1c79e20..cf45ba37 100644 --- a/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/model/JpaUser.java +++ b/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/model/JpaUser.java @@ -51,21 +51,21 @@ public class JpaUser implements org.apache.archiva.redback.users.User { @Column(name="LAST_PASSWORD_CHANGE") private Date lastPasswordChange; @ElementCollection(fetch = FetchType.EAGER) - @OrderColumn(name="INTEGER_IDX") + @OrderColumn(name="INTEGER_IDX", nullable = false) @Column(name="STRING_ELE") @CollectionTable(name="JDOUSER_PREVIOUSENCODEDPASSWORDS", - joinColumns = @JoinColumn(name = "USERNAME_OID", referencedColumnName = "USERNAME") + joinColumns = @JoinColumn(name = "USERNAME_OID", nullable = false, referencedColumnName = "USERNAME") ) private List previousEncodedPasswords = new ArrayList(); - @Column(name="PERMANENT") + @Column(name="PERMANENT", nullable = false) private boolean permanent; - @Column(name="LOCKED") + @Column(name="LOCKED", nullable = false) private boolean locked; - @Column(name="PASSWORD_CHANGE_REQUIRED") + @Column(name="PASSWORD_CHANGE_REQUIRED", nullable = false) private boolean passwordChangeRequired; - @Column(name="VALIDATED") + @Column(name="VALIDATED", nullable = false) private boolean validated; - @Column(name="COUNT_FAILED_LOGIN_ATTEMPTS") + @Column(name="COUNT_FAILED_LOGIN_ATTEMPTS",nullable = false) private int countFailedLoginAttempts; @Column(name="ACCOUNT_CREATION_DATE") private Date accountCreationDate; From e55262c8cca26d2c838185a993f5c792a1863ea0 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Sat, 19 Nov 2016 23:26:08 +0100 Subject: [PATCH 22/30] Add schema changes for compatibility with JDO implementation --- .../main/resources/META-INF/persistence.xml | 1 + .../redback/rbac/jpa/model/JpaOperation.java | 2 +- .../redback/rbac/jpa/model/JpaPermission.java | 2 +- .../redback/rbac/jpa/model/JpaResource.java | 8 ++++---- .../redback/rbac/jpa/model/JpaRole.java | 4 ++-- .../rbac/jpa/model/JpaUserAssignment.java | 2 +- .../redback/users/jpa/model/JpaUser.java | 18 +++++++++++------- 7 files changed, 21 insertions(+), 16 deletions(-) diff --git a/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence.xml b/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence.xml index 6d9f1afa..602cd977 100644 --- a/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence.xml +++ b/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence.xml @@ -34,6 +34,7 @@ + diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaOperation.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaOperation.java index aaf0af7a..bf9e7477 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaOperation.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaOperation.java @@ -40,7 +40,7 @@ public class JpaOperation implements Operation, Serializable { @Column(name="DESCRIPTION") private String description; @Column(name="PERMANENT", nullable = false) - private boolean permanent; + private Boolean permanent = false; @Override diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaPermission.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaPermission.java index 218cbc7d..ed3928a6 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaPermission.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaPermission.java @@ -40,7 +40,7 @@ public class JpaPermission implements Permission,Serializable { @Column(name="DESCRIPTION") private String description; @Column(name="PERMANENT", nullable = false) - private boolean permanent; + private Boolean permanent = false; @ManyToOne(cascade = CascadeType.ALL) @JoinColumn( name="OPERATION_NAME_OID", diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaResource.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaResource.java index dd2f3f42..19da451d 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaResource.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaResource.java @@ -37,10 +37,10 @@ public class JpaResource implements Resource, Serializable { @Id @Column(name="IDENTIFIER") private String identifier; - @Column(name="PATTERN", nullable = false) - private boolean pattern; - @Column(name="PERMANENT", nullable = false) - private boolean permanent; + @Column(name="PATTERN", nullable = false, columnDefinition = "CHAR(1)") + private Boolean pattern = false; + @Column(name="PERMANENT", nullable = false, columnDefinition = "CHAR(1)") + private Boolean permanent = false; @Override diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaRole.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaRole.java index 425fa35c..565409b1 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaRole.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaRole.java @@ -43,9 +43,9 @@ public class JpaRole extends AbstractRole implements Serializable { @Column(name="DESCRIPTION") private String description; @Column(name="ASSIGNABLE",nullable = false) - private boolean assignable; + private Boolean assignable = false; @Column(name="PERMANENT", nullable = false) - private boolean permanent; + private Boolean permanent = false; @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @OrderColumn(name="INTEGER_IDX", nullable = false) @JoinTable( diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaUserAssignment.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaUserAssignment.java index 3b6853c8..7e64bdd1 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaUserAssignment.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaUserAssignment.java @@ -58,7 +58,7 @@ public class JpaUserAssignment extends AbstractUserAssignment implements UserAss ) private List roleNames = new ArrayList(); @Column(name="PERMANENT", nullable = false) - private boolean permanent = false; + private Boolean permanent = false; @Column(name="LAST_UPDATED") private Date timestamp; diff --git a/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/model/JpaUser.java b/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/model/JpaUser.java index cf45ba37..e5ee5eb4 100644 --- a/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/model/JpaUser.java +++ b/redback-users/redback-users-providers/redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/model/JpaUser.java @@ -19,6 +19,9 @@ package org.apache.archiva.redback.users.jpa.model; * under the License. */ +import org.apache.openjpa.persistence.ExternalValues; +import org.apache.openjpa.persistence.Type; + import javax.persistence.CollectionTable; import javax.persistence.Column; import javax.persistence.ElementCollection; @@ -26,6 +29,7 @@ import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.Id; import javax.persistence.JoinColumn; +import javax.persistence.OneToMany; import javax.persistence.OrderColumn; import javax.persistence.Table; import java.util.ArrayList; @@ -52,26 +56,26 @@ public class JpaUser implements org.apache.archiva.redback.users.User { private Date lastPasswordChange; @ElementCollection(fetch = FetchType.EAGER) @OrderColumn(name="INTEGER_IDX", nullable = false) - @Column(name="STRING_ELE") + @Column(name="STRING_ELE", nullable = false) @CollectionTable(name="JDOUSER_PREVIOUSENCODEDPASSWORDS", joinColumns = @JoinColumn(name = "USERNAME_OID", nullable = false, referencedColumnName = "USERNAME") ) private List previousEncodedPasswords = new ArrayList(); @Column(name="PERMANENT", nullable = false) - private boolean permanent; + private Boolean permanent = false; @Column(name="LOCKED", nullable = false) - private boolean locked; + private Boolean locked = false; @Column(name="PASSWORD_CHANGE_REQUIRED", nullable = false) - private boolean passwordChangeRequired; + private Boolean passwordChangeRequired = false; @Column(name="VALIDATED", nullable = false) - private boolean validated; + private Boolean validated = false; @Column(name="COUNT_FAILED_LOGIN_ATTEMPTS",nullable = false) - private int countFailedLoginAttempts; + private int countFailedLoginAttempts = 0; @Column(name="ACCOUNT_CREATION_DATE") private Date accountCreationDate; @Column(name="LAST_LOGIN_DATE") private Date lastLoginDate; - @Column(name="USER_PASSSWORD") + @Column(name="USER_PASSWORD") private String rawPassword; From 09b5fab0d26e9c80b8a7bf718ee9ece72eb9084b Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Mon, 5 Dec 2016 21:14:56 +1100 Subject: [PATCH 23/30] fix duplicate dependency Signed-off-by: olivier lamy --- pom.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pom.xml b/pom.xml index cdb4c899..18cce4f1 100644 --- a/pom.xml +++ b/pom.xml @@ -316,11 +316,6 @@ redback-common-jpa 2.5-SNAPSHOT - - org.apache.archiva.redback - redback-users-jpa - 2.5-SNAPSHOT - javax.servlet servlet-api From 96b6771e7fcbe4c7f5f2346c3c54d7eb1460db83 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Wed, 28 Dec 2016 19:52:28 +0100 Subject: [PATCH 24/30] Remove schema types in annotation --- .../apache/archiva/redback/rbac/jpa/model/JpaResource.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaResource.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaResource.java index 19da451d..d18b81c6 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaResource.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/model/JpaResource.java @@ -37,9 +37,9 @@ public class JpaResource implements Resource, Serializable { @Id @Column(name="IDENTIFIER") private String identifier; - @Column(name="PATTERN", nullable = false, columnDefinition = "CHAR(1)") + @Column(name="PATTERN", nullable = false) private Boolean pattern = false; - @Column(name="PERMANENT", nullable = false, columnDefinition = "CHAR(1)") + @Column(name="PERMANENT", nullable = false) private Boolean permanent = false; From 2add792524d77fc26a68c50dae0f64410aa8507c Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Fri, 30 Dec 2016 15:33:17 +0100 Subject: [PATCH 25/30] Set JPA as default and only database backend Remove JDO dependencies and set the JPA implementations as only implementation for database backend providers. Uses the same database as JDO before. --- pom.xml | 18 +- .../resources/META-INF/persistence-hsqldb.xml | 5 +- .../main/resources/META-INF/persistence.xml | 8 +- .../redback/config-defaults.properties | 2 +- redback-data-management/pom.xml | 10 +- .../management/JdoDataManagementTool.java | 307 ------------------ .../management/DataManagementTest.java | 22 +- .../src/test/resources/spring-context.xml | 19 -- .../integration/mail/MailGeneratorTest.java | 40 +-- .../src/test/resources/spring-context.xml | 14 - .../redback-rest-services/pom.xml | 4 + .../rest/services/DefaultLoginService.java | 4 +- .../services/FakeCreateAdminServiceImpl.java | 4 +- .../src/test/resources/security.properties | 2 +- redback-keys/redback-keys-providers/pom.xml | 3 +- .../redback-keys-cached/pom.xml | 6 +- .../redback/keys/cached/CachedKeyManager.java | 2 +- .../src/test/resources/spring-context.xml | 44 ++- redback-rbac/redback-rbac-providers/pom.xml | 3 +- .../redback-rbac-cached/pom.xml | 4 - .../rbac/cached/CachedRbacManager.java | 2 +- .../src/test/resources/spring-context.xml | 13 - .../redback/rbac/jpa/JpaRbacManager.java | 22 +- .../redback/rbac/jpa/JpaRbacManagerTest.java | 1 - .../redback-rbac-ldap/pom.xml | 4 - .../src/test/resources/spring-context.xml | 14 - .../src/test/resources/spring-context.xml | 13 - .../redback-rbac-role-manager/pom.xml | 9 - .../redback/role/JpoxRoleManagerTest.java | 36 +- .../test/resources/jpox-spring-context.xml | 31 +- .../src/test/resources/spring-context.xml | 13 - .../src/test/resources/spring-context.xml | 12 - redback-users/redback-users-providers/pom.xml | 1 - .../redback-users-cached/pom.xml | 4 - 34 files changed, 113 insertions(+), 583 deletions(-) delete mode 100644 redback-data-management/src/main/java/org/apache/archiva/redback/management/JdoDataManagementTool.java diff --git a/pom.xml b/pom.xml index 18cce4f1..c2b68e49 100644 --- a/pom.xml +++ b/pom.xml @@ -146,11 +146,6 @@ redback-policy ${project.version} - - org.apache.archiva.redback - redback-common-jdo - ${project.version} - org.apache.archiva.redback redback-common-ldap @@ -183,7 +178,7 @@ org.apache.archiva.redback - redback-keys-jdo + redback-keys-jpa ${project.version} @@ -216,11 +211,6 @@ redback-users-api ${project.version} - - org.apache.archiva.redback - redback-users-jdo - ${project.version} - org.apache.archiva.redback redback-users-jpa @@ -276,11 +266,6 @@ redback-rbac-cached ${project.version} - - org.apache.archiva.redback - redback-rbac-jdo - ${project.version} - org.apache.archiva.redback redback-rbac-jpa @@ -831,6 +816,7 @@ build-number.txt .idea/** + **/*.iml .project .classpath diff --git a/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence-hsqldb.xml b/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence-hsqldb.xml index 82da347e..54255d98 100644 --- a/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence-hsqldb.xml +++ b/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence-hsqldb.xml @@ -32,10 +32,13 @@ - + + + + diff --git a/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence.xml b/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence.xml index 602cd977..8ea770a1 100644 --- a/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence.xml +++ b/redback-common/redback-common-jpa/src/main/resources/META-INF/persistence.xml @@ -20,7 +20,7 @@ org.apache.openjpa.persistence.PersistenceProviderImpl - java:comp/env/jdbc/redbackjpa + java:comp/env/jdbc/users org.apache.archiva.redback.users.jpa.model.JpaUser org.apache.archiva.redback.rbac.jpa.model.JpaOperation org.apache.archiva.redback.rbac.jpa.model.JpaResource @@ -31,10 +31,10 @@ - - - + + diff --git a/redback-configuration/src/main/resources/org/apache/archiva/redback/config-defaults.properties b/redback-configuration/src/main/resources/org/apache/archiva/redback/config-defaults.properties index 402aaf97..78ff0473 100644 --- a/redback-configuration/src/main/resources/org/apache/archiva/redback/config-defaults.properties +++ b/redback-configuration/src/main/resources/org/apache/archiva/redback/config-defaults.properties @@ -130,7 +130,7 @@ ldap.bind.authenticator.enabled=false #ldap.config.authentication.method= # config parameter for the ConfigurableUserManager -user.manager.impl=jdo +user.manager.impl=jpa diff --git a/redback-data-management/pom.xml b/redback-data-management/pom.xml index c232c3a5..a882f785 100644 --- a/redback-data-management/pom.xml +++ b/redback-data-management/pom.xml @@ -35,15 +35,15 @@ org.apache.archiva.redback - redback-rbac-jdo + redback-users-api org.apache.archiva.redback - redback-keys-jdo + redback-rbac-model org.apache.archiva.redback - redback-users-jdo + redback-keys-api org.springframework @@ -88,6 +88,10 @@ jul-to-slf4j test + + org.hsqldb + hsqldb + diff --git a/redback-data-management/src/main/java/org/apache/archiva/redback/management/JdoDataManagementTool.java b/redback-data-management/src/main/java/org/apache/archiva/redback/management/JdoDataManagementTool.java deleted file mode 100644 index 7b625b70..00000000 --- a/redback-data-management/src/main/java/org/apache/archiva/redback/management/JdoDataManagementTool.java +++ /dev/null @@ -1,307 +0,0 @@ -package org.apache.archiva.redback.management; - -/* - * 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 java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.xml.stream.XMLStreamException; - -import org.apache.archiva.redback.keys.AuthenticationKey; -import org.apache.archiva.redback.keys.KeyManager; -import org.apache.archiva.redback.keys.jdo.AuthenticationKeyDatabase; -import org.apache.archiva.redback.keys.jdo.io.stax.RedbackKeyManagementJdoStaxReader; -import org.apache.archiva.redback.keys.jdo.io.stax.RedbackKeyManagementJdoStaxWriter; -import org.apache.archiva.redback.rbac.Operation; -import org.apache.archiva.redback.rbac.Permission; -import org.apache.archiva.redback.rbac.RbacManagerException; -import org.apache.archiva.redback.rbac.Role; -import org.apache.archiva.redback.rbac.jdo.RbacDatabase; -import org.apache.archiva.redback.rbac.jdo.io.stax.RbacJdoModelStaxReader; -import org.apache.archiva.redback.rbac.jdo.io.stax.RbacJdoModelStaxWriter; -import org.apache.archiva.redback.users.UserManager; -import org.apache.archiva.redback.keys.KeyManagerException; -import org.apache.archiva.redback.rbac.RBACManager; -import org.apache.archiva.redback.rbac.Resource; -import org.apache.archiva.redback.rbac.UserAssignment; -import org.apache.archiva.redback.users.User; -import org.apache.archiva.redback.users.UserManagerException; -import org.apache.archiva.redback.users.jdo.UserDatabase; -import org.apache.archiva.redback.users.jdo.io.stax.UsersManagementStaxReader; -import org.apache.archiva.redback.users.jdo.io.stax.UsersManagementStaxWriter; -import org.apache.commons.io.IOUtils; -import org.springframework.stereotype.Service; - -/** - * JDO implementation of the data management tool. - * - * TODO do we really need JDO specifics here? Could optimize by going straight to JDOFactory - * TODO check whether this current method logs everything unnecessarily. - */ -@Service("dataManagementTool#jdo") -public class JdoDataManagementTool - implements DataManagementTool -{ - private static final String USERS_XML_NAME = "users.xml"; - - private static final String KEYS_XML_NAME = "keys.xml"; - - private static final String RBAC_XML_NAME = "rbac.xml"; - - public void backupRBACDatabase( RBACManager manager, File backupDirectory ) - throws RbacManagerException, IOException, XMLStreamException - { - RbacDatabase database = new RbacDatabase(); - database.setRoles( manager.getAllRoles() ); - database.setUserAssignments( manager.getAllUserAssignments() ); - database.setPermissions( manager.getAllPermissions() ); - database.setOperations( manager.getAllOperations() ); - database.setResources( manager.getAllResources() ); - - RbacJdoModelStaxWriter writer = new RbacJdoModelStaxWriter(); - Writer fileWriter = createWriter( backupDirectory, RBAC_XML_NAME, database.getModelEncoding() ); - try - { - writer.write( fileWriter, database ); - } - finally - { - IOUtils.closeQuietly( fileWriter ); - } - } - - public void backupUserDatabase( UserManager manager, File backupDirectory ) - throws IOException, XMLStreamException, UserManagerException - { - UserDatabase database = new UserDatabase(); - database.setUsers( manager.getUsers() ); - - UsersManagementStaxWriter writer = new UsersManagementStaxWriter(); - Writer fileWriter = createWriter( backupDirectory, USERS_XML_NAME, database.getModelEncoding() ); - try - { - writer.write( fileWriter, database ); - } - finally - { - IOUtils.closeQuietly( fileWriter ); - } - } - - public void backupKeyDatabase( KeyManager manager, File backupDirectory ) - throws IOException, XMLStreamException - { - try - { - manager.removeExpiredKeys(); - } - catch ( KeyManagerException e ) - { - throw new IOException( "Error removing expired keys" ); - } - - AuthenticationKeyDatabase database = new AuthenticationKeyDatabase(); - database.setKeys( manager.getAllKeys() ); - - RedbackKeyManagementJdoStaxWriter writer = new RedbackKeyManagementJdoStaxWriter(); - Writer fileWriter = createWriter( backupDirectory, KEYS_XML_NAME, database.getModelEncoding() ); - try - { - writer.write( fileWriter, database ); - } - finally - { - IOUtils.closeQuietly( fileWriter ); - } - } - - @SuppressWarnings("unchecked") - public void restoreRBACDatabase( RBACManager manager, File backupDirectory ) - throws IOException, XMLStreamException, RbacManagerException - { - RbacJdoModelStaxReader reader = new RbacJdoModelStaxReader(); - - FileReader fileReader = new FileReader( new File( backupDirectory, RBAC_XML_NAME ) ); - - RbacDatabase database; - try - { - database = reader.read( fileReader ); - } - finally - { - IOUtils.closeQuietly( fileReader ); - } - - Map permissionMap = new HashMap(); - Map resources = new HashMap(); - Map operations = new HashMap(); - for ( Role role : (List) database.getRoles() ) - { - // TODO: this could be generally useful and put into saveRole itself as long as the performance penalty isn't too harsh. - // Currently it always saves everything where it could pull pack the existing permissions, etc if they exist - List permissions = new ArrayList(); - for ( Permission permission : role.getPermissions() ) - { - if ( permissionMap.containsKey( permission.getName() ) ) - { - permission = permissionMap.get( permission.getName() ); - } - else if ( manager.permissionExists( permission ) ) - { - permission = manager.getPermission( permission.getName() ); - permissionMap.put( permission.getName(), permission ); - } - else - { - Operation operation = permission.getOperation(); - if ( operations.containsKey( operation.getName() ) ) - { - operation = operations.get( operation.getName() ); - } - else if ( manager.operationExists( operation ) ) - { - operation = manager.getOperation( operation.getName() ); - operations.put( operation.getName(), operation ); - } - else - { - operation = manager.saveOperation( operation ); - operations.put( operation.getName(), operation ); - } - permission.setOperation( operation ); - - Resource resource = permission.getResource(); - if ( resources.containsKey( resource.getIdentifier() ) ) - { - resource = resources.get( resource.getIdentifier() ); - } - else if ( manager.resourceExists( resource ) ) - { - resource = manager.getResource( resource.getIdentifier() ); - resources.put( resource.getIdentifier(), resource ); - } - else - { - resource = manager.saveResource( resource ); - resources.put( resource.getIdentifier(), resource ); - } - permission.setResource( resource ); - - permission = manager.savePermission( permission ); - permissionMap.put( permission.getName(), permission ); - } - permissions.add( permission ); - } - role.setPermissions( permissions ); - - manager.saveRole( role ); - } - - for ( UserAssignment userAssignment : (List) database.getUserAssignments() ) - { - manager.saveUserAssignment( userAssignment ); - } - } - - @SuppressWarnings("unchecked") - public void restoreUsersDatabase( UserManager manager, File backupDirectory ) - throws IOException, XMLStreamException, UserManagerException - { - UsersManagementStaxReader reader = new UsersManagementStaxReader(); - - FileReader fileReader = new FileReader( new File( backupDirectory, USERS_XML_NAME ) ); - - UserDatabase database; - try - { - database = reader.read( fileReader ); - } - finally - { - IOUtils.closeQuietly( fileReader ); - } - - for ( User user : (List) database.getUsers() ) - { - manager.addUserUnchecked( user ); - } - } - - @SuppressWarnings("unchecked") - public void restoreKeysDatabase( KeyManager manager, File backupDirectory ) - throws IOException, XMLStreamException - { - RedbackKeyManagementJdoStaxReader reader = new RedbackKeyManagementJdoStaxReader(); - - FileReader fileReader = new FileReader( new File( backupDirectory, KEYS_XML_NAME ) ); - - AuthenticationKeyDatabase database; - try - { - database = reader.read( fileReader ); - } - finally - { - IOUtils.closeQuietly( fileReader ); - } - - for ( AuthenticationKey key : (List) database.getKeys() ) - { - manager.addKey( key ); - } - } - - public void eraseRBACDatabase( RBACManager manager ) - { - manager.eraseDatabase(); - } - - public void eraseUsersDatabase( UserManager manager ) - { - manager.eraseDatabase(); - } - - public void eraseKeysDatabase( KeyManager manager ) - { - manager.eraseDatabase(); - } - - private Writer createWriter( File directory, String file, String encoding ) - throws FileNotFoundException - { - File f = new File( directory, file ); - File parentFile = f.getParentFile(); - parentFile.mkdirs(); - - FileOutputStream out = new FileOutputStream( f ); - return new OutputStreamWriter( out, Charset.forName( encoding ) ); - } -} diff --git a/redback-data-management/src/test/java/org/apache/archiva/redback/management/DataManagementTest.java b/redback-data-management/src/test/java/org/apache/archiva/redback/management/DataManagementTest.java index 461337a5..3a781829 100644 --- a/redback-data-management/src/test/java/org/apache/archiva/redback/management/DataManagementTest.java +++ b/redback-data-management/src/test/java/org/apache/archiva/redback/management/DataManagementTest.java @@ -20,24 +20,24 @@ package org.apache.archiva.redback.management; */ import junit.framework.TestCase; -import org.apache.archiva.redback.common.jdo.UserConfigurableJdoFactory; import org.apache.archiva.redback.keys.AuthenticationKey; import org.apache.archiva.redback.keys.KeyManager; +import org.apache.archiva.redback.keys.KeyManagerException; import org.apache.archiva.redback.rbac.Permission; import org.apache.archiva.redback.rbac.RBACManager; +import org.apache.archiva.redback.rbac.RbacManagerException; import org.apache.archiva.redback.rbac.Role; import org.apache.archiva.redback.rbac.UserAssignment; +import org.apache.archiva.redback.tests.utils.RBACDefaults; +import org.apache.archiva.redback.users.User; import org.apache.archiva.redback.users.UserManager; import org.apache.archiva.redback.users.UserManagerException; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.SystemUtils; -import org.apache.archiva.redback.keys.KeyManagerException; -import org.apache.archiva.redback.rbac.RbacManagerException; -import org.apache.archiva.redback.tests.utils.RBACDefaults; -import org.apache.archiva.redback.users.User; import org.custommonkey.xmlunit.XMLAssert; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; @@ -57,6 +57,8 @@ import java.util.List; import java.util.Locale; +// @TODO: Investigate how to implement export with JPA +@Ignore("Currently no JPA implementation") @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" }) public class DataManagementTest @@ -68,20 +70,16 @@ public class DataManagementTest private File targetDirectory; @Inject - @Named(value = "jdoFactory#users") - UserConfigurableJdoFactory jdoFactory; - - @Inject - @Named(value = "userManager#jdo") + @Named(value = "userManager#jpa") UserManager userManager; @Inject - @Named(value = "keyManager#jdo") + @Named(value = "keyManager#jpa") KeyManager keyManager; @Inject - @Named(value = "rbacManager#jdo") + @Named(value = "rbacManager#jpa") RBACManager rbacManager; @Before diff --git a/redback-data-management/src/test/resources/spring-context.xml b/redback-data-management/src/test/resources/spring-context.xml index 54b5521f..6bf30d57 100644 --- a/redback-data-management/src/test/resources/spring-context.xml +++ b/redback-data-management/src/test/resources/spring-context.xml @@ -28,25 +28,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - JDK_DEFAULT_TIMEZONE - true - - - + http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> @@ -60,4 +46,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/redback-rbac/redback-rbac-providers/pom.xml b/redback-rbac/redback-rbac-providers/pom.xml index a94d451d..81afcadd 100644 --- a/redback-rbac/redback-rbac-providers/pom.xml +++ b/redback-rbac/redback-rbac-providers/pom.xml @@ -28,10 +28,9 @@ Redback :: RBAC Providers pom - redback-rbac-jdo + redback-rbac-jpa redback-rbac-memory redback-rbac-cached redback-rbac-ldap - redback-rbac-jpa diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-cached/pom.xml b/redback-rbac/redback-rbac-providers/redback-rbac-cached/pom.xml index bb25053c..921bcb70 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-cached/pom.xml +++ b/redback-rbac/redback-rbac-providers/redback-rbac-cached/pom.xml @@ -64,10 +64,6 @@ javax.annotation jsr250-api - - org.apache.archiva.redback - redback-rbac-jdo - org.apache.archiva.redback redback-rbac-jpa diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-cached/src/main/java/org/apache/archiva/redback/rbac/cached/CachedRbacManager.java b/redback-rbac/redback-rbac-providers/redback-rbac-cached/src/main/java/org/apache/archiva/redback/rbac/cached/CachedRbacManager.java index b69b0e81..61c62eee 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-cached/src/main/java/org/apache/archiva/redback/rbac/cached/CachedRbacManager.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-cached/src/main/java/org/apache/archiva/redback/rbac/cached/CachedRbacManager.java @@ -54,7 +54,7 @@ public class CachedRbacManager private Logger log = LoggerFactory.getLogger( getClass() ); @Inject - @Named( value = "rbacManager#jdo" ) + @Named( value = "rbacManager#jpa" ) private RBACManager rbacImpl; @Inject diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-cached/src/test/resources/spring-context.xml b/redback-rbac/redback-rbac-providers/redback-rbac-cached/src/test/resources/spring-context.xml index 71c14e2f..cde60702 100755 --- a/redback-rbac/redback-rbac-providers/redback-rbac-cached/src/test/resources/spring-context.xml +++ b/redback-rbac/redback-rbac-providers/redback-rbac-cached/src/test/resources/spring-context.xml @@ -24,19 +24,6 @@ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd" default-lazy-init="false"> - - - - - - - - - JDK_DEFAULT_TIMEZONE - true - - - diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java index ea219e99..09d3bc79 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/main/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManager.java @@ -31,6 +31,7 @@ import javax.persistence.*; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; /** @@ -73,6 +74,18 @@ public class JpaRbacManager extends AbstractRBACManager { return mergedRole; } + @Transactional + @Override + public Map> getAssignedPermissionMap(String principal) throws RbacManagerException { + return super.getAssignedPermissionMap(principal); + } + + @Transactional + @Override + public Map getChildRoles(Role role) throws RbacManagerException { + return super.getChildRoles(role); + } + @Transactional @Override public void addChildRole(Role role, Role childRole) throws RbacObjectInvalidException, RbacManagerException { @@ -105,7 +118,14 @@ public class JpaRbacManager extends AbstractRBACManager { final EntityManager em = getEm(); TypedQuery q = em.createQuery("SELECT r FROM JpaRole r WHERE r.name = :rolename", JpaRole.class); q.setParameter("rolename",roleName); - return q.getSingleResult(); + Role role; + try { + role = q.getSingleResult(); + } catch (NoResultException ex) { + log.warn("Role {0} not found", roleName); + throw new RbacObjectNotFoundException("Role not found "+roleName); + } + return role; } @Override diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/test/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManagerTest.java b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/test/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManagerTest.java index cfc34f46..082d1ea8 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/test/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManagerTest.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/src/test/java/org/apache/archiva/redback/rbac/jpa/JpaRbacManagerTest.java @@ -19,7 +19,6 @@ package org.apache.archiva.redback.rbac.jpa; * under the License. */ -import org.apache.archiva.redback.common.jdo.test.StoreManagerDebug; import org.apache.archiva.redback.rbac.RBACManager; import org.apache.archiva.redback.rbac.RbacManagerException; import org.apache.archiva.redback.tests.AbstractRbacManagerTestCase; diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-ldap/pom.xml b/redback-rbac/redback-rbac-providers/redback-rbac-ldap/pom.xml index 7f2afc33..fd100f5a 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-ldap/pom.xml +++ b/redback-rbac/redback-rbac-providers/redback-rbac-ldap/pom.xml @@ -72,10 +72,6 @@ org.apache.archiva.redback redback-users-ldap - - org.apache.archiva.redback - redback-rbac-jdo - org.apache.archiva.redback redback-rbac-cached diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/resources/spring-context.xml b/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/resources/spring-context.xml index beae9e07..b92edd4a 100755 --- a/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/resources/spring-context.xml +++ b/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/resources/spring-context.xml @@ -63,20 +63,6 @@ - - - - - - - - - JDK_DEFAULT_TIMEZONE - true - - - - diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/test/resources/spring-context.xml b/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/test/resources/spring-context.xml index cec014ea..781d2b31 100755 --- a/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/test/resources/spring-context.xml +++ b/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/test/resources/spring-context.xml @@ -23,19 +23,6 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> - - - - - - - - - JDK_DEFAULT_TIMEZONE - true - - - diff --git a/redback-rbac/redback-rbac-role-manager/pom.xml b/redback-rbac/redback-rbac-role-manager/pom.xml index 6930efaa..9586536f 100644 --- a/redback-rbac/redback-rbac-role-manager/pom.xml +++ b/redback-rbac/redback-rbac-role-manager/pom.xml @@ -62,19 +62,10 @@ org.apache.archiva.redback test - - redback-rbac-jdo - org.apache.archiva.redback - test - org.apache.archiva.redback redback-rbac-model - - org.apache.archiva.redback - redback-common-jdo - org.apache.archiva.redback redback-rbac-cached diff --git a/redback-rbac/redback-rbac-role-manager/src/test/java/org/apache/archiva/redback/role/JpoxRoleManagerTest.java b/redback-rbac/redback-rbac-role-manager/src/test/java/org/apache/archiva/redback/role/JpoxRoleManagerTest.java index 53a84cab..3ebbe025 100644 --- a/redback-rbac/redback-rbac-role-manager/src/test/java/org/apache/archiva/redback/role/JpoxRoleManagerTest.java +++ b/redback-rbac/redback-rbac-role-manager/src/test/java/org/apache/archiva/redback/role/JpoxRoleManagerTest.java @@ -19,8 +19,7 @@ package org.apache.archiva.redback.role; * under the License. */ -import org.apache.archiva.redback.rbac.jdo.JdoRbacManager; -import org.apache.archiva.redback.components.jdo.DefaultConfigurableJdoFactory; +import org.apache.archiva.redback.rbac.RBACManager; import org.junit.Before; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; @@ -28,8 +27,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import javax.inject.Inject; import javax.inject.Named; -import javax.jdo.PersistenceManager; -import javax.jdo.PersistenceManagerFactory; /** * RoleManagerTest: @@ -41,38 +38,31 @@ import javax.jdo.PersistenceManagerFactory; public class JpoxRoleManagerTest extends AbstractRoleManagerTest { - @Inject - @Named( value = "jdoFactory#users" ) - DefaultConfigurableJdoFactory jdoFactory; - - @Inject - @Named( value = "rbacManager#jdo" ) - JdoRbacManager rbacManagerJdo; @Inject @Named(value = "roleManager#jpox") DefaultRoleManager roleManagerInjected; + @Inject + @Named(value = "rbacManager#jpa") + RBACManager rbacManager; + + + /** * Creates a new RbacStore which contains no data. */ @Before public void setUp() - throws Exception + throws Exception { super.setUp(); - - PersistenceManagerFactory pmf = jdoFactory.getPersistenceManagerFactory(); - - assertNotNull( pmf ); - - PersistenceManager pm = pmf.getPersistenceManager(); - - pm.close(); - - setRbacManager( rbacManagerJdo ); - + // rbacManager.setEntityManager(emf.createEntityManager()); + super.setRbacManager(rbacManager); + assertNotNull(rbacManager); setRoleManager( roleManagerInjected ); + } + } \ No newline at end of file diff --git a/redback-rbac/redback-rbac-role-manager/src/test/resources/jpox-spring-context.xml b/redback-rbac/redback-rbac-role-manager/src/test/resources/jpox-spring-context.xml index c674a02d..72609b4d 100644 --- a/redback-rbac/redback-rbac-role-manager/src/test/resources/jpox-spring-context.xml +++ b/redback-rbac/redback-rbac-role-manager/src/test/resources/jpox-spring-context.xml @@ -26,13 +26,13 @@ - + - + @@ -41,35 +41,10 @@ - + - - - - - - - - - - - - - - - JDK_DEFAULT_TIMEZONE - READ_UNCOMMITTED - READ_UNCOMMITTED - true - true - true - true - - - - diff --git a/redback-rbac/redback-rbac-role-manager/src/test/resources/spring-context.xml b/redback-rbac/redback-rbac-role-manager/src/test/resources/spring-context.xml index 9ba16d9b..7f866502 100755 --- a/redback-rbac/redback-rbac-role-manager/src/test/resources/spring-context.xml +++ b/redback-rbac/redback-rbac-role-manager/src/test/resources/spring-context.xml @@ -25,19 +25,6 @@ default-lazy-init="false"> - - - - - - - - - JDK_DEFAULT_TIMEZONE - true - - - diff --git a/redback-system/src/test/resources/spring-context.xml b/redback-system/src/test/resources/spring-context.xml index 2b4f86e8..348c365a 100644 --- a/redback-system/src/test/resources/spring-context.xml +++ b/redback-system/src/test/resources/spring-context.xml @@ -23,18 +23,6 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> - - - - - - - - - JDK_DEFAULT_TIMEZONE - - - diff --git a/redback-users/redback-users-providers/pom.xml b/redback-users/redback-users-providers/pom.xml index 1172f625..6bc7fff5 100644 --- a/redback-users/redback-users-providers/pom.xml +++ b/redback-users/redback-users-providers/pom.xml @@ -36,7 +36,6 @@ redback-users-cached redback-users-memory - redback-users-jdo redback-users-ldap redback-users-configurable redback-users-jpa diff --git a/redback-users/redback-users-providers/redback-users-cached/pom.xml b/redback-users/redback-users-providers/redback-users-cached/pom.xml index b64fe22e..52d28862 100644 --- a/redback-users/redback-users-providers/redback-users-cached/pom.xml +++ b/redback-users/redback-users-providers/redback-users-cached/pom.xml @@ -56,10 +56,6 @@ javax.annotation jsr250-api - - org.apache.archiva.redback - redback-users-jdo - org.apache.archiva.redback redback-users-jpa From 9b2f812568992c501e9a16b33297cab858e472d2 Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Sat, 31 Dec 2016 10:07:19 +0100 Subject: [PATCH 26/30] simplify pom Signed-off-by: olivier lamy --- pom.xml | 7 ++++++- .../redback-keys-providers/redback-keys-jpa/pom.xml | 1 - .../redback-rbac-providers/redback-rbac-jpa/pom.xml | 1 - .../redback-users-providers/redback-users-jpa/pom.xml | 1 - 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index c2b68e49..c16a926d 100644 --- a/pom.xml +++ b/pom.xml @@ -73,7 +73,7 @@ 4.2.1.RELEASE 1.7.12 - 2.3 + 2.7 UTF-8 true @@ -737,6 +737,11 @@ jpox-modello-maven-plugin 1.0 + + org.apache.openjpa + openjpa-maven-plugin + ${openjpa.version} + diff --git a/redback-keys/redback-keys-providers/redback-keys-jpa/pom.xml b/redback-keys/redback-keys-providers/redback-keys-jpa/pom.xml index 7f43e99e..b05ca424 100644 --- a/redback-keys/redback-keys-providers/redback-keys-jpa/pom.xml +++ b/redback-keys/redback-keys-providers/redback-keys-jpa/pom.xml @@ -88,7 +88,6 @@ org.apache.openjpa openjpa-maven-plugin - 2.4.1 **/model/*.class true diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/pom.xml b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/pom.xml index 665af806..47856b96 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jpa/pom.xml +++ b/redback-rbac/redback-rbac-providers/redback-rbac-jpa/pom.xml @@ -78,7 +78,6 @@ org.apache.openjpa openjpa-maven-plugin - 2.4.1 **/model/*.class true diff --git a/redback-users/redback-users-providers/redback-users-jpa/pom.xml b/redback-users/redback-users-providers/redback-users-jpa/pom.xml index a73e9f25..741951a5 100644 --- a/redback-users/redback-users-providers/redback-users-jpa/pom.xml +++ b/redback-users/redback-users-providers/redback-users-jpa/pom.xml @@ -80,7 +80,6 @@ org.apache.openjpa openjpa-maven-plugin - 2.4.1 **/model/*.class true From effc4a280b5235af06ab1933c2ac612269199918 Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Sat, 31 Dec 2016 10:08:30 +0100 Subject: [PATCH 27/30] format pom Signed-off-by: olivier lamy --- redback-common/pom.xml | 5 +- .../redback-keys-jpa/pom.xml | 170 +++++++++--------- 2 files changed, 88 insertions(+), 87 deletions(-) diff --git a/redback-common/pom.xml b/redback-common/pom.xml index 9819bb01..cefc84fe 100644 --- a/redback-common/pom.xml +++ b/redback-common/pom.xml @@ -17,7 +17,8 @@ ~ specific language governing permissions and limitations ~ under the License. --> - + 4.0.0 org.apache.archiva.redback @@ -31,6 +32,6 @@ redback-common-jdo redback-common-ldap redback-common-test-resources - redback-common-jpa + redback-common-jpa \ No newline at end of file diff --git a/redback-keys/redback-keys-providers/redback-keys-jpa/pom.xml b/redback-keys/redback-keys-providers/redback-keys-jpa/pom.xml index b05ca424..99b44ab6 100644 --- a/redback-keys/redback-keys-providers/redback-keys-jpa/pom.xml +++ b/redback-keys/redback-keys-providers/redback-keys-jpa/pom.xml @@ -20,99 +20,99 @@ - - redback-keys-providers - org.apache.archiva.redback - 2.5-SNAPSHOT - - 4.0.0 + + redback-keys-providers + org.apache.archiva.redback + 2.5-SNAPSHOT + + 4.0.0 - redback-keys-jpa - jar - Redback :: Key Management Provider :: JPA + redback-keys-jpa + jar + Redback :: Key Management Provider :: JPA - - - org.apache.archiva.redback - redback-keys-api - + + + org.apache.archiva.redback + redback-keys-api + - - org.apache.archiva.redback - redback-common-jpa - + + org.apache.archiva.redback + redback-common-jpa + - - org.springframework - spring-context-support - - - javax.annotation - jsr250-api - + + org.springframework + spring-context-support + + + javax.annotation + jsr250-api + - - org.apache.archiva.redback - redback-keys-tests - test - - + + org.apache.archiva.redback + redback-keys-tests + test + + + org.apache.openjpa + openjpa + ${openjpa.version} + + + org.springframework + spring-tx + ${springVersion} + + + org.springframework + spring-orm + ${springVersion} + + + org.hsqldb + hsqldb + test + + + org.slf4j + slf4j-simple + test + + + + + + + org.apache.openjpa + openjpa-maven-plugin + + **/model/*.class + true + true + + + + enhancer + process-classes + + enhance + + + + + org.apache.openjpa openjpa + ${openjpa.version} - - - org.springframework - spring-tx - ${springVersion} - - - org.springframework - spring-orm - ${springVersion} - - - org.hsqldb - hsqldb - test - - - org.slf4j - slf4j-simple - test - - - - - - - org.apache.openjpa - openjpa-maven-plugin - - **/model/*.class - true - true - - - - enhancer - process-classes - - enhance - - - - - - org.apache.openjpa - openjpa - - ${openjpa.version} - - - - - + + + + + \ No newline at end of file From 0537b8562ed46c5b4f56d88410d11ceae32f4320 Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Sat, 31 Dec 2016 10:21:49 +0100 Subject: [PATCH 28/30] get rid of all jdo jpox dependencies Signed-off-by: olivier lamy --- pom.xml | 88 +-- redback-common/pom.xml | 1 - redback-common/redback-common-jdo/pom.xml | 116 --- .../jdo/UserConfigurableJdoFactory.java | 132 ---- .../common/jdo/test/StoreManagerDebug.java | 113 --- .../resources/META-INF/spring-context.xml | 35 - .../redback-keys-jdo/pom.xml | 170 ----- .../redback/keys/jdo/JdoKeyManager.java | 187 ----- .../redback-keys-jdo/src/main/mdo/keys.mdo | 89 --- .../resources/META-INF/spring-context.xml | 32 - .../redback/keys/jdo/JdoKeyManagerTest.java | 102 --- .../src/test/resources/spring-context.xml | 48 -- .../redback-rbac-jdo/pom.xml | 156 ---- .../redback/rbac/jdo/JdoRbacManager.java | 711 ------------------ .../archiva/redback/rbac/jdo/JdoTool.java | 500 ------------ .../src/main/mdo/rbac-jdo.mdo | 337 --------- .../resources/META-INF/spring-context.xml | 34 - .../redback/rbac/jdo/JdoRbacManagerTest.java | 219 ------ .../rbac/jdo/RbacJdoModelStaxTest.java | 198 ----- .../src/test/resources/ehcache.xml | 90 --- .../src/test/resources/spring-context.xml | 85 --- .../redback-users-jdo/pom.xml | 176 ----- .../redback/users/jdo/JdoUserManager.java | 466 ------------ .../redback/users/jdo/JdoUserQuery.java | 136 ---- .../archiva/redback/users/jdo/Messages.java | 94 --- .../redback-users-jdo/src/main/mdo/user.mdo | 162 ---- .../resources/META-INF/spring-context.xml | 33 - .../redback/users/jdo/messages.properties | 18 - .../redback/users/jdo/JdoUserManagerTest.java | 117 --- .../src/test/resources/spring-context.xml | 58 -- .../src/test/resources/test.properties | 17 - 31 files changed, 2 insertions(+), 4718 deletions(-) delete mode 100644 redback-common/redback-common-jdo/pom.xml delete mode 100644 redback-common/redback-common-jdo/src/main/java/org/apache/archiva/redback/common/jdo/UserConfigurableJdoFactory.java delete mode 100644 redback-common/redback-common-jdo/src/main/java/org/apache/archiva/redback/common/jdo/test/StoreManagerDebug.java delete mode 100644 redback-common/redback-common-jdo/src/main/resources/META-INF/spring-context.xml delete mode 100644 redback-keys/redback-keys-providers/redback-keys-jdo/pom.xml delete mode 100644 redback-keys/redback-keys-providers/redback-keys-jdo/src/main/java/org/apache/archiva/redback/keys/jdo/JdoKeyManager.java delete mode 100644 redback-keys/redback-keys-providers/redback-keys-jdo/src/main/mdo/keys.mdo delete mode 100644 redback-keys/redback-keys-providers/redback-keys-jdo/src/main/resources/META-INF/spring-context.xml delete mode 100644 redback-keys/redback-keys-providers/redback-keys-jdo/src/test/java/org/apache/archiva/redback/keys/jdo/JdoKeyManagerTest.java delete mode 100644 redback-keys/redback-keys-providers/redback-keys-jdo/src/test/resources/spring-context.xml delete mode 100644 redback-rbac/redback-rbac-providers/redback-rbac-jdo/pom.xml delete mode 100644 redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/java/org/apache/archiva/redback/rbac/jdo/JdoRbacManager.java delete mode 100644 redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/java/org/apache/archiva/redback/rbac/jdo/JdoTool.java delete mode 100644 redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/mdo/rbac-jdo.mdo delete mode 100644 redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/resources/META-INF/spring-context.xml delete mode 100644 redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/java/org/apache/archiva/redback/rbac/jdo/JdoRbacManagerTest.java delete mode 100644 redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/java/org/apache/archiva/redback/rbac/jdo/RbacJdoModelStaxTest.java delete mode 100644 redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/resources/ehcache.xml delete mode 100644 redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/resources/spring-context.xml delete mode 100644 redback-users/redback-users-providers/redback-users-jdo/pom.xml delete mode 100644 redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/JdoUserManager.java delete mode 100644 redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/JdoUserQuery.java delete mode 100644 redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/Messages.java delete mode 100644 redback-users/redback-users-providers/redback-users-jdo/src/main/mdo/user.mdo delete mode 100644 redback-users/redback-users-providers/redback-users-jdo/src/main/resources/META-INF/spring-context.xml delete mode 100644 redback-users/redback-users-providers/redback-users-jdo/src/main/resources/org/apache/archiva/redback/users/jdo/messages.properties delete mode 100644 redback-users/redback-users-providers/redback-users-jdo/src/test/java/org/apache/archiva/redback/users/jdo/JdoUserManagerTest.java delete mode 100644 redback-users/redback-users-providers/redback-users-jdo/src/test/resources/spring-context.xml delete mode 100644 redback-users/redback-users-providers/redback-users-jdo/src/test/resources/test.properties diff --git a/pom.xml b/pom.xml index c16a926d..91954b64 100644 --- a/pom.xml +++ b/pom.xml @@ -387,35 +387,7 @@ - - org.apache.archiva.redback.components - spring-jdo2 - 2.2 - - - xerces - xercesImpl - - - xerces - xmlParserAPIs - - - - - xalan - xalan - - 2.7.0 - - - xml-apis - xml-apis - - 1.3.03 - commons-lang commons-lang @@ -543,45 +515,6 @@ redback-rest-services ${project.version} - - jpox - jpox - 1.1.9-1 - compile - - - - javax.sql - jdbc-stdext - - - log4j - log4j - - - - javax.resource - connector - - - javax.transaction - jta - - - - - - jpox - jpox-ehcache - 1.1.9 - test - - - ehcache - ehcache - - - com.google.guava guava @@ -697,22 +630,10 @@ org.apache.maven.plugins maven-compiler-plugin - 1.6 - 1.6 + 1.7 + 1.7 - - org.codehaus.mojo - jpox-maven-plugin - 1.1.7 - - - org.apache.bcel - bcel - 6.0 - - - org.codehaus.modello modello-maven-plugin @@ -732,11 +653,6 @@ scm:svn:https://svn.apache.org/repos/asf/archiva/site-content/redback/core - - org.apache.archiva.redback.components.modello - jpox-modello-maven-plugin - 1.0 - org.apache.openjpa openjpa-maven-plugin diff --git a/redback-common/pom.xml b/redback-common/pom.xml index cefc84fe..42e13500 100644 --- a/redback-common/pom.xml +++ b/redback-common/pom.xml @@ -29,7 +29,6 @@ Redback :: Commons pom - redback-common-jdo redback-common-ldap redback-common-test-resources redback-common-jpa diff --git a/redback-common/redback-common-jdo/pom.xml b/redback-common/redback-common-jdo/pom.xml deleted file mode 100644 index 275c641b..00000000 --- a/redback-common/redback-common-jdo/pom.xml +++ /dev/null @@ -1,116 +0,0 @@ - - - - - 4.0.0 - - - org.apache.archiva.redback - redback-common - 2.5-SNAPSHOT - - - redback-common-jdo - bundle - Redback :: JDO Common API - - - - org.apache.archiva.redback.components - spring-jdo2 - - - jpox - jpox - compile - - - - javax.sql - jdbc-stdext - - - log4j - log4j - - - - javax.resource - connector - - - javax.transaction - jta - - - - - - org.hsqldb - hsqldb - test - - - org.apache.archiva.redback - redback-configuration - - - org.springframework - spring-context-support - - - javax.annotation - jsr250-api - - - commons-lang - commons-lang - - - - - - - org.apache.felix - maven-bundle-plugin - - - - org.apache.archiva.redback.common.jdo*;version=${project.version};-split-package:=merge-first - - - javax.annotation, - javax.inject;version="[1,2)", - javax.jdo;version="[2,3)", - org.apache.archiva.redback.components.jdo;version=${project.version}, - org.apache.archiva.redback.configuration;version=${project.version}, - org.apache.commons.lang;version="[2.6,3)", - org.codehaus.plexus.interpolation;version="[1.9,2)", - org.jpox*;version="[1.1,2)", - org.springframework.stereotype;version="[3,4)", - org.slf4j;resolution:=optional - - - - - - - - diff --git a/redback-common/redback-common-jdo/src/main/java/org/apache/archiva/redback/common/jdo/UserConfigurableJdoFactory.java b/redback-common/redback-common-jdo/src/main/java/org/apache/archiva/redback/common/jdo/UserConfigurableJdoFactory.java deleted file mode 100644 index e5114923..00000000 --- a/redback-common/redback-common-jdo/src/main/java/org/apache/archiva/redback/common/jdo/UserConfigurableJdoFactory.java +++ /dev/null @@ -1,132 +0,0 @@ -package org.apache.archiva.redback.common.jdo; - -/* - * 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.components.jdo.DefaultConfigurableJdoFactory; -import org.apache.archiva.redback.configuration.UserConfiguration; -import org.apache.commons.lang.StringUtils; -import org.codehaus.plexus.interpolation.InterpolationException; -import org.codehaus.plexus.interpolation.PropertiesBasedValueSource; -import org.codehaus.plexus.interpolation.StringSearchInterpolator; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Service; - -import javax.annotation.PostConstruct; -import javax.inject.Inject; -import javax.inject.Named; - -/** - * UserConfigurableJdoFactory - * - * @author Joakim Erdfelt - */ -@Service("jdoFactory#users") -public class UserConfigurableJdoFactory - extends DefaultConfigurableJdoFactory -{ - - private Logger log = LoggerFactory.getLogger( getClass() ); - - private UserConfiguration userConfiguration; - - @Inject - public UserConfigurableJdoFactory( - @Named( value = "userConfiguration#default" ) UserConfiguration userConfiguration ) - { - this.userConfiguration = userConfiguration; - } - - private String getConfigString( String key, String currentValue, String defaultValue ) - { - String valueFromSysProps = System.getProperty( "redback." + key ); - if ( StringUtils.isNotEmpty( valueFromSysProps ) ) - { - return valueFromSysProps; - } - String value = null; - if ( StringUtils.isNotEmpty( currentValue ) ) - { - value = userConfiguration.getString( key, currentValue ); - } - else - { - value = userConfiguration.getString( key, defaultValue ); - } - // do some interpolation as we can have some ${plexus.home} etc... - StringSearchInterpolator interpolator = new StringSearchInterpolator(); - interpolator.addValueSource( new PropertiesBasedValueSource( System.getProperties() ) ); - - try - { - return interpolator.interpolate( value ); - } - catch ( InterpolationException e ) - { - // ignore interpolation issue - log.warn( "skip issue during interpolation {}", e.getMessage() ); - return value; - } - } - - @PostConstruct - public void initialize() - { - String jdbcDriverName = - getConfigString( "jdbc.driver.name", super.getDriverName(), "org.apache.derby.jdbc.EmbeddedDriver" ); - String jdbcUrl = - getConfigString( "jdbc.url", super.getUrl(), "jdbc:derby:${plexus.home}/database;create=true" ); - - String jdbcUsername = getConfigString( "jdbc.username", super.getUserName(), "sa" ); - String jdbcPassword = getConfigString( "jdbc.password", super.getPassword(), "" ); - - super.setDriverName( jdbcDriverName ); - super.setUrl( jdbcUrl ); - super.setUserName( jdbcUsername ); - super.setPassword( jdbcPassword ); - - if ( StringUtils.isEmpty( super.persistenceManagerFactoryClass ) ) - { - super.setPersistenceManagerFactoryClass( "org.jpox.PersistenceManagerFactoryImpl" ); - } - - if ( ( super.otherProperties == null ) || super.otherProperties.isEmpty() ) - { - super.setProperty( "org.jpox.autoCreateSchema", "true" ); - super.setProperty( "org.jpox.validateSchema", "false" ); - super.setProperty( "org.jpox.validateTables", "false" ); - super.setProperty( "org.jpox.validateConstraints", "false" ); - super.setProperty( "org.jpox.transactionIsolation", "READ_COMMITTED" ); - super.setProperty( "org.jpox.rdbms.dateTimezone", "JDK_DEFAULT_TIMEZONE" ); - } - - super.initialize(); - } - - public UserConfiguration getUserConfiguration() - { - return userConfiguration; - } - - public void setUserConfiguration( UserConfiguration userConfiguration ) - { - this.userConfiguration = userConfiguration; - } -} diff --git a/redback-common/redback-common-jdo/src/main/java/org/apache/archiva/redback/common/jdo/test/StoreManagerDebug.java b/redback-common/redback-common-jdo/src/main/java/org/apache/archiva/redback/common/jdo/test/StoreManagerDebug.java deleted file mode 100644 index ea57a519..00000000 --- a/redback-common/redback-common-jdo/src/main/java/org/apache/archiva/redback/common/jdo/test/StoreManagerDebug.java +++ /dev/null @@ -1,113 +0,0 @@ -package org.apache.archiva.redback.common.jdo.test; - -/* - * 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 java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; - -import javax.jdo.PersistenceManager; - -import org.jpox.AbstractPersistenceManagerFactory; -import org.jpox.ClassLoaderResolver; -import org.jpox.plugin.ConfigurationElement; -import org.jpox.plugin.Extension; -import org.jpox.store.rdbms.RDBMSManager; - -/** - * A extension to JPOX store manager that allows counting the SQL queries - * - * @author Carlos Sanchez - */ -public class StoreManagerDebug - extends RDBMSManager -{ - private static int counter; - - public StoreManagerDebug( ClassLoaderResolver clr, AbstractPersistenceManagerFactory pmf, String userName, - String password ) - { - super( clr, pmf, userName, password ); - } - - /** - * This method will change JPOX store manager extension so it uses our class instead of whatever is configured in - * the plugin.xml - * - * @param pmf - */ - public static void setup( AbstractPersistenceManagerFactory pmf ) - { - /* set our own Store Manager to allow counting SQL statements */ - Extension[] extensions = - pmf.getPMFContext().getPluginManager().getExtensionPoint( "org.jpox.store_manager" ).getExtensions(); - Extension e = extensions[0]; - for ( ConfigurationElement element : e.getConfigurationElements() ) - { - element.putAttribute( "class-name", StoreManagerDebug.class.getName() ); - } - } - - /** - * Get the currently configured store manager from JPOX. Will fail if - * {@link #setup(AbstractPersistenceManagerFactory)} is not called first. - * - * @param persistenceManager - * @return - */ - public static StoreManagerDebug getConfiguredStoreManager( PersistenceManager persistenceManager ) - { - return (StoreManagerDebug) ( (org.jpox.PersistenceManager) persistenceManager ).getStoreManager(); - } - - @Override - public int[] executeStatementBatch( String stmt, PreparedStatement ps ) - throws SQLException - { - counter++; - return super.executeStatementBatch( stmt, ps ); - } - - @Override - public ResultSet executeStatementQuery( String stmt, PreparedStatement ps ) - throws SQLException - { - counter++; - return super.executeStatementQuery( stmt, ps ); - } - - @Override - public int executeStatementUpdate( String stmt, PreparedStatement ps ) - throws SQLException - { - counter++; - return super.executeStatementUpdate( stmt, ps ); - } - - public void resetCounter() - { - counter = 0; - } - - public int counter() - { - return counter; - } -} diff --git a/redback-common/redback-common-jdo/src/main/resources/META-INF/spring-context.xml b/redback-common/redback-common-jdo/src/main/resources/META-INF/spring-context.xml deleted file mode 100644 index 86a9fe94..00000000 --- a/redback-common/redback-common-jdo/src/main/resources/META-INF/spring-context.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/redback-keys/redback-keys-providers/redback-keys-jdo/pom.xml b/redback-keys/redback-keys-providers/redback-keys-jdo/pom.xml deleted file mode 100644 index abf709ce..00000000 --- a/redback-keys/redback-keys-providers/redback-keys-jdo/pom.xml +++ /dev/null @@ -1,170 +0,0 @@ - - - - - 4.0.0 - - - org.apache.archiva.redback - redback-keys-providers - 2.5-SNAPSHOT - - - redback-keys-jdo - jar - Redback :: Key Management Provider :: JDO - - - - org.apache.archiva.redback - redback-keys-api - - - - org.apache.archiva.redback - redback-common-jdo - - - - org.springframework - spring-context-support - - - javax.annotation - jsr250-api - - - - org.apache.archiva.redback - redback-keys-tests - test - - - - org.hsqldb - hsqldb - test - - - net.java.dev.stax-utils - stax-utils - 20060502 - - - com.bea.xml - jsr173-ri - - - - - org.slf4j - slf4j-simple - test - - - - - - - org.apache.felix - maven-bundle-plugin - - - bundle-manifest - process-classes - - manifest - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - - - - org.codehaus.modello - modello-maven-plugin - - 1.0.1 - false - - src/main/mdo/keys.mdo - - - - - modello-java - - java - stax-reader - stax-writer - - - - - - org.apache.archiva.redback.components.modello - jpox-modello-maven-plugin - - 1.0.1 - false - - src/main/mdo/keys.mdo - - - - - modello-jpox - - jpox-metadata-class - - - - jpox-jdo-mapping - - jpox-jdo-mapping - - - ${project.build.outputDirectory}/org/apache/archiva/redback/keys/jdo - - - - - - org.codehaus.mojo - jpox-maven-plugin - - - - enhance - - - - - - - - diff --git a/redback-keys/redback-keys-providers/redback-keys-jdo/src/main/java/org/apache/archiva/redback/keys/jdo/JdoKeyManager.java b/redback-keys/redback-keys-providers/redback-keys-jdo/src/main/java/org/apache/archiva/redback/keys/jdo/JdoKeyManager.java deleted file mode 100644 index 1537f576..00000000 --- a/redback-keys/redback-keys-providers/redback-keys-jdo/src/main/java/org/apache/archiva/redback/keys/jdo/JdoKeyManager.java +++ /dev/null @@ -1,187 +0,0 @@ -package org.apache.archiva.redback.keys.jdo; - -/* - * 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.components.jdo.JdoFactory; -import org.apache.archiva.redback.components.jdo.RedbackJdoUtils; -import org.apache.archiva.redback.components.jdo.RedbackObjectNotFoundException; -import org.apache.archiva.redback.components.jdo.RedbackStoreException; -import org.apache.archiva.redback.keys.AuthenticationKey; -import org.apache.archiva.redback.keys.AbstractKeyManager; -import org.apache.archiva.redback.keys.KeyManagerException; -import org.apache.archiva.redback.keys.KeyNotFoundException; -import org.codehaus.plexus.util.StringUtils; -import org.jpox.PersistenceManagerFactoryImpl; -import org.springframework.stereotype.Service; - -import javax.annotation.PostConstruct; -import javax.inject.Inject; -import javax.inject.Named; -import javax.jdo.PersistenceManager; -import javax.jdo.PersistenceManagerFactory; -import java.util.Calendar; -import java.util.List; - -/** - * JdoKeyManager - * - * @author Joakim Erdfelt - * - */ -@Service( "keyManager#jdo" ) -public class JdoKeyManager - extends AbstractKeyManager -{ - @Inject - @Named( value = "jdoFactory#users" ) - private JdoFactory jdoFactory; - - private PersistenceManagerFactory pmf; - - public AuthenticationKey createKey( String principal, String purpose, int expirationMinutes ) - throws KeyManagerException - { - JdoAuthenticationKey authkey = new JdoAuthenticationKey(); - authkey.setKey( super.generateUUID() ); - authkey.setForPrincipal( principal ); - authkey.setPurpose( purpose ); - - Calendar now = getNowGMT(); - authkey.setDateCreated( now.getTime() ); - - if ( expirationMinutes >= 0 ) - { - Calendar expiration = getNowGMT(); - expiration.add( Calendar.MINUTE, expirationMinutes ); - authkey.setDateExpires( expiration.getTime() ); - } - - return addKey( authkey ); - } - - public AuthenticationKey addKey( AuthenticationKey key ) - { - return (AuthenticationKey) RedbackJdoUtils.addObject( getPersistenceManager(), key ); - } - - public void eraseDatabase() - { - RedbackJdoUtils.removeAll( getPersistenceManager(), JdoAuthenticationKey.class ); - RedbackJdoUtils.removeAll( getPersistenceManager(), RedbackKeyManagementJdoModelloMetadata.class ); - } - - public AuthenticationKey findKey( String key ) - throws KeyNotFoundException, KeyManagerException - { - if ( StringUtils.isEmpty( key ) ) - { - throw new KeyNotFoundException( "Empty key not found." ); - } - - try - { - JdoAuthenticationKey authkey = (JdoAuthenticationKey) RedbackJdoUtils.getObjectById( - getPersistenceManager(), JdoAuthenticationKey.class, key ); - - if ( authkey == null ) - { - throw new KeyNotFoundException( "Key [" + key + "] not found." ); - } - assertNotExpired( authkey ); - - return authkey; - } - catch ( RedbackObjectNotFoundException e ) - { - throw new KeyNotFoundException( e.getMessage() ); - } - catch ( RedbackStoreException e ) - { - throw new KeyManagerException( - "Unable to get " + JdoAuthenticationKey.class.getName() + "', key '" + key + "' from jdo store." ); - } - } - - public void deleteKey( AuthenticationKey authkey ) - throws KeyManagerException - { - RedbackJdoUtils.removeObject( getPersistenceManager(), authkey ); - } - - public void deleteKey( String key ) - throws KeyManagerException - { - try - { - AuthenticationKey authkey = findKey( key ); - RedbackJdoUtils.removeObject( getPersistenceManager(), authkey ); - } - catch ( KeyNotFoundException e ) - { - // not found? nothing to do. - } - } - - @SuppressWarnings( "unchecked" ) - public List getAllKeys() - { - return RedbackJdoUtils.getAllObjectsDetached( getPersistenceManager(), JdoAuthenticationKey.class ); - } - - @PostConstruct - public void initialize() - { - pmf = jdoFactory.getPersistenceManagerFactory(); - - if ( pmf instanceof PersistenceManagerFactoryImpl ) - { - PersistenceManagerFactoryImpl jpoxpmf = (PersistenceManagerFactoryImpl) pmf; - if ( !StringUtils.equals( "JDK_DEFAULT_TIMEZONE", jpoxpmf.getDateTimezone() ) ) - { - throw new RuntimeException( "The JdoFactory property 'org.jpox.rdbms.dateTimezone' MUST BE " - + "Set to 'JDK_DEFAULT_TIMEZONE' in order for jpox and JdoKeyManager to operate correctly." ); - } - } - } - - private PersistenceManager getPersistenceManager() - { - PersistenceManager pm = pmf.getPersistenceManager(); - - pm.getFetchPlan().setMaxFetchDepth( 5 ); - - return pm; - } - - public String getId() - { - return "JDO Key Manager - " + this.getClass().getName(); - } - - public JdoFactory getJdoFactory() - { - return jdoFactory; - } - - public void setJdoFactory( JdoFactory jdoFactory ) - { - this.jdoFactory = jdoFactory; - } -} diff --git a/redback-keys/redback-keys-providers/redback-keys-jdo/src/main/mdo/keys.mdo b/redback-keys/redback-keys-providers/redback-keys-jdo/src/main/mdo/keys.mdo deleted file mode 100644 index 5c2ff591..00000000 --- a/redback-keys/redback-keys-providers/redback-keys-jdo/src/main/mdo/keys.mdo +++ /dev/null @@ -1,89 +0,0 @@ - - - - - - redback-keys-jdo - RedbackKeyManagementJdo - 1.0.1 - Archiva Redback :: Key Management JDO Store. - - - package - org.apache.archiva.redback.keys.jdo - - - - - - AuthenticationKeyDatabase - 1.0.1+ - - - keys - 1.0.1+ - - JdoAuthenticationKey - * - - - - - - JdoAuthenticationKey - 1.0.0+ - - org.apache.archiva.redback.keys.AuthenticationKey - - - - key - 1.0.0+ - String - true - - - forPrincipal - 1.0.0+ - String - true - - - purpose - 1.0.0+ - String - - - dateCreated - 1.0.0+ - Date - - - dateExpires - 1.0.0+ - Date - - - - - diff --git a/redback-keys/redback-keys-providers/redback-keys-jdo/src/main/resources/META-INF/spring-context.xml b/redback-keys/redback-keys-providers/redback-keys-jdo/src/main/resources/META-INF/spring-context.xml deleted file mode 100644 index b757d07b..00000000 --- a/redback-keys/redback-keys-providers/redback-keys-jdo/src/main/resources/META-INF/spring-context.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/redback-keys/redback-keys-providers/redback-keys-jdo/src/test/java/org/apache/archiva/redback/keys/jdo/JdoKeyManagerTest.java b/redback-keys/redback-keys-providers/redback-keys-jdo/src/test/java/org/apache/archiva/redback/keys/jdo/JdoKeyManagerTest.java deleted file mode 100644 index 70f6d73a..00000000 --- a/redback-keys/redback-keys-providers/redback-keys-jdo/src/test/java/org/apache/archiva/redback/keys/jdo/JdoKeyManagerTest.java +++ /dev/null @@ -1,102 +0,0 @@ -package org.apache.archiva.redback.keys.jdo; - -/* - * 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.components.jdo.DefaultConfigurableJdoFactory; -import org.apache.archiva.redback.keys.KeyManager; -import org.apache.archiva.redback.keys.KeyManagerTestCase; -import org.jpox.SchemaTool; -import org.junit.Before; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.jdo.PersistenceManager; -import javax.jdo.PersistenceManagerFactory; -import java.net.URL; -import java.util.Map; -import java.util.Properties; - -/** - * JdoKeyManagerTest - * - * @author Joakim Erdfelt - * - */ -public class JdoKeyManagerTest - extends KeyManagerTestCase -{ - - @Inject - @Named(value = "jdoFactory#users") - DefaultConfigurableJdoFactory jdoFactory; - - @Inject @Named(value = "keyManager#jdo") - KeyManager keyManager; - - - @Before - public void setUp() - throws Exception - { - - super.setUp(); - - assertEquals( DefaultConfigurableJdoFactory.class.getName(), jdoFactory.getClass().getName() ); - - jdoFactory.setPersistenceManagerFactoryClass( "org.jpox.PersistenceManagerFactoryImpl" ); //$NON-NLS-1$ - - jdoFactory.setDriverName( "org.hsqldb.jdbcDriver" ); //$NON-NLS-1$ - - jdoFactory.setUrl( "jdbc:hsqldb:mem:" + getName() ); //$NON-NLS-1$ - - jdoFactory.setUserName( "sa" ); //$NON-NLS-1$ - - jdoFactory.setPassword( "" ); //$NON-NLS-1$ - - jdoFactory.setProperty( "org.jpox.transactionIsolation", "READ_COMMITTED" ); //$NON-NLS-1$ //$NON-NLS-2$ - - jdoFactory.setProperty( "org.jpox.poid.transactionIsolation", "READ_COMMITTED" ); //$NON-NLS-1$ //$NON-NLS-2$ - - jdoFactory.setProperty( "org.jpox.autoCreateSchema", "true" ); //$NON-NLS-1$ //$NON-NLS-2$ - - jdoFactory.setProperty( "org.jpox.rdbms.dateTimezone", "JDK_DEFAULT_TIMEZONE" ); //$NON-NLS-1$ //$NON-NLS-2$ - - Properties properties = jdoFactory.getProperties(); - - for ( Map.Entry entry : properties.entrySet() ) - { - System.setProperty( (String) entry.getKey(), (String) entry.getValue() ); - } - - SchemaTool.createSchemaTables( new URL[] { getClass() - .getResource( "/org/apache/archiva/redback/keys/jdo/package.jdo" ) }, new URL[] {}, null, false, null ); //$NON-NLS-1$ - - PersistenceManagerFactory pmf = jdoFactory.getPersistenceManagerFactory(); - - assertNotNull( pmf ); - - PersistenceManager pm = pmf.getPersistenceManager(); - - pm.close(); - keyManager.eraseDatabase(); - setKeyManager( keyManager ); - } - -} diff --git a/redback-keys/redback-keys-providers/redback-keys-jdo/src/test/resources/spring-context.xml b/redback-keys/redback-keys-providers/redback-keys-jdo/src/test/resources/spring-context.xml deleted file mode 100644 index dd75f723..00000000 --- a/redback-keys/redback-keys-providers/redback-keys-jdo/src/test/resources/spring-context.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - - - - - - - JDK_DEFAULT_TIMEZONE - - - - - - - - - - - - - - \ No newline at end of file diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/pom.xml b/redback-rbac/redback-rbac-providers/redback-rbac-jdo/pom.xml deleted file mode 100644 index d3c4c731..00000000 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/pom.xml +++ /dev/null @@ -1,156 +0,0 @@ - - - - - 4.0.0 - - - org.apache.archiva.redback - redback-rbac-providers - 2.5-SNAPSHOT - - - redback-rbac-jdo - bundle - Redback :: RBAC Provider :: JDO - - - - org.apache.archiva.redback - redback-rbac-model - - - org.springframework - spring-context-support - - - javax.annotation - jsr250-api - - - org.apache.archiva.redback - redback-rbac-tests - test - - - org.codehaus.plexus - plexus-utils - - - org.apache.archiva.redback - redback-common-jdo - - - net.java.dev.stax-utils - stax-utils - 20060502 - - - com.bea.xml - jsr173-ri - - - - - org.slf4j - slf4j-simple - test - - - org.hsqldb - hsqldb - test - - - jpox - jpox-ehcache - test - - - ehcache - ehcache - - - - - - - - - org.apache.felix - maven-bundle-plugin - - - org.codehaus.modello - modello-maven-plugin - - 1.0.1 - false - - src/main/mdo/rbac-jdo.mdo - - - - - modello-java - - java - - stax-reader - stax-writer - - - - - - org.apache.archiva.redback.components.modello - jpox-modello-maven-plugin - - 1.0.1 - false - - src/main/mdo/rbac-jdo.mdo - - - - - modello-jpox - - jpox-metadata-class - jpox-jdo-mapping - - - - - - org.codehaus.mojo - jpox-maven-plugin - - - - enhance - - - - - - - - diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/java/org/apache/archiva/redback/rbac/jdo/JdoRbacManager.java b/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/java/org/apache/archiva/redback/rbac/jdo/JdoRbacManager.java deleted file mode 100644 index ac565a3c..00000000 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/java/org/apache/archiva/redback/rbac/jdo/JdoRbacManager.java +++ /dev/null @@ -1,711 +0,0 @@ -package org.apache.archiva.redback.rbac.jdo; - -/* - * 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.rbac.AbstractRBACManager; -import org.apache.archiva.redback.rbac.Operation; -import org.apache.archiva.redback.rbac.RBACManagerListener; -import org.apache.archiva.redback.rbac.RbacManagerException; -import org.apache.archiva.redback.rbac.RbacObjectInvalidException; -import org.apache.archiva.redback.rbac.RbacObjectNotFoundException; -import org.apache.archiva.redback.rbac.RbacPermanentException; -import org.apache.archiva.redback.rbac.Resource; -import org.apache.archiva.redback.rbac.Role; -import org.apache.archiva.redback.rbac.UserAssignment; -import org.apache.archiva.redback.rbac.Permission; -import org.apache.archiva.redback.rbac.RBACObjectAssertions; -import org.springframework.stereotype.Service; - -import javax.annotation.PostConstruct; -import javax.inject.Inject; -import javax.jdo.JDOHelper; -import javax.jdo.PersistenceManager; -import javax.jdo.Transaction; -import java.util.Collection; -import java.util.List; - -/** - * JdoRbacManager: - * - * @author Joakim Erdfelt - * @author Jesse McConnell - * - */ -@Service( "rbacManager#jdo" ) -public class JdoRbacManager - extends AbstractRBACManager - implements RBACManagerListener -{ - @Inject - private JdoTool jdo; - - private boolean enableCache = true; - - // private static final String ROLE_DETAIL = "role-child-detail"; - private static final String ROLE_DETAIL = null; - - // ---------------------------------------------------------------------- - // Role methods - // ---------------------------------------------------------------------- - - /** - * Creates an implementation specific {@link Role}. - * - * Note: this method does not add the {@link Role} to the underlying store. - * a call to {@link #saveRole(Role)} is required to track the role created with this - * method call. - * - * @param name the name. - * @return the new {@link Role} object with an empty (non-null) {@link Role#getChildRoleNames()} object. - */ - public Role createRole( String name ) - { - Role role; - - try - { - role = getRole( name ); - } - catch ( RbacManagerException e ) - { - role = new JdoRole(); - role.setName( name ); - } - - return role; - } - - /** - * Method addRole - * - * @param role - */ - public Role saveRole( Role role ) - throws RbacObjectInvalidException, RbacManagerException - { - RBACObjectAssertions.assertValid( role ); - - return jdo.saveObject( role, new String[]{ ROLE_DETAIL } ); - } - - public boolean roleExists( Role role ) - { - return jdo.objectExists( role ); - } - - public boolean roleExists( String name ) - { - try - { - return jdo.objectExistsById( JdoRole.class, name ); - } - catch ( RbacManagerException e ) - { - return false; - } - } - - /** - * @param roleName - * @return - * @throws RbacObjectNotFoundException - * @throws RbacManagerException - */ - public Role getRole( String roleName ) - throws RbacObjectNotFoundException, RbacManagerException - { - return jdo.getObjectById( JdoRole.class, roleName, ROLE_DETAIL ); - } - - /** - * Method getRoles - */ - @SuppressWarnings( "unchecked" ) - public List getAllRoles() - throws RbacManagerException - { - return (List) jdo.getAllObjects( JdoRole.class ); - } - - public void removeRole( Role role ) - throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException - { - RBACObjectAssertions.assertValid( role ); - - if ( role.isPermanent() ) - { - throw new RbacPermanentException( "Unable to delete permanent role [" + role.getName() + "]" ); - } - - jdo.removeObject( role ); - } - - public void saveRoles( Collection roles ) - throws RbacObjectInvalidException, RbacManagerException - { - if ( roles == null ) - { - // Nothing to do. - return; - } - - // This is done in JdoRbacManager as opposed to JdoTool as we need to assertValid() on each role and - // also wrap the entire collection into a single atomic save/makePersistent. - - PersistenceManager pm = jdo.getPersistenceManager(); - Transaction tx = pm.currentTransaction(); - - try - { - tx.begin(); - - for ( Role role : roles ) - { - if ( ( JDOHelper.getObjectId( role ) != null ) && !JDOHelper.isDetached( role ) ) - { - // This is a fatal error that means we need to fix our code. - // Leave it as a JDOUserException, it's intentional. - throw new RbacManagerException( "Existing Role is not detached: " + role ); - } - - RBACObjectAssertions.assertValid( role ); - - pm.makePersistent( role ); - } - - tx.commit(); - } - finally - { - jdo.rollbackIfActive( tx ); - } - } - - // ---------------------------------------------------------------------- - // Permission methods - // ---------------------------------------------------------------------- - - /** - * Creates an implementation specific {@link Permission}. - * - * Note: this method does not add the {@link Permission} to the underlying store. - * a call to {@link #savePermission(Permission)} is required to track the permission created - * with this method call. - * - * @param name the name. - * @return the new Permission. - * @throws RbacManagerException - */ - public Permission createPermission( String name ) - throws RbacManagerException - { - Permission permission; - - try - { - permission = getPermission( name ); - log.debug( "Create Permission [{}] Returning Existing.", name ); - } - catch ( RbacObjectNotFoundException e ) - { - permission = new JdoPermission(); - permission.setName( name ); - log.debug( "Create Permission [{}] New JdoPermission.", name ); - } - - return permission; - } - - /** - * Creates an implementation specific {@link Permission} with specified {@link Operation}, - * and {@link Resource} identifiers. - * - * Note: this method does not add the Permission, Operation, or Resource to the underlying store. - * a call to {@link #savePermission(Permission)} is required to track the permission, operation, - * or resource created with this method call. - * - * @param name the name. - * @param operationName the {@link Operation#setName(String)} value - * @param resourceIdentifier the {@link Resource#setIdentifier(String)} value - * @return the new Permission. - * @throws RbacManagerException - */ - public Permission createPermission( String name, String operationName, String resourceIdentifier ) - throws RbacManagerException - { - Permission permission = new JdoPermission(); - permission.setName( name ); - - Operation operation; - try - { - operation = getOperation( operationName ); - } - catch ( RbacObjectNotFoundException e ) - { - operation = new JdoOperation(); - operation.setName( operationName ); - } - permission.setOperation( operation ); - - Resource resource; - try - { - resource = getResource( resourceIdentifier ); - } - catch ( RbacObjectNotFoundException e ) - { - resource = new JdoResource(); - resource.setIdentifier( resourceIdentifier ); - } - permission.setResource( resource ); - - return permission; - } - - public Permission savePermission( Permission permission ) - throws RbacObjectInvalidException, RbacManagerException - { - RBACObjectAssertions.assertValid( permission ); - - return jdo.saveObject( permission, null ); - } - - public boolean permissionExists( Permission permission ) - { - return jdo.objectExists( permission ); - } - - public boolean permissionExists( String name ) - { - try - { - return jdo.objectExistsById( JdoPermission.class, name ); - } - catch ( RbacManagerException e ) - { - return false; - } - } - - public Permission getPermission( String permissionName ) - throws RbacObjectNotFoundException, RbacManagerException - { - return jdo.getObjectById( JdoPermission.class, permissionName, null ); - } - - @SuppressWarnings( "unchecked" ) - public List getAllPermissions() - throws RbacManagerException - { - return (List) jdo.getAllObjects( JdoPermission.class ); - } - - public void removePermission( Permission permission ) - throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException - { - RBACObjectAssertions.assertValid( permission ); - - if ( permission.isPermanent() ) - { - throw new RbacPermanentException( "Unable to delete permanent permission [" + permission.getName() + "]" ); - } - - jdo.removeObject( permission ); - } - - // ---------------------------------------------------------------------- - // Operation methods - // ---------------------------------------------------------------------- - - /** - * Creates an implementation specific {@link Operation}. - * - * Note: this method does not add the {@link Operation} to the underlying store. - * a call to {@link #saveOperation(Operation)} is required to track the operation created - * with this method call. - * - * @param name the name. - * @return the new Operation. - * @throws RbacManagerException - */ - public Operation createOperation( String name ) - throws RbacManagerException - { - Operation operation; - - try - { - operation = getOperation( name ); - } - catch ( RbacObjectNotFoundException e ) - { - operation = new JdoOperation(); - operation.setName( name ); - } - - return operation; - } - - public Operation saveOperation( Operation operation ) - throws RbacObjectInvalidException, RbacManagerException - { - RBACObjectAssertions.assertValid( operation ); - return jdo.saveObject( operation, null ); - } - - public boolean operationExists( Operation operation ) - { - return jdo.objectExists( operation ); - } - - public boolean operationExists( String name ) - { - try - { - return jdo.objectExistsById( JdoOperation.class, name ); - } - catch ( RbacManagerException e ) - { - return false; - } - } - - public Operation getOperation( String operationName ) - throws RbacObjectNotFoundException, RbacManagerException - { - return jdo.getObjectById( JdoOperation.class, operationName, null ); - } - - @SuppressWarnings( "unchecked" ) - public List getAllOperations() - throws RbacManagerException - { - return (List) jdo.getAllObjects( JdoOperation.class ); - } - - public void removeOperation( Operation operation ) - throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException - { - RBACObjectAssertions.assertValid( operation ); - - if ( operation.isPermanent() ) - { - throw new RbacPermanentException( "Unable to delete permanent operation [" + operation.getName() + "]" ); - } - - jdo.removeObject( operation ); - } - - // ---------------------------------------------------------------------- - // Resource methods - // ---------------------------------------------------------------------- - - /** - * Creates an implementation specific {@link Resource}. - * - * Note: this method does not add the {@link Resource} to the underlying store. - * a call to {@link #saveResource(Resource)} is required to track the resource created - * with this method call. - * - * @param identifier the identifier. - * @return the new Resource. - * @throws RbacManagerException - */ - public Resource createResource( String identifier ) - throws RbacManagerException - { - Resource resource; - - try - { - resource = getResource( identifier ); - log.debug( "Create Resource [ {} ] Returning Existing.", identifier ); - } - catch ( RbacObjectNotFoundException e ) - { - resource = new JdoResource(); - resource.setIdentifier( identifier ); - log.debug( "Create Resource [ {} ] New JdoResource.", identifier ); - } - - return resource; - } - - public Resource saveResource( Resource resource ) - throws RbacObjectInvalidException, RbacManagerException - { - RBACObjectAssertions.assertValid( resource ); - return jdo.saveObject( resource, null ); - } - - public boolean resourceExists( Resource resource ) - { - return jdo.objectExists( resource ); - } - - public boolean resourceExists( String identifier ) - { - try - { - return jdo.objectExistsById( JdoResource.class, identifier ); - } - catch ( RbacManagerException e ) - { - return false; - } - } - - public Resource getResource( String resourceIdentifier ) - throws RbacObjectNotFoundException, RbacManagerException - { - return jdo.getObjectById( JdoResource.class, resourceIdentifier, null ); - } - - @SuppressWarnings( "unchecked" ) - public List getAllResources() - throws RbacManagerException - { - return (List) jdo.getAllObjects( JdoResource.class ); - } - - public void removeResource( Resource resource ) - throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException - { - RBACObjectAssertions.assertValid( resource ); - - if ( resource.isPermanent() ) - { - throw new RbacPermanentException( - "Unable to delete permanent resource [" + resource.getIdentifier() + "]" ); - } - - jdo.removeObject( resource ); - } - - // ---------------------------------------------------------------------- - // User Assignment methods - // ---------------------------------------------------------------------- - - /** - * Creates an implementation specific {@link UserAssignment}. - * - * Note: this method does not add the {@link UserAssignment} to the underlying store. - * a call to {@link #saveUserAssignment(UserAssignment)} is required to track the user - * assignment created with this method call. - * - * @param principal the principal reference to the user. - * @return the new UserAssignment with an empty (non-null) {@link UserAssignment#getRoleNames()} object. - */ - public UserAssignment createUserAssignment( String principal ) - { - UserAssignment ua; - - try - { - ua = getUserAssignment( principal ); - } - catch ( RbacManagerException e ) - { - ua = new JdoUserAssignment(); - ua.setPrincipal( principal ); - } - - return ua; - } - - /** - * Method addUserAssignment - * - * @param userAssignment - */ - public UserAssignment saveUserAssignment( UserAssignment userAssignment ) - throws RbacObjectInvalidException, RbacManagerException - { - RBACObjectAssertions.assertValid( "Save User Assignment", userAssignment ); - - fireRbacUserAssignmentSaved( userAssignment ); - - return jdo.saveObject( userAssignment, new String[]{ ROLE_DETAIL } ); - } - - public boolean userAssignmentExists( String principal ) - { - try - { - return jdo.objectExistsById( JdoUserAssignment.class, principal ); - } - catch ( RbacManagerException e ) - { - return false; - } - } - - public boolean userAssignmentExists( UserAssignment assignment ) - { - return jdo.objectExists( assignment ); - } - - public UserAssignment getUserAssignment( String principal ) - throws RbacObjectNotFoundException, RbacManagerException - { - return jdo.getObjectById( JdoUserAssignment.class, principal, ROLE_DETAIL ); - } - - /** - * Method getAssignments - */ - @SuppressWarnings( "unchecked" ) - public List getAllUserAssignments() - throws RbacManagerException - { - return (List) jdo.getAllObjects( JdoUserAssignment.class ); - } - - /** - * Method getUserAssignmentsForRoles - */ - @SuppressWarnings( "unchecked" ) - public List getUserAssignmentsForRoles( Collection roleNames ) - throws RbacManagerException - { - return (List) jdo.getUserAssignmentsForRoles( JdoUserAssignment.class, null, roleNames ); - } - - /** - * Method removeAssignment - * - * @param userAssignment - */ - public void removeUserAssignment( UserAssignment userAssignment ) - throws RbacObjectNotFoundException, RbacObjectInvalidException, RbacManagerException - { - RBACObjectAssertions.assertValid( userAssignment ); - - if ( userAssignment.isPermanent() ) - { - throw new RbacPermanentException( - "Unable to delete permanent user assignment [" + userAssignment.getPrincipal() + "]" ); - } - - fireRbacUserAssignmentRemoved( userAssignment ); - - jdo.removeObject( userAssignment ); - } - - public void eraseDatabase() - { - // Must delete in order so that FK constraints don't get violated - jdo.removeAll( JdoRole.class ); - jdo.removeAll( JdoPermission.class ); - jdo.removeAll( JdoOperation.class ); - jdo.removeAll( JdoResource.class ); - jdo.removeAll( JdoUserAssignment.class ); - jdo.removeAll( RbacJdoModelModelloMetadata.class ); - } - - @PostConstruct - public void initialize() - { - super.initialize(); - - jdo.setListener( this ); - if ( enableCache ) - { - jdo.enableCache( JdoRole.class ); - jdo.enableCache( JdoOperation.class ); - jdo.enableCache( JdoResource.class ); - jdo.enableCache( JdoUserAssignment.class ); - jdo.enableCache( JdoPermission.class ); - } - } - - public void rbacInit( boolean freshdb ) - { - fireRbacInit( freshdb ); - } - - public void rbacPermissionRemoved( Permission permission ) - { - fireRbacPermissionRemoved( permission ); - } - - public void rbacPermissionSaved( Permission permission ) - { - fireRbacPermissionSaved( permission ); - } - - public void rbacRoleRemoved( Role role ) - { - fireRbacRoleRemoved( role ); - } - - public void rbacRoleSaved( Role role ) - { - fireRbacRoleSaved( role ); - } - - - public void rbacUserAssignmentSaved( UserAssignment userAssignment ) - { - fireRbacUserAssignmentSaved( userAssignment ); - } - - public void rbacUserAssignmentRemoved( UserAssignment userAssignment ) - { - fireRbacUserAssignmentRemoved( userAssignment ); - } - - public JdoTool getJdo() - { - return jdo; - } - - public void setJdo( JdoTool jdo ) - { - this.jdo = jdo; - } - - public boolean isEnableCache() - { - return enableCache; - } - - public void setEnableCache( boolean enableCache ) - { - this.enableCache = enableCache; - } - - @Override - public boolean isFinalImplementation() - { - return true; - } - - public String getDescriptionKey() - { - return "archiva.redback.rbacmanager.jdo"; - } - - public boolean isReadOnly() - { - return false; - } -} diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/java/org/apache/archiva/redback/rbac/jdo/JdoTool.java b/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/java/org/apache/archiva/redback/rbac/jdo/JdoTool.java deleted file mode 100644 index 2d4233e3..00000000 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/java/org/apache/archiva/redback/rbac/jdo/JdoTool.java +++ /dev/null @@ -1,500 +0,0 @@ -package org.apache.archiva.redback.rbac.jdo; - -/* - * 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.rbac.Permission; -import org.apache.archiva.redback.rbac.RBACManagerListener; -import org.apache.archiva.redback.rbac.RbacManagerException; -import org.apache.archiva.redback.rbac.RbacObjectNotFoundException; -import org.apache.archiva.redback.rbac.Role; -import org.apache.archiva.redback.components.jdo.JdoFactory; -import org.apache.commons.lang.StringUtils; -import org.springframework.stereotype.Service; - -import javax.annotation.PostConstruct; -import javax.annotation.Resource; -import javax.jdo.Extent; -import javax.jdo.JDOException; -import javax.jdo.JDOHelper; -import javax.jdo.JDOObjectNotFoundException; -import javax.jdo.JDOUserException; -import javax.jdo.PersistenceManager; -import javax.jdo.PersistenceManagerFactory; -import javax.jdo.Query; -import javax.jdo.Transaction; -import javax.jdo.datastore.DataStoreCache; -import javax.jdo.listener.DeleteLifecycleListener; -import javax.jdo.listener.InstanceLifecycleEvent; -import javax.jdo.listener.StoreLifecycleListener; -import javax.jdo.spi.Detachable; -import javax.jdo.spi.PersistenceCapable; -import java.io.PrintStream; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -/** - * JdoTool - RBAC JDO Tools. - * - * @author Joakim Erdfelt - * - */ -@Service("jdoTool") -public class JdoTool - implements DeleteLifecycleListener, StoreLifecycleListener -{ - - @Resource(name="jdoFactory#users") - private JdoFactory jdoFactory; - - private PersistenceManagerFactory pmf; - - private RBACManagerListener listener; - - @PostConstruct - public void initialize() - { - pmf = jdoFactory.getPersistenceManagerFactory(); - - pmf.addInstanceLifecycleListener( this, null ); - } - - public static void dumpObjectState( PrintStream out, Object o ) - { - final String STATE = "[STATE] "; - final String INDENT = " "; - - if ( o == null ) - { - out.println( STATE + "Object is null." ); - return; - } - - out.println( STATE + "Object " + o.getClass().getName() ); - - if ( !( o instanceof PersistenceCapable ) ) - { - out.println( INDENT + "is NOT PersistenceCapable (not a jdo object?)" ); - return; - } - - out.println( INDENT + "is PersistenceCapable." ); - if ( o instanceof Detachable ) - { - out.println( INDENT + "is Detachable" ); - } - - out.println( INDENT + "is new : " + Boolean.toString( JDOHelper.isNew( o ) ) ); - out.println( INDENT + "is transactional : " + Boolean.toString( JDOHelper.isTransactional( o ) ) ); - out.println( INDENT + "is deleted : " + Boolean.toString( JDOHelper.isDeleted( o ) ) ); - out.println( INDENT + "is detached : " + Boolean.toString( JDOHelper.isDetached( o ) ) ); - out.println( INDENT + "is dirty : " + Boolean.toString( JDOHelper.isDirty( o ) ) ); - out.println( INDENT + "is persistent : " + Boolean.toString( JDOHelper.isPersistent( o ) ) ); - - out.println( INDENT + "object id : " + JDOHelper.getObjectId( o ) ); - } - - public PersistenceManager getPersistenceManager() - { - PersistenceManager pm = pmf.getPersistenceManager(); - - pm.getFetchPlan().setMaxFetchDepth( -1 ); - - triggerInit(); - - return pm; - } - - private boolean hasTriggeredInit = false; - - @SuppressWarnings("unchecked") - public void triggerInit() - { - if ( !hasTriggeredInit ) - { - hasTriggeredInit = true; - - List roles = (List) getAllObjects( JdoRole.class ); - - listener.rbacInit( roles.isEmpty() ); - } - } - - public void enableCache( Class clazz ) - { - DataStoreCache cache = pmf.getDataStoreCache(); - if ( cache.getClass().getName().equals( "org.jpox.cache.EhcacheClassBasedLevel2Cache" ) - || cache.getClass().getName().equals( "org.jpox.cache.EhcacheLevel2Cache" ) ) - { - /* Ehcache adapters don't support pinAll, the caching is handled in the configuration */ - return; - } - cache.pinAll( clazz, false ); // Pin all objects of type clazz from now on - } - - public T saveObject( T object ) - { - return (T) saveObject( object, null ); - } - - public T saveObject( T object, String[] fetchGroups ) - { - PersistenceManager pm = getPersistenceManager(); - Transaction tx = pm.currentTransaction(); - - try - { - tx.begin(); - - if ( ( JDOHelper.getObjectId( object ) != null ) && !JDOHelper.isDetached( object ) ) - { - // This is a fatal error that means we need to fix our code. - // Leave it as a JDOUserException, it's intentional. - throw new JDOUserException( "Existing object is not detached: " + object, object ); - } - - if ( fetchGroups != null ) - { - for ( int i = 0; i >= fetchGroups.length; i++ ) - { - pm.getFetchPlan().addGroup( fetchGroups[i] ); - } - } - - pm.makePersistent( object ); - - object = (T) pm.detachCopy( object ); - - tx.commit(); - - return object; - } - finally - { - rollbackIfActive( tx ); - } - } - - public List getAllObjects( Class clazz ) - { - return getAllObjects( clazz, null, null ); - } - - public List getAllObjects( Class clazz, String ordering ) - { - return getAllObjects( clazz, ordering, null ); - } - - public List getAllObjects( Class clazz, String ordering, String fetchGroup ) - { - PersistenceManager pm = getPersistenceManager(); - Transaction tx = pm.currentTransaction(); - - try - { - tx.begin(); - - Extent extent = pm.getExtent( clazz, true ); - - Query query = pm.newQuery( extent ); - - if ( ordering != null ) - { - query.setOrdering( ordering ); - } - - if ( fetchGroup != null ) - { - pm.getFetchPlan().addGroup( fetchGroup ); - } - - List result = (List) query.execute(); - - result = (List) pm.detachCopyAll( result ); - - tx.commit(); - - return result; - } - finally - { - rollbackIfActive( tx ); - } - } - - public List getUserAssignmentsForRoles( Class clazz, String ordering, Collection roleNames ) - { - PersistenceManager pm = getPersistenceManager(); - Transaction tx = pm.currentTransaction(); - - try - { - tx.begin(); - - Extent extent = pm.getExtent( clazz, true ); - - Query query = pm.newQuery( extent ); - - if ( ordering != null ) - { - query.setOrdering( ordering ); - } - - query.declareImports( "import java.lang.String" ); - - StringBuilder filter = new StringBuilder(); - - if ( roleNames.size() > 0 ) - { - Iterator i = roleNames.iterator(); - - filter.append( "this.roleNames.contains(\"" ).append( i.next() ).append( "\")" ); - - while ( i.hasNext() ) - { - filter.append( " || this.roleNames.contains(\"" ).append( i.next() ).append( "\")" ); - } - - query.setFilter( filter.toString() ); - } - - List result = (List) query.execute(); - - result = (List) pm.detachCopyAll( result ); - - tx.commit(); - - return result; - } - finally - { - rollbackIfActive( tx ); - } - } - - public T getObjectById( Class clazz, String id, String fetchGroup ) - throws RbacObjectNotFoundException, RbacManagerException - { - if ( StringUtils.isEmpty( id ) ) - { - throw new RbacObjectNotFoundException( - "Unable to get object '" + clazz.getName() + "' from jdo using null/empty id." ); - } - - PersistenceManager pm = getPersistenceManager(); - Transaction tx = pm.currentTransaction(); - - try - { - tx.begin(); - - if ( fetchGroup != null ) - { - pm.getFetchPlan().addGroup( fetchGroup ); - } - - Object objectId = pm.newObjectIdInstance( clazz, id ); - - Object object = pm.getObjectById( objectId ); - - object = pm.detachCopy( object ); - - tx.commit(); - - return (T) object; - } - catch ( JDOObjectNotFoundException e ) - { - throw new RbacObjectNotFoundException( "Unable to find RBAC Object '" + id + "' of type " + - clazz.getName() + " using fetch-group '" + fetchGroup + "'", e, id ); - } - catch ( JDOException e ) - { - throw new RbacManagerException( "Error in JDO during get of RBAC object id '" + id + "' of type " + - clazz.getName() + " using fetch-group '" + fetchGroup + "'", e ); - } - finally - { - rollbackIfActive( tx ); - } - } - - public boolean objectExists( Object object ) - { - return ( JDOHelper.getObjectId( object ) != null ); - } - - public boolean objectExistsById( Class clazz, String id ) - throws RbacManagerException - { - try - { - Object o = getObjectById( clazz, id, null ); - return ( o != null ); - } - catch ( RbacObjectNotFoundException e ) - { - return false; - } - } - - public T removeObject( T o ) - throws RbacManagerException - { - if ( o == null ) - { - throw new RbacManagerException( "Unable to remove null object" ); - } - - PersistenceManager pm = getPersistenceManager(); - Transaction tx = pm.currentTransaction(); - - try - { - tx.begin(); - - o = (T) pm.getObjectById( pm.getObjectId( o ) ); - - pm.deletePersistent( o ); - - tx.commit(); - - return o; - } - finally - { - rollbackIfActive( tx ); - } - } - - public void rollbackIfActive( Transaction tx ) - { - PersistenceManager pm = tx.getPersistenceManager(); - - try - { - if ( tx.isActive() ) - { - tx.rollback(); - } - } - finally - { - closePersistenceManager( pm ); - } - } - - public void closePersistenceManager( PersistenceManager pm ) - { - try - { - pm.close(); - } - catch ( JDOUserException e ) - { - // ignore - } - } - - public RBACManagerListener getListener() - { - return listener; - } - - public void setListener( RBACManagerListener listener ) - { - this.listener = listener; - } - - public void postDelete( InstanceLifecycleEvent evt ) - { - PersistenceCapable obj = ( (PersistenceCapable) evt.getSource() ); - - if ( obj == null ) - { - // Do not track null objects. - // These events are typically a product of an internal lifecycle event. - return; - } - - if ( obj instanceof Role ) - { - listener.rbacRoleRemoved( (Role) obj ); - } - else if ( obj instanceof Permission ) - { - listener.rbacPermissionRemoved( (Permission) obj ); - } - } - - public void preDelete( InstanceLifecycleEvent evt ) - { - // ignore - } - - public void postStore( InstanceLifecycleEvent evt ) - { - PersistenceCapable obj = ( (PersistenceCapable) evt.getSource() ); - - if ( obj instanceof Role ) - { - listener.rbacRoleSaved( (Role) obj ); - } - else if ( obj instanceof Permission ) - { - listener.rbacPermissionSaved( (Permission) obj ); - } - } - - public void preStore( InstanceLifecycleEvent evt ) - { - // ignore - } - - public void removeAll( Class aClass ) - { - PersistenceManager pm = getPersistenceManager(); - Transaction tx = pm.currentTransaction(); - - try - { - tx.begin(); - - Query query = pm.newQuery( aClass ); - query.deletePersistentAll(); - - tx.commit(); - } - finally - { - rollbackIfActive( tx ); - } - } - - public JdoFactory getJdoFactory() - { - return jdoFactory; - } - - public void setJdoFactory( JdoFactory jdoFactory ) - { - this.jdoFactory = jdoFactory; - } -} diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/mdo/rbac-jdo.mdo b/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/mdo/rbac-jdo.mdo deleted file mode 100644 index ebd9eccb..00000000 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/mdo/rbac-jdo.mdo +++ /dev/null @@ -1,337 +0,0 @@ - - - - - - rbac-jdo - RbacJdoModel - 1.0.1 - - - package - org.apache.archiva.redback.rbac.jdo - - - - - RbacDatabase - 1.0.1+ - - - roles - 1.0.1+ - - JdoRole - * - - - - permissions - 1.0.1+ - - JdoPermission - * - - - - operations - 1.0.1+ - - JdoOperation - * - - - - resources - 1.0.1+ - - JdoResource - * - - - - userAssignments - 1.0.1+ - - JdoUserAssignment - * - - - - - - - JdoRole - 1.0.0+ - - org.apache.archiva.redback.rbac.Role - - org.apache.archiva.redback.rbac.AbstractRole - - - name - 1.0.0+ - String - true - - - description - 1.0.0+ - String - - - assignable - 1.0.0+ - boolean - - true if this role is available to be assigned to a user - - - - permanent - 1.0.0+ - boolean - - true if this object is permanent. - - - - childRoleNames - 1.0.0+ - - String - * - - - roles that will inherit the permissions of this role - - - - permissions - 1.0.0+ - - JdoPermission - * - - - - - - - JdoPermission - 1.0.0+ - - org.apache.archiva.redback.rbac.Permission - - - - name - 1.0.0+ - String - true - - - description - 1.0.0+ - String - - - permanent - 1.0.0+ - boolean - - true if this object is permanent. - - - - operation - 1.0.0+ - - JdoOperation - 1 - - - - resource - 1.0.0+ - - JdoResource - 1 - - - - - - - JdoOperation - 1.0.0+ - - org.apache.archiva.redback.rbac.Operation - - - - name - 1.0.0+ - String - true - - - description - 1.0.0+ - String - - - permanent - 1.0.0+ - boolean - - true if this object is permanent. - - - - resourceRequired - 1.0.0+ - boolean - - true if the resource is required for authorization to be granted - - - - - - - JdoResource - 1.0.0+ - - In RBAC terms, this is the entity which an operation is associated with that which permissions are based on. - - - org.apache.archiva.redback.rbac.Resource - - - - identifier - 1.0.0+ - String - - The string identifier for a resource. - - true - - - pattern - 1.0.0+ - boolean - - true if the identifer is a pattern that is to be evaluated, for example x.* could match x.a or x.b and x.** - could match x.foo - - - - permanent - 1.0.0+ - boolean - - true if this object is permanent. - - - - - - - JdoUserAssignment - binding of a principal to a role - 1.0.0+ - - org.apache.archiva.redback.rbac.UserAssignment - - org.apache.archiva.redback.rbac.AbstractUserAssignment - - - principal - 1.0.0+ - String - true - - - timestamp - 1.0.0+ - Date - - - permanent - 1.0.0+ - boolean - - true if this object is permanent. - - - - roleNames - 1.0.0+ - - String - * - - - - - - diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/resources/META-INF/spring-context.xml b/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/resources/META-INF/spring-context.xml deleted file mode 100644 index 2a3dec13..00000000 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/resources/META-INF/spring-context.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/java/org/apache/archiva/redback/rbac/jdo/JdoRbacManagerTest.java b/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/java/org/apache/archiva/redback/rbac/jdo/JdoRbacManagerTest.java deleted file mode 100644 index 0572706b..00000000 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/java/org/apache/archiva/redback/rbac/jdo/JdoRbacManagerTest.java +++ /dev/null @@ -1,219 +0,0 @@ -package org.apache.archiva.redback.rbac.jdo; - -/* - * 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.common.jdo.test.StoreManagerDebug; -import org.apache.archiva.redback.components.jdo.DefaultConfigurableJdoFactory; -import org.apache.archiva.redback.rbac.RBACManager; -import org.apache.archiva.redback.rbac.RbacManagerException; -import org.apache.archiva.redback.tests.AbstractRbacManagerTestCase; -import org.jpox.AbstractPersistenceManagerFactory; -import org.jpox.SchemaTool; -import org.junit.Before; -import org.springframework.test.annotation.DirtiesContext; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.jdo.PersistenceManager; -import javax.jdo.PersistenceManagerFactory; -import java.io.File; -import java.net.URL; -import java.util.Map; -import java.util.Properties; - -/** - * JdoRbacManagerTest: - * - * @author Jesse McConnell - * @author Joakim Erdfelt - */ -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -public class JdoRbacManagerTest - extends AbstractRbacManagerTestCase -{ - private StoreManagerDebug storeManager; - - @Inject - @Named(value = "jdoFactory#users") - DefaultConfigurableJdoFactory jdoFactory; - - @Inject - @Named(value = "rbacManager#jdo") - RBACManager rbacManager; - - public static int EVENTCOUNT = 2; - - @Override - public void assertEventCount() - { - assertEquals( EVENTCOUNT, eventTracker.initCount ); - } - - /** - * Creates a new RbacStore which contains no data. - */ - @Before - public void setUp() - throws Exception - { - - super.setUp(); - - assertEquals( DefaultConfigurableJdoFactory.class.getName(), jdoFactory.getClass().getName() ); - - jdoFactory.setPersistenceManagerFactoryClass( "org.jpox.PersistenceManagerFactoryImpl" ); //$NON-NLS-1$ - - jdoFactory.setDriverName( - System.getProperty( "jdo.test.driver", "org.hsqldb.jdbcDriver" ) ); //$NON-NLS-1$ //$NON-NLS-2$ - - jdoFactory.setUrl( - System.getProperty( "jdo.test.url", "jdbc:hsqldb:mem:" + getName() ) ); //$NON-NLS-1$ //$NON-NLS-2$ - - jdoFactory.setUserName( System.getProperty( "jdo.test.user", "sa" ) ); //$NON-NLS-1$ - - jdoFactory.setPassword( System.getProperty( "jdo.test.pass", "" ) ); //$NON-NLS-1$ - - jdoFactory.setProperty( "org.jpox.transactionIsolation", "READ_COMMITTED" ); //$NON-NLS-1$ //$NON-NLS-2$ - - jdoFactory.setProperty( "org.jpox.poid.transactionIsolation", "READ_COMMITTED" ); //$NON-NLS-1$ //$NON-NLS-2$ - - jdoFactory.setProperty( "org.jpox.autoCreateSchema", "true" ); //$NON-NLS-1$ //$NON-NLS-2$ - - jdoFactory.setProperty( "org.jpox.autoCreateTables", "true" ); - - jdoFactory.setProperty( "javax.jdo.option.RetainValues", "true" ); - - jdoFactory.setProperty( "javax.jdo.option.RestoreValues", "true" ); - - // jdoFactory.setProperty( "org.jpox.autoCreateColumns", "true" ); - - jdoFactory.setProperty( "org.jpox.validateTables", "true" ); - - jdoFactory.setProperty( "org.jpox.validateColumns", "true" ); - - jdoFactory.setProperty( "org.jpox.validateConstraints", "true" ); - - /* Enable the level 2 Ehcache class-based cache */ - jdoFactory.setProperty( "org.jpox.cache.level2", "true" ); - jdoFactory.setProperty( "org.jpox.cache.level2.type", "ehcacheclassbased" ); - jdoFactory.setProperty( "org.jpox.cache.level2.configurationFile", "/ehcache.xml" ); // ehcache config - jdoFactory.setProperty( "org.jpox.cache.level2.cacheName", "default" ); // default cache name - - Properties properties = jdoFactory.getProperties(); - - for ( Map.Entry entry : properties.entrySet() ) - { - System.setProperty( (String) entry.getKey(), (String) entry.getValue() ); - } - - URL[] jdoFileUrls = - new URL[]{ getClass().getResource( "/org/apache/archiva/redback/rbac/jdo/package.jdo" ) }; //$NON-NLS-1$ - - if ( ( jdoFileUrls == null ) || ( jdoFileUrls[0] == null ) ) - { - fail( "Unable to process test " + getName() + " - missing package.jdo." ); - } - - File propsFile = null; // intentional - boolean verbose = true; - - PersistenceManagerFactory pmf = jdoFactory.getPersistenceManagerFactory(); - - assertNotNull( pmf ); - - /* set our own Store Manager to allow counting SQL statements */ - StoreManagerDebug.setup( (AbstractPersistenceManagerFactory) pmf ); - - /* clean up the db */ - SchemaTool.deleteSchemaTables( jdoFileUrls, new URL[]{ }, propsFile, verbose ); - SchemaTool.createSchemaTables( jdoFileUrls, new URL[]{ }, propsFile, verbose, null ); - - PersistenceManager pm = pmf.getPersistenceManager(); - - pm.close(); - - setRbacManager( rbacManager ); - - /* save the store manager to access the queries executed */ - JdoRbacManager rbacManager = (JdoRbacManager) getRbacManager(); - storeManager = StoreManagerDebug.getConfiguredStoreManager( rbacManager.getJdo().getPersistenceManager() ); - } - - - @Override - public void testGetAssignedRoles() - throws RbacManagerException - { - storeManager.resetCounter(); - super.testGetAssignedRoles(); - int counter = storeManager.counter(); - /* without Level 2 cache: 15 queries */ - /* with Level 2 cache: 8 queries */ - assertEquals( "Number of SQL queries", 8, counter ); - } - - @Override - public void testGetAssignedPermissionsDeep() - throws RbacManagerException - { - super.testGetAssignedPermissionsDeep(); - int counter = storeManager.counter(); - /* without Level 2 cache: 26 queries */ - /* with Level 2 cache: 10 queries */ - assertEquals( "Number of SQL queries", 10, counter ); - } - - @Override - protected void afterSetup() - { - super.afterSetup(); - storeManager.resetCounter(); - } - - @Override - public void testLargeApplicationInit() - throws RbacManagerException - { - this.clearCache(); - super.testLargeApplicationInit(); - } - - @Override - public void testGetRolesDeep() - throws RbacManagerException - { - this.clearCache(); - super.testGetRolesDeep(); - } - - - @Override - public void testStoreInitialization() - throws Exception - { - this.clearCache(); - rbacManager.eraseDatabase(); - eventTracker.rbacInit( true ); - super.testStoreInitialization(); - assertEquals( EVENTCOUNT, eventTracker.initCount ); - } - - -} diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/java/org/apache/archiva/redback/rbac/jdo/RbacJdoModelStaxTest.java b/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/java/org/apache/archiva/redback/rbac/jdo/RbacJdoModelStaxTest.java deleted file mode 100644 index cde20d68..00000000 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/java/org/apache/archiva/redback/rbac/jdo/RbacJdoModelStaxTest.java +++ /dev/null @@ -1,198 +0,0 @@ -package org.apache.archiva.redback.rbac.jdo; - -/* - * 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 java.io.IOException; -import java.io.StringReader; -import java.io.StringWriter; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.List; -import java.util.Locale; - -import javax.xml.stream.XMLStreamException; - -import junit.framework.TestCase; - -import org.apache.archiva.redback.rbac.Operation; -import org.apache.archiva.redback.rbac.Permission; -import org.apache.archiva.redback.rbac.Resource; -import org.apache.archiva.redback.rbac.jdo.io.stax.RbacJdoModelStaxReader; -import org.apache.archiva.redback.rbac.jdo.io.stax.RbacJdoModelStaxWriter; - - -/** - * Test the StAX reader and writer generated. - */ -public class RbacJdoModelStaxTest - extends TestCase -{ - @SuppressWarnings("unchecked") - public void testStax() - throws IOException, XMLStreamException - { - RbacDatabase database = new RbacDatabase(); - - JdoRole role = new JdoRole(); - role.setAssignable( true ); - role.setDescription( "descriptor" ); - role.setName( "name" ); - role.setPermanent( true ); - role.addChildRoleName( "childRole1" ); - role.addChildRoleName( "childRole2" ); - - JdoPermission permission = new JdoPermission(); - permission.setDescription( "permDesc" ); - permission.setName( "permName" ); - - JdoOperation operation = new JdoOperation(); - operation.setDescription( "opDesc" ); - operation.setName( "opName" ); - operation.setPermanent( true ); - operation.setResourceRequired( true ); - permission.setOperation( operation ); - database.addOperation( operation ); - - JdoResource resource = new JdoResource(); - resource.setIdentifier( "resId" ); - resource.setPattern( true ); - resource.setPermanent( true ); - permission.setResource( resource ); - database.addResource( resource ); - permission.setPermanent( true ); - role.addPermission( permission ); - database.addPermission( permission ); - - database.addRole( role ); - - JdoUserAssignment assignment = new JdoUserAssignment(); - assignment.setPermanent( false ); - assignment.setPrincipal( "principal" ); - assignment.setTimestamp( new Date() ); - assignment.addRoleName( "name" ); - - database.addUserAssignment( assignment ); - - StringWriter w = new StringWriter(); - new RbacJdoModelStaxWriter().write( w, database ); - - RbacDatabase newDatabase = new RbacJdoModelStaxReader().read( new StringReader( w.toString() ) ); - - List expectedRoles = database.getRoles(); - List roles = newDatabase.getRoles(); - assertEquals( expectedRoles.size(), roles.size() ); - for ( JdoRole r : roles ) - { - boolean found = false; - for ( JdoRole expectedRole : expectedRoles ) - { - if ( expectedRole.getName().equals( r.getName() ) ) - { - found = true; - - assertRole( expectedRole, r ); - } - } - if ( !found ) - { - fail( "Couldn't find role: " + r.getName() ); - } - } - - List expectedUserAssignments = database.getUserAssignments(); - List userAssignments = newDatabase.getUserAssignments(); - assertEquals( expectedUserAssignments.size(), userAssignments.size() ); - for ( JdoUserAssignment a : userAssignments ) - { - boolean found = false; - for ( JdoUserAssignment expectedAssignment : expectedUserAssignments ) - { - if ( expectedAssignment.getPrincipal().equals( a.getPrincipal() ) ) - { - found = true; - - assertUserAssignment( expectedAssignment, a ); - } - } - if ( !found ) - { - fail( "Couldn't find assignment: " + a.getPrincipal() ); - } - } - } - - @SuppressWarnings("unchecked") - private void assertRole( JdoRole expectedRole, JdoRole role ) - { - assertEquals( expectedRole.getDescription(), role.getDescription() ); - assertPermissions( expectedRole.getPermissions(), role.getPermissions() ); - assertEquals( expectedRole.getChildRoleNames(), role.getChildRoleNames() ); - } - - private void assertUserAssignment( JdoUserAssignment expectedAssignment, JdoUserAssignment assignment ) - { - SimpleDateFormat sdf = new SimpleDateFormat( "EEE, d MMM yyyy HH:mm:ss Z", Locale.US ); - assertNotNull( expectedAssignment.getTimestamp() ); - assertNotNull( assignment.getTimestamp() ); - - assertEquals( sdf.format( expectedAssignment.getTimestamp() ), sdf.format( assignment.getTimestamp() ) ); - assertEquals( expectedAssignment.getRoleNames(), assignment.getRoleNames() ); - } - - private void assertPermissions( List expectedPermissions, List permissions ) - { - assertEquals( expectedPermissions.size(), permissions.size() ); - for ( Permission permission : permissions ) - { - boolean found = false; - for ( Permission expectedPermission : expectedPermissions ) - { - if ( expectedPermission.getName().equals( permission.getName() ) ) - { - found = true; - - assertPermission( expectedPermission, permission ); - } - } - if ( !found ) - { - fail( "Couldn't find permission: " + permission.getName() ); - } - } - } - - private void assertPermission( Permission expectedPermission, Permission permission ) - { - assertEquals( expectedPermission.getDescription(), permission.getDescription() ); - assertOperation( expectedPermission.getOperation(), permission.getOperation() ); - assertResource( expectedPermission.getResource(), permission.getResource() ); - } - - private void assertResource( Resource expectedResource, Resource resource ) - { - assertEquals( expectedResource.getIdentifier(), resource.getIdentifier() ); - } - - private void assertOperation( Operation expectedOperation, Operation operation ) - { - assertEquals( expectedOperation.getName(), operation.getName() ); - assertEquals( expectedOperation.getDescription(), operation.getDescription() ); - } -} diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/resources/ehcache.xml b/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/resources/ehcache.xml deleted file mode 100644 index 34e6626f..00000000 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/resources/ehcache.xml +++ /dev/null @@ -1,90 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/resources/spring-context.xml b/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/resources/spring-context.xml deleted file mode 100644 index 34e8738e..00000000 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/resources/spring-context.xml +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - - - - - - - - - JDK_DEFAULT_TIMEZONE - true - true - ehcacheclassbased - /ehcache.xml - defaultfake - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/redback-users/redback-users-providers/redback-users-jdo/pom.xml b/redback-users/redback-users-providers/redback-users-jdo/pom.xml deleted file mode 100644 index 9b889a61..00000000 --- a/redback-users/redback-users-providers/redback-users-jdo/pom.xml +++ /dev/null @@ -1,176 +0,0 @@ - - - - - 4.0.0 - - - org.apache.archiva.redback - redback-users-providers - 2.5-SNAPSHOT - - - redback-users-jdo - jar - Redback :: Users Provider :: JDO - - - - org.codehaus.plexus - plexus-utils - - - org.apache.archiva.redback - redback-common-jdo - - - org.apache.archiva.redback - redback-policy - - - org.springframework - spring-context-support - - - javax.annotation - jsr250-api - - - org.apache.archiva.redback - redback-users-tests - test - - - org.hsqldb - hsqldb - test - - - net.java.dev.stax-utils - stax-utils - 20060502 - - - com.bea.xml - jsr173-ri - - - - - - org.slf4j - slf4j-simple - test - - - org.slf4j - jul-to-slf4j - test - - - - - - - org.apache.felix - maven-bundle-plugin - - - bundle-manifest - process-classes - - manifest - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - - - - org.codehaus.modello - modello-maven-plugin - - 1.0.1 - false - - src/main/mdo/user.mdo - - - - - modello-java - - java - stax-reader - stax-writer - - - - - - org.apache.archiva.redback.components.modello - jpox-modello-maven-plugin - - 1.0.1 - false - - src/main/mdo/user.mdo - - - - - modello-jpox - - jpox-metadata-class - - - - jpox-jdo-mapping - - jpox-jdo-mapping - - - ${project.build.outputDirectory}/org/apache/archiva/redback/users/jdo - - - - - - org.codehaus.mojo - jpox-maven-plugin - - - - enhance - - - - - - - - diff --git a/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/JdoUserManager.java b/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/JdoUserManager.java deleted file mode 100644 index 2369a168..00000000 --- a/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/JdoUserManager.java +++ /dev/null @@ -1,466 +0,0 @@ -package org.apache.archiva.redback.users.jdo; - -/* - * 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.components.jdo.JdoFactory; -import org.apache.archiva.redback.components.jdo.RedbackJdoUtils; -import org.apache.archiva.redback.components.jdo.RedbackObjectNotFoundException; -import org.apache.archiva.redback.components.jdo.RedbackStoreException; -import org.apache.archiva.redback.policy.UserSecurityPolicy; -import org.apache.archiva.redback.users.AbstractUserManager; -import org.apache.archiva.redback.users.PermanentUserException; -import org.apache.archiva.redback.users.User; -import org.apache.archiva.redback.users.UserManagerException; -import org.apache.archiva.redback.users.UserNotFoundException; -import org.apache.archiva.redback.users.UserQuery; -import org.codehaus.plexus.util.StringUtils; -import org.jpox.JDOClassLoaderResolver; -import org.springframework.stereotype.Service; - -import javax.annotation.PostConstruct; -import javax.inject.Inject; -import javax.inject.Named; -import javax.jdo.Extent; -import javax.jdo.PersistenceManager; -import javax.jdo.PersistenceManagerFactory; -import javax.jdo.Query; -import javax.jdo.Transaction; -import java.util.Date; -import java.util.List; - -/** - * JdoUserManager - * - * @author Joakim Erdfelt - */ -@Service("userManager#jdo") -public class JdoUserManager - extends AbstractUserManager -{ - @Inject - @Named(value = "jdoFactory#users") - private JdoFactory jdoFactory; - - @Inject - private UserSecurityPolicy userSecurityPolicy; - - private PersistenceManagerFactory pmf; - - public String getId() - { - return "jdo"; - } - - - public boolean isReadOnly() - { - return false; - } - - public UserQuery createUserQuery() - { - return new JdoUserQuery(); - } - - // ------------------------------------------------------------------ - - public User createUser( String username, String fullname, String email ) - { - User user = new JdoUser(); - user.setUsername( username ); - user.setFullName( fullname ); - user.setEmail( email ); - user.setAccountCreationDate( new Date() ); - - return user; - } - - public List getUsers() - { - return getAllObjectsDetached( null ); - } - - public List getUsers( boolean orderAscending ) - { - String ordering = orderAscending ? "username ascending" : "username descending"; - - return getAllObjectsDetached( ordering ); - } - - @SuppressWarnings("unchecked") - private List getAllObjectsDetached( String ordering ) - { - return RedbackJdoUtils.getAllObjectsDetached( getPersistenceManager(), JdoUser.class, ordering, (String) null ); - } - - public List findUsersByUsernameKey( String usernameKey, boolean orderAscending ) - { - return findUsers( "username", usernameKey, orderAscending ); - } - - public List findUsersByFullNameKey( String fullNameKey, boolean orderAscending ) - { - return findUsers( "fullName", fullNameKey, orderAscending ); - } - - public List findUsersByEmailKey( String emailKey, boolean orderAscending ) - { - return findUsers( "email", emailKey, orderAscending ); - } - - @SuppressWarnings("unchecked") - public List findUsersByQuery( UserQuery userQuery ) - { - JdoUserQuery uq = (JdoUserQuery) userQuery; - - PersistenceManager pm = getPersistenceManager(); - - Transaction tx = pm.currentTransaction(); - - try - { - tx.begin(); - - Extent extent = pm.getExtent( JdoUser.class, true ); - - Query query = pm.newQuery( extent ); - - String ordering = uq.getOrdering(); - - query.setOrdering( ordering ); - - query.declareImports( "import java.lang.String" ); - - query.declareParameters( uq.getParameters() ); - - query.setFilter( uq.getFilter() ); - - query.setRange( uq.getFirstResult(), - uq.getMaxResults() < 0 ? Long.MAX_VALUE : uq.getFirstResult() + uq.getMaxResults() ); - - List result = (List) query.executeWithArray( uq.getSearchKeys() ); - - result = (List) pm.detachCopyAll( result ); - - tx.commit(); - - return result; - } - finally - { - rollback( tx ); - } - } - - @SuppressWarnings("unchecked") - private List findUsers( String searchField, String searchKey, boolean ascendingUsername ) - { - PersistenceManager pm = getPersistenceManager(); - - Transaction tx = pm.currentTransaction(); - - try - { - tx.begin(); - - Extent extent = pm.getExtent( JdoUser.class, true ); - - Query query = pm.newQuery( extent ); - - String ordering = ascendingUsername ? "username ascending" : "username descending"; - - query.setOrdering( ordering ); - - query.declareImports( "import java.lang.String" ); - - query.declareParameters( "String searchKey" ); - - query.setFilter( "this." + searchField + ".toLowerCase().indexOf(searchKey.toLowerCase()) > -1" ); - - List result = (List) query.execute( searchKey ); - - result = (List) pm.detachCopyAll( result ); - - tx.commit(); - - return result; - } - finally - { - rollback( tx ); - } - } - - public User addUser( User user ) - throws UserManagerException - { - if ( !( user instanceof JdoUser ) ) - { - throw new UserManagerException( "Unable to Add User. User object " + user.getClass().getName() + - " is not an instance of " + JdoUser.class.getName() ); - } - - if ( StringUtils.isEmpty( user.getUsername() ) ) - { - throw new IllegalStateException( - Messages.getString( "user.manager.cannot.add.user.without.username" ) ); //$NON-NLS-1$ - } - - userSecurityPolicy.extensionChangePassword( user ); - - fireUserManagerUserAdded( user ); - - // TODO: find a better solution - // workaround for avoiding the admin from providing another password on the next login after the - // admin account has been created - // extensionChangePassword by default sets the password change status to false - if ( "admin".equals( user.getUsername() ) ) - { - user.setPasswordChangeRequired( false ); - } - else - { - user.setPasswordChangeRequired( true ); - } - - return (User) addObject( user ); - } - - public void deleteUser( String username ) - throws UserManagerException - { - try - { - User user = findUser( username ); - - if ( user.isPermanent() ) - { - throw new PermanentUserException( "Cannot delete permanent user [" + user.getUsername() + "]." ); - } - - fireUserManagerUserRemoved( user ); - - RedbackJdoUtils.removeObject( getPersistenceManager(), user ); - } - catch ( UserNotFoundException e ) - { - log.warn( "Unable to delete user {}, user not found.", username, e ); - } - } - - public void addUserUnchecked( User user ) - throws UserManagerException - { - if ( !( user instanceof JdoUser ) ) - { - throw new UserManagerException( "Unable to Add User. User object " + user.getClass().getName() + - " is not an instance of " + JdoUser.class.getName() ); - } - - if ( StringUtils.isEmpty( user.getUsername() ) ) - { - throw new IllegalStateException( - Messages.getString( "user.manager.cannot.add.user.without.username" ) ); //$NON-NLS-1$ - } - - addObject( user ); - } - - public void eraseDatabase() - { - RedbackJdoUtils.removeAll( getPersistenceManager(), JdoUser.class ); - RedbackJdoUtils.removeAll( getPersistenceManager(), UsersManagementModelloMetadata.class ); - } - - public User findUser( String username ) - throws UserNotFoundException, UserManagerException - { - if ( StringUtils.isEmpty( username ) ) - { - throw new UserNotFoundException( "User with empty username not found." ); - } - - return (User) getObjectById( username, null ); - } - - @Override - public User findUser( String username, boolean useCache ) - throws UserNotFoundException, UserManagerException - { - return findUser( username ); - } - - public boolean userExists( String principal ) - throws UserManagerException - { - try - { - findUser( principal ); - return true; - } - catch ( UserNotFoundException ne ) - { - return false; - } - } - - public User updateUser( User user ) - throws UserNotFoundException, UserManagerException - { - return updateUser( user, false ); - } - - public User updateUser( User user, boolean passwordChangeRequired ) - throws UserNotFoundException, UserManagerException - { - if ( !( user instanceof JdoUser ) ) - { - throw new UserManagerException( "Unable to Update User. User object " + user.getClass().getName() + - " is not an instance of " + JdoUser.class.getName() ); - } - - // If password is supplied, assume changing of password. - // TODO: Consider adding a boolean to the updateUser indicating a password change or not. - if ( StringUtils.isNotEmpty( user.getPassword() ) ) - { - userSecurityPolicy.extensionChangePassword( user, passwordChangeRequired ); - } - - user = (User) updateObject( user ); - - fireUserManagerUserUpdated( user ); - - return user; - } - - @PostConstruct - public void initialize() - { - JDOClassLoaderResolver d; - pmf = jdoFactory.getPersistenceManagerFactory(); - } - - public PersistenceManager getPersistenceManager() - { - PersistenceManager pm = pmf.getPersistenceManager(); - - pm.getFetchPlan().setMaxFetchDepth( -1 ); - - triggerInit(); - - return pm; - } - - // ---------------------------------------------------------------------- - // jdo utility methods - // ---------------------------------------------------------------------- - - private Object addObject( Object object ) - { - return RedbackJdoUtils.addObject( getPersistenceManager(), object ); - } - - private Object getObjectById( String id, String fetchGroup ) - throws UserNotFoundException, UserManagerException - { - try - { - return RedbackJdoUtils.getObjectById( getPersistenceManager(), JdoUser.class, id, fetchGroup ); - } - catch ( RedbackObjectNotFoundException e ) - { - throw new UserNotFoundException( e.getMessage() ); - } - catch ( RedbackStoreException e ) - { - throw new UserManagerException( "Unable to get object '" + JdoUser.class.getName() + "', id '" + id + - "', fetch-group '" + fetchGroup + "' from jdo store.", e ); - } - } - - private Object removeObject( Object o ) - throws UserManagerException - { - if ( o == null ) - { - throw new UserManagerException( "Unable to remove null object" ); - } - - RedbackJdoUtils.removeObject( getPersistenceManager(), o ); - return o; - } - - private Object updateObject( Object object ) - throws UserNotFoundException, UserManagerException - { - try - { - return RedbackJdoUtils.updateObject( getPersistenceManager(), object ); - } - catch ( RedbackStoreException e ) - { - throw new UserManagerException( - "Unable to update the '" + object.getClass().getName() + "' object in the jdo database. Cause: " + e.getMessage(), e ); - } - } - - private void rollback( Transaction tx ) - { - RedbackJdoUtils.rollbackIfActive( tx ); - } - - private boolean hasTriggeredInit = false; - - public void triggerInit() - { - if ( !hasTriggeredInit ) - { - hasTriggeredInit = true; - List users = getAllObjectsDetached( null ); - - fireUserManagerInit( users.isEmpty() ); - } - } - - public JdoFactory getJdoFactory() - { - return jdoFactory; - } - - public void setJdoFactory( JdoFactory jdoFactory ) - { - this.jdoFactory = jdoFactory; - } - - public UserSecurityPolicy getUserSecurityPolicy() - { - return userSecurityPolicy; - } - - public boolean isFinalImplementation() - { - return true; - } - - public String getDescriptionKey() - { - return "archiva.redback.usermanager.jdo"; - } -} diff --git a/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/JdoUserQuery.java b/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/JdoUserQuery.java deleted file mode 100644 index 2a06caac..00000000 --- a/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/JdoUserQuery.java +++ /dev/null @@ -1,136 +0,0 @@ -package org.apache.archiva.redback.users.jdo; - -/* - * 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.users.AbstractUserQuery; -import org.apache.archiva.redback.users.UserQuery; -import org.codehaus.plexus.util.StringUtils; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - - -public class JdoUserQuery - extends AbstractUserQuery -{ - - /** - * Create the ordering string for use in {@link javax.jdo.Query#setOrdering(String)} - * - * @return the created filter - */ - public String getOrdering() - { - StringBuilder ordering = new StringBuilder(); - - if ( UserQuery.ORDER_BY_EMAIL.equals( getOrderBy() ) ) - { - ordering.append( "email" ); - } - else if ( UserQuery.ORDER_BY_FULLNAME.equals( getOrderBy() ) ) - { - ordering.append( "fullName" ); - } - else - { - ordering.append( "username" ); - } - ordering.append( " " ).append( isAscending() ? "ascending" : "descending" ); - return ordering.toString(); - } - - /** - * Create and return the filter string for use in {@link javax.jdo.Query#setFilter(String)} - * - * @return the query filter - */ - public String getFilter() - { - Set terms = new HashSet(); - - if ( getUsername() != null ) - { - terms.add( "this.username.toLowerCase().indexOf(usernameKey.toLowerCase()) > -1" ); - } - if ( getFullName() != null ) - { - terms.add( "this.fullName.toLowerCase().indexOf(fullNameKey.toLowerCase()) > -1" ); - } - if ( getEmail() != null ) - { - terms.add( "this.email.toLowerCase().indexOf(emailKey.toLowerCase()) > -1" ); - } - - return StringUtils.join( terms.iterator(), " && " ); - } - - /** - * Return an array of parameters for user in {@link javax.jdo.Query#executeWithArray(Object[])} - * - * @return the parameter array - */ - public String[] getSearchKeys() - { - List keys = new ArrayList(); - - if ( getUsername() != null ) - { - keys.add( getUsername() ); - } - if ( getFullName() != null ) - { - keys.add( getFullName() ); - } - if ( getEmail() != null ) - { - keys.add( getEmail() ); - } - - return keys.toArray( new String[keys.size()] ); - } - - /** - * Returns the parameters for use in {@link javax.jdo.Query#declareParameters(String)} - * - * @return the parameter list - */ - public String getParameters() - { - - List params = new ArrayList(); - - if ( getUsername() != null ) - { - params.add( "String usernameKey" ); - } - if ( getFullName() != null ) - { - params.add( "String fullNameKey" ); - } - if ( getEmail() != null ) - { - params.add( "String emailKey" ); - } - - return StringUtils.join( params.iterator(), ", " ); - } -} diff --git a/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/Messages.java b/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/Messages.java deleted file mode 100644 index d0675484..00000000 --- a/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/Messages.java +++ /dev/null @@ -1,94 +0,0 @@ -package org.apache.archiva.redback.users.jdo; - -/* - * 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 java.text.MessageFormat; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -/** - * Localized Message Handling. - * - * @author Joakim Erdfelt - * - */ -public class Messages -{ - private static final String BUNDLE_NAME = "org.apache.archiva.redback.users.jdo"; //$NON-NLS-1$ - - private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( BUNDLE_NAME ); - - /** - * Get a Message as-is from the Resource Bundle. - * - * @param key the key for the message to get. - * @return the value of the key, or "!key!" if the key is not found. - */ - public static String getString( String key ) - { - try - { - return RESOURCE_BUNDLE.getString( key ); - } - catch ( MissingResourceException e ) - { - return '!' + key + '!'; - } - } - - /** - * Gets a Message from the Resource Bundle, with {1} and {2} style arguments. - * - * @param key the key for the message to get. - * @param arg the argument to pass in. - * @return the value of the key, or "!key!" if the key is not found. - */ - public static String getString( String key, Object arg ) - { - return getString( key, new Object[] { arg } ); - } - - /** - * Gets a Message from the Resource Bundle, with {1} and {2} style arguments. - * - * @param key the key for the message to get. - * @param args the arguments to pass in. - * @return the value of the key, or "!key!" if the key is not found. - */ - public static String getString( String key, Object args[] ) - { - try - { - String pattern = RESOURCE_BUNDLE.getString( key ); - return MessageFormat.format( pattern, args ); - } - catch ( MissingResourceException e ) - { - return '!' + key + '!'; - } - } - - /** - * Prevent Instantiation. - */ - private Messages() - { - } -} diff --git a/redback-users/redback-users-providers/redback-users-jdo/src/main/mdo/user.mdo b/redback-users/redback-users-providers/redback-users-jdo/src/main/mdo/user.mdo deleted file mode 100644 index b7ca9bb5..00000000 --- a/redback-users/redback-users-providers/redback-users-jdo/src/main/mdo/user.mdo +++ /dev/null @@ -1,162 +0,0 @@ - - - - - redback-users-jdo - UsersManagement - 1.0.1 - Archiva Redback Users object model. - - - package - org.apache.archiva.redback.users.jdo - - - - - - UserDatabase - 1.0.1+ - - - users - 1.0.1+ - - JdoUser - * - - - - - - JdoUser - 1.0.0+ - - org.apache.archiva.redback.users.User - - - - - username - 1.0.0+ - String - true - - - password - 1.0.0+ - String - true - - - encodedPassword - 1.0.0+ - String - true - - - fullName - 1.0.0+ - String - true - - - email - 1.0.0+ - String - true - - - lastPasswordChange - 1.0.0+ - Date - - - lastLoginDate - 1.0.0+ - Date - - - countFailedLoginAttempts - 1.0.0+ - int - - - locked - 1.0.0+ - boolean - false - true - - - permanent - 1.0.0+ - boolean - false - true - - - validated - 1.0.0+ - boolean - false - true - - - passwordChangeRequired - 1.0.0+ - boolean - false - true - - - previousEncodedPasswords - 1.0.0+ - - String - * - - - - accountCreationDate - 1.0.0+ - Date - - - - - 1.0.0+ - (); - } - public String getUserManagerId() - { - return "jdo"; - } - - ]]> - - - - - diff --git a/redback-users/redback-users-providers/redback-users-jdo/src/main/resources/META-INF/spring-context.xml b/redback-users/redback-users-providers/redback-users-jdo/src/main/resources/META-INF/spring-context.xml deleted file mode 100644 index 522f90b4..00000000 --- a/redback-users/redback-users-providers/redback-users-jdo/src/main/resources/META-INF/spring-context.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/redback-users/redback-users-providers/redback-users-jdo/src/main/resources/org/apache/archiva/redback/users/jdo/messages.properties b/redback-users/redback-users-providers/redback-users-jdo/src/main/resources/org/apache/archiva/redback/users/jdo/messages.properties deleted file mode 100644 index a05e4005..00000000 --- a/redback-users/redback-users-providers/redback-users-jdo/src/main/resources/org/apache/archiva/redback/users/jdo/messages.properties +++ /dev/null @@ -1,18 +0,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. -user.manager.cannot.add.user.without.username=User.username must be supplied on an .addUser() request. -user.manager.cannot.add.user.without.password=User.password must be supplied on an .addUser() request. diff --git a/redback-users/redback-users-providers/redback-users-jdo/src/test/java/org/apache/archiva/redback/users/jdo/JdoUserManagerTest.java b/redback-users/redback-users-providers/redback-users-jdo/src/test/java/org/apache/archiva/redback/users/jdo/JdoUserManagerTest.java deleted file mode 100644 index 38167e3b..00000000 --- a/redback-users/redback-users-providers/redback-users-jdo/src/test/java/org/apache/archiva/redback/users/jdo/JdoUserManagerTest.java +++ /dev/null @@ -1,117 +0,0 @@ -package org.apache.archiva.redback.users.jdo; - -/* - * 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.components.jdo.DefaultConfigurableJdoFactory; -import org.apache.archiva.redback.common.jdo.test.StoreManagerDebug; -import org.apache.archiva.redback.users.UserManagerException; -import org.apache.archiva.redback.users.provider.test.AbstractUserManagerTestCase; -import org.jpox.AbstractPersistenceManagerFactory; -import org.jpox.SchemaTool; -import org.junit.Before; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.jdo.PersistenceManager; -import javax.jdo.PersistenceManagerFactory; -import java.net.URL; -import java.util.Map; -import java.util.Properties; - -/** - * JdoUserManagerTest - * - * @author Joakim Erdfelt - */ -public class JdoUserManagerTest - extends AbstractUserManagerTestCase -{ - @Inject - @Named(value = "jdoFactory#users") - DefaultConfigurableJdoFactory jdoFactory; - - @Inject - @Named(value = "userManager#jdo") - JdoUserManager jdoUserManager; - - private StoreManagerDebug storeManager; - - @Before - public void setUp() - throws Exception - { - super.setUp(); - - jdoFactory.setPersistenceManagerFactoryClass( "org.jpox.PersistenceManagerFactoryImpl" ); //$NON-NLS-1$ - - jdoFactory.setDriverName( "org.hsqldb.jdbcDriver" ); //$NON-NLS-1$ - - jdoFactory.setUrl( "jdbc:hsqldb:mem:" + getName() ); //$NON-NLS-1$ - - jdoFactory.setUserName( "sa" ); //$NON-NLS-1$ - - jdoFactory.setPassword( "" ); //$NON-NLS-1$ - - jdoFactory.setProperty( "org.jpox.transactionIsolation", "READ_COMMITTED" ); //$NON-NLS-1$ //$NON-NLS-2$ - - jdoFactory.setProperty( "org.jpox.poid.transactionIsolation", "READ_COMMITTED" ); //$NON-NLS-1$ //$NON-NLS-2$ - - jdoFactory.setProperty( "org.jpox.autoCreateSchema", "true" ); //$NON-NLS-1$ //$NON-NLS-2$ - - Properties properties = jdoFactory.getProperties(); - - for ( Map.Entry entry : properties.entrySet() ) - { - System.setProperty( (String) entry.getKey(), (String) entry.getValue() ); - } - - PersistenceManagerFactory pmf = jdoFactory.getPersistenceManagerFactory(); - - assertNotNull( pmf ); - - /* set our own Store Manager to allow counting SQL statements */ - StoreManagerDebug.setup( (AbstractPersistenceManagerFactory) pmf ); - - SchemaTool.createSchemaTables( - new URL[]{ getClass().getResource( "/org/apache/archiva/redback/users/jdo/package.jdo" ) }, new URL[]{ }, - null, false, null ); //$NON-NLS-1$ - - PersistenceManager pm = pmf.getPersistenceManager(); - - pm.close(); - - setUserManager( jdoUserManager ); - - /* save the store manager to access the queries executed */ - JdoUserManager userManager = (JdoUserManager) getUserManager(); - storeManager = StoreManagerDebug.getConfiguredStoreManager( userManager.getPersistenceManager() ); - - } - - protected void assertCleanUserManager() - throws UserManagerException - { - // database cleanup - ( (JdoUserManager) getUserManager() ).eraseDatabase(); - super.assertCleanUserManager(); - } - - -} diff --git a/redback-users/redback-users-providers/redback-users-jdo/src/test/resources/spring-context.xml b/redback-users/redback-users-providers/redback-users-jdo/src/test/resources/spring-context.xml deleted file mode 100644 index 23b30f81..00000000 --- a/redback-users/redback-users-providers/redback-users-jdo/src/test/resources/spring-context.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - ]]> - - - - - - - \ No newline at end of file diff --git a/redback-users/redback-users-providers/redback-users-jdo/src/test/resources/test.properties b/redback-users/redback-users-providers/redback-users-jdo/src/test/resources/test.properties deleted file mode 100644 index aeb122f2..00000000 --- a/redback-users/redback-users-providers/redback-users-jdo/src/test/resources/test.properties +++ /dev/null @@ -1,17 +0,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. -jdbc.driver.name=org.hsqldb.jdbcDriver \ No newline at end of file From 90d8515ff48a18c8230ed5bb4054a472bff8503f Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Sun, 1 Jan 2017 09:33:48 +0100 Subject: [PATCH 29/30] add used dependency spring-aop Signed-off-by: olivier lamy --- pom.xml | 5 +++++ .../redback-users-providers/redback-users-cached/pom.xml | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 91954b64..5206e831 100644 --- a/pom.xml +++ b/pom.xml @@ -455,6 +455,11 @@ spring-core ${springVersion} + + org.springframework + spring-aop + ${springVersion} + org.springframework spring-web diff --git a/redback-users/redback-users-providers/redback-users-cached/pom.xml b/redback-users/redback-users-providers/redback-users-cached/pom.xml index 52d28862..d934f6bd 100644 --- a/redback-users/redback-users-providers/redback-users-cached/pom.xml +++ b/redback-users/redback-users-providers/redback-users-cached/pom.xml @@ -51,7 +51,11 @@ org.springframework spring-context-support - + + + org.springframework + spring-aop + javax.annotation jsr250-api From d45870b37733d72b2b0a307d0a7c5aa9fba6caca Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Sun, 1 Jan 2017 09:43:41 +0100 Subject: [PATCH 30/30] bump spring version to 4.3.5 Signed-off-by: olivier lamy --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5206e831..c784aa5f 100644 --- a/pom.xml +++ b/pom.xml @@ -71,7 +71,7 @@ - 4.2.1.RELEASE + 4.3.5.RELEASE 1.7.12 2.7