http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0537b856/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/java/org/apache/archiva/redback/rbac/jdo/JdoTool.java ---------------------------------------------------------------------- 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 2d4233e..0000000 --- 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 <a href="mailto:[email protected]">Joakim Erdfelt</a> - * - */ -@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<Role> roles = (List<Role>) 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>T saveObject( T object ) - { - return (T) saveObject( object, null ); - } - - public <T>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<String> 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<String> 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>T getObjectById( Class<T> 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>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; - } -}
http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0537b856/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/mdo/rbac-jdo.mdo ---------------------------------------------------------------------- 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 ebd9ecc..0000000 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/mdo/rbac-jdo.mdo +++ /dev/null @@ -1,337 +0,0 @@ -<?xml version="1.0"?> - -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one - ~ or more contributor license agreements. See the NOTICE file - ~ distributed with this work for additional information - ~ regarding copyright ownership. The ASF licenses this file - ~ to you under the Apache License, Version 2.0 (the - ~ "License"); you may not use this file except in compliance - ~ with the License. You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, - ~ software distributed under the License is distributed on an - ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - ~ KIND, either express or implied. See the License for the - ~ specific language governing permissions and limitations - ~ under the License. - --> -<model jpox.mapping-in-package="true" - jpox.table-prefix="SECURITY_"> - <!-- TODO: there is no reason this model is JDO specific. Shouldn't it be the basis for the various providers? It would dramatically reduce the code in -memory, for example --> - <id>rbac-jdo</id> - <name>RbacJdoModel</name> - <version>1.0.1</version> - <defaults> - <default> - <key>package</key> - <value>org.apache.archiva.redback.rbac.jdo</value> - </default> - </defaults> - <classes> - <class rootElement="true" - jpox.stashable="false"> - <name>RbacDatabase</name> - <version>1.0.1+</version> - <fields> - <field jpox.column="RBAC_ROLES"> - <name>roles</name> - <version>1.0.1+</version> - <association> - <type>JdoRole</type> - <multiplicity>*</multiplicity> - </association> - </field> - <field> - <name>permissions</name> - <version>1.0.1+</version> - <association> - <type>JdoPermission</type> - <multiplicity>*</multiplicity> - </association> - </field> - <field> - <name>operations</name> - <version>1.0.1+</version> - <association> - <type>JdoOperation</type> - <multiplicity>*</multiplicity> - </association> - </field> - <field> - <name>resources</name> - <version>1.0.1+</version> - <association> - <type>JdoResource</type> - <multiplicity>*</multiplicity> - </association> - </field> - <field> - <name>userAssignments</name> - <version>1.0.1+</version> - <association> - <type>JdoUserAssignment</type> - <multiplicity>*</multiplicity> - </association> - </field> - </fields> - </class> - - <class jpox.stashable="true" - jpox.table="ROLES"> - <name>JdoRole</name> - <version>1.0.0+</version> - <interfaces> - <interface>org.apache.archiva.redback.rbac.Role</interface> - </interfaces> - <superClass>org.apache.archiva.redback.rbac.AbstractRole</superClass> - <fields> - <field jpox.primary-key="true" jpox.value-strategy="off"> - <name>name</name> - <version>1.0.0+</version> - <type>String</type> - <identifier>true</identifier> - </field> - <field> - <name>description</name> - <version>1.0.0+</version> - <type>String</type> - </field> - <field> - <name>assignable</name> - <version>1.0.0+</version> - <type>boolean</type> - <description> - true if this role is available to be assigned to a user - </description> - </field> - <field> - <name>permanent</name> - <version>1.0.0+</version> - <type>boolean</type> - <description> - true if this object is permanent. - </description> - </field> - <field jpox.persistence-modifier="persistent" - jpox.fetch-groups="role-child-detail" - jpox.join-table="ROLE_CHILDROLE_MAP"> - <name>childRoleNames</name> - <version>1.0.0+</version> - <association stash.part="true" - jpox.join="true" - java.init="field" - jpox.dependent="false" - java.generate-break="false" - java.generate-create="false" - zjava.use-interface="org.apache.archiva.redback.rbac.Role"> - <type>String</type> - <multiplicity>*</multiplicity> - </association> - <description> - roles that will inherit the permissions of this role - </description> - </field> - <field jpox.fetch-groups="role-child-detail" - jpox.join-table="ROLE_PERMISSION_MAP"> - <name>permissions</name> - <version>1.0.0+</version> - <association stash.part="true" - xml.reference="true" - jpox.join="true" - jpox.dependent="false" - java.init="field" - java.generate-break="false" - java.generate-create="false" - java.use-interface="org.apache.archiva.redback.rbac.Permission"> - <type>JdoPermission</type> - <multiplicity>*</multiplicity> - </association> - </field> - </fields> - </class> - - <class jpox.stashable="true" - jpox.table="PERMISSIONS"> - <name>JdoPermission</name> - <version>1.0.0+</version> - <interfaces> - <interface>org.apache.archiva.redback.rbac.Permission</interface> - </interfaces> - <fields> - <field jpox.primary-key="true" jpox.value-strategy="off"> - <name>name</name> - <version>1.0.0+</version> - <type>String</type> - <identifier>true</identifier> - </field> - <field> - <name>description</name> - <version>1.0.0+</version> - <type>String</type> - </field> - <field> - <name>permanent</name> - <version>1.0.0+</version> - <type>boolean</type> - <description> - true if this object is permanent. - </description> - </field> - <field jpox.indexed="true" - jpox.persistence-modifier="persistent" - jpox.column="RBAC_OPERATION"> - <name>operation</name> - <version>1.0.0+</version> - <association stash.part="true" - xml.reference="true" - java.use-interface="org.apache.archiva.redback.rbac.Operation" - jpox.dependent="false"> - <type>JdoOperation</type> - <multiplicity>1</multiplicity> - </association> - </field> - <field jpox.indexed="true" - jpox.persistence-modifier="persistent" - jpox.column="RBAC_RESOURCE"> - <name>resource</name> - <version>1.0.0+</version> - <association stash.part="true" - xml.reference="true" - java.use-interface="org.apache.archiva.redback.rbac.Resource" - jpox.dependent="false"> - <type>JdoResource</type> - <multiplicity>1</multiplicity> - </association> - </field> - </fields> - </class> - - <class jpox.stashable="true" - jpox.table="OPERATIONS"> - <name>JdoOperation</name> - <version>1.0.0+</version> - <interfaces> - <interface>org.apache.archiva.redback.rbac.Operation</interface> - </interfaces> - <fields> - <field jpox.primary-key="true" jpox.value-strategy="off"> - <name>name</name> - <version>1.0.0+</version> - <type>String</type> - <identifier>true</identifier> - </field> - <field> - <name>description</name> - <version>1.0.0+</version> - <type>String</type> - </field> - <field> - <name>permanent</name> - <version>1.0.0+</version> - <type>boolean</type> - <description> - true if this object is permanent. - </description> - </field> - <field> - <name>resourceRequired</name> - <version>1.0.0+</version> - <type>boolean</type> - <description> - true if the resource is required for authorization to be granted - </description> - </field> - </fields> - </class> - - <class jpox.stashable="true" - jpox.table="RESOURCES"> - <name>JdoResource</name> - <version>1.0.0+</version> - <description> - In RBAC terms, this is the entity which an operation is associated with that which permissions are based on. - </description> - <interfaces> - <interface>org.apache.archiva.redback.rbac.Resource</interface> - </interfaces> - <fields> - <field jpox.primary-key="true" jpox.value-strategy="off"> - <name>identifier</name> - <version>1.0.0+</version> - <type>String</type> - <description> - The string identifier for a resource. - </description> - <identifier>true</identifier> - </field> - <field> - <name>pattern</name> - <version>1.0.0+</version> - <type>boolean</type> - <description> - 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 - </description> - </field> - <field> - <name>permanent</name> - <version>1.0.0+</version> - <type>boolean</type> - <description> - true if this object is permanent. - </description> - </field> - </fields> - </class> - - <class jpox.stashable="true" - jpox.table="USER_ASSIGNMENTS"> - <name>JdoUserAssignment</name> - <description>binding of a principal to a role</description> - <version>1.0.0+</version> - <interfaces> - <interface>org.apache.archiva.redback.rbac.UserAssignment</interface> - </interfaces> - <superClass>org.apache.archiva.redback.rbac.AbstractUserAssignment</superClass> - <fields> - <field jpox.primary-key="true" jpox.value-strategy="off"> - <name>principal</name> - <version>1.0.0+</version> - <type>String</type> - <identifier>true</identifier> - </field> - <field jpox.column="LAST_UPDATED" xml.format="long"> - <name>timestamp</name> - <version>1.0.0+</version> - <type>Date</type> - </field> - <field> - <name>permanent</name> - <version>1.0.0+</version> - <type>boolean</type> - <description> - true if this object is permanent. - </description> - </field> - <field java.adder="false" - jpox.persistence-modifier="persistent" - jpox.indexed="false" - jpox.join-table="USERASSIGNMENT_ROLENAMES"> - <name>roleNames</name> - <version>1.0.0+</version> - <association stash.part="true" - jpox.join="true" - java.init="field" - java.generate-break="false" - java.generate-create="false"> - <type>String</type> - <multiplicity>*</multiplicity> - </association> - </field> - </fields> - </class> - </classes> -</model> http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0537b856/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/resources/META-INF/spring-context.xml ---------------------------------------------------------------------- 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 2a3dec1..0000000 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/main/resources/META-INF/spring-context.xml +++ /dev/null @@ -1,34 +0,0 @@ -<?xml version="1.0"?> - -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one - ~ or more contributor license agreements. See the NOTICE file - ~ distributed with this work for additional information - ~ regarding copyright ownership. The ASF licenses this file - ~ to you under the Apache License, Version 2.0 (the - ~ "License"); you may not use this file except in compliance - ~ with the License. You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, - ~ software distributed under the License is distributed on an - ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - ~ KIND, either express or implied. See the License for the - ~ specific language governing permissions and limitations - ~ under the License. - --> -<beans xmlns="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://www.springframework.org/schema/beans - http://www.springframework.org/schema/beans/spring-beans-3.0.xsd" - default-lazy-init="true"> - - <bean name="rbacManager#jdo" class="org.apache.archiva.redback.rbac.jdo.JdoRbacManager" init-method="initialize"> - <property name="jdo" ref="jdoTool"/> - </bean> - - <bean id="jdoTool" class="org.apache.archiva.redback.rbac.jdo.JdoTool" init-method="initialize" lazy-init="true"> - <property name="jdoFactory" ref="jdoFactory#users"/> - </bean> -</beans> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0537b856/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/java/org/apache/archiva/redback/rbac/jdo/JdoRbacManagerTest.java ---------------------------------------------------------------------- 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 0572706..0000000 --- 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 <a href="mailto:[email protected]">Joakim Erdfelt</a> - */ -@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<Object, Object> 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 ); - } - - -} http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0537b856/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/java/org/apache/archiva/redback/rbac/jdo/RbacJdoModelStaxTest.java ---------------------------------------------------------------------- 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 cde20d6..0000000 --- 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<JdoRole> expectedRoles = database.getRoles(); - List<JdoRole> 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<JdoUserAssignment> expectedUserAssignments = database.getUserAssignments(); - List<JdoUserAssignment> 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<Permission> expectedPermissions, List<Permission> 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() ); - } -} http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0537b856/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/resources/ehcache.xml ---------------------------------------------------------------------- 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 34e6626..0000000 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/resources/ehcache.xml +++ /dev/null @@ -1,90 +0,0 @@ -<?xml version="1.0"?> - -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one - ~ or more contributor license agreements. See the NOTICE file - ~ distributed with this work for additional information - ~ regarding copyright ownership. The ASF licenses this file - ~ to you under the Apache License, Version 2.0 (the - ~ "License"); you may not use this file except in compliance - ~ with the License. You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, - ~ software distributed under the License is distributed on an - ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - ~ KIND, either express or implied. See the License for the - ~ specific language governing permissions and limitations - ~ under the License. - --> -<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"> - <diskStore path="java.io.tmpdir" /> - - <!-- - Redback EHCACHE config file that can be used with JPOX-Ehcache integration - - For reference http://ehcache.sourceforge.net/documentation/configuration.html - --> - - <!-- make default cache very short lived --> - <defaultCache - maxElementsInMemory="100" - maxElementsOnDisk="0" - eternal="false" - overflowToDisk="false" - timeToIdleSeconds="300" - timeToLiveSeconds="600" - memoryStoreEvictionPolicy="LFU" /> - - <!-- - cache Redback classes longer to avoid a lot of SQL queries - See REDBACK-227 - --> - <cache name="org.apache.archiva.redback.rbac.jdo.JdoOperation" - maxElementsInMemory="10000" - maxElementsOnDisk="0" - eternal="false" - overflowToDisk="false" - timeToIdleSeconds="3000" - timeToLiveSeconds="6000" - memoryStoreEvictionPolicy="LFU" /> - - <cache name="org.apache.archiva.redback.rbac.jdo.JdoPermission" - maxElementsInMemory="10000" - maxElementsOnDisk="0" - eternal="false" - overflowToDisk="false" - timeToIdleSeconds="3000" - timeToLiveSeconds="6000" - memoryStoreEvictionPolicy="LFU" /> - - <cache name="org.apache.archiva.redback.rbac.jdo.JdoResource" - maxElementsInMemory="10000" - maxElementsOnDisk="0" - eternal="false" - overflowToDisk="false" - timeToIdleSeconds="3000" - timeToLiveSeconds="6000" - memoryStoreEvictionPolicy="LFU" /> - - <cache name="org.apache.archiva.redback.rbac.jdo.JdoRole" - maxElementsInMemory="10000" - maxElementsOnDisk="0" - eternal="false" - overflowToDisk="false" - timeToIdleSeconds="3000" - timeToLiveSeconds="6000" - memoryStoreEvictionPolicy="LFU" /> - - <cache name="org.apache.archiva.redback.rbac.jdo.JdoUserAssignment" - maxElementsInMemory="10000" - maxElementsOnDisk="0" - eternal="false" - overflowToDisk="false" - timeToIdleSeconds="3000" - timeToLiveSeconds="6000" - memoryStoreEvictionPolicy="LFU" /> - -</ehcache> http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0537b856/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/resources/spring-context.xml ---------------------------------------------------------------------- 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 34e8738..0000000 --- a/redback-rbac/redback-rbac-providers/redback-rbac-jdo/src/test/resources/spring-context.xml +++ /dev/null @@ -1,85 +0,0 @@ -<?xml version="1.0"?> - -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one - ~ or more contributor license agreements. See the NOTICE file - ~ distributed with this work for additional information - ~ regarding copyright ownership. The ASF licenses this file - ~ to you under the Apache License, Version 2.0 (the - ~ "License"); you may not use this file except in compliance - ~ with the License. You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, - ~ software distributed under the License is distributed on an - ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - ~ KIND, either express or implied. See the License for the - ~ specific language governing permissions and limitations - ~ under the License. - --> -<beans xmlns="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" - 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"> - - <bean name="jdoFactory#users" class="org.apache.archiva.redback.components.jdo.DefaultConfigurableJdoFactory"> - <property name="driverName" value="org.hsqldb.jdbcDriver"/> - <property name="url" value="jdbc:hsqldb:mem:redback-users-tests" /> - <property name="userName" value="sa"/> - <property name="password" value=""/> - <property name="persistenceManagerFactoryClass" value="org.jpox.PersistenceManagerFactoryImpl"/> - <property name="otherProperties"> - <props> - <prop key="org.jpox.rdbms.dateTimezone">JDK_DEFAULT_TIMEZONE</prop> - <prop key="org.jpox.autoCreateTables">true</prop> - <prop key="org.jpox.cache.level2">true</prop> - <prop key="org.jpox.cache.level2.type">ehcacheclassbased</prop> - <prop key="org.jpox.cache.level2.configurationFile">/ehcache.xml</prop> - <prop key="org.jpox.cache.level2.cacheName">defaultfake</prop> - </props> - </property> - </bean> - - <!-- - *** jpa init *** - Needed because of the dependency redback-user-cache -> redback-user-jpa - *** - --> - <bean name="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> - <property name="jpaVendorAdapter" > - <bean class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter" /> - </property> - <property name="persistenceXmlLocation" value="classpath:META-INF/persistence-hsqldb.xml" /> - <property name="jpaPropertyMap"> - <map> - <entry key="openjpa.ConnectionURL" value="jdbc:hsqldb:mem:redback_database" /> - <entry key="openjpa.ConnectionDriverName" value="org.hsqldb.jdbcDriver" /> - <entry key="openjpa.ConnectionUserName" value="sa" /> - <entry key="openjpa.ConnectionPassword" value="" /> - <entry key="openjpa.Log" value="DefaultLevel=TRACE, Runtime=TRACE, Tool=INFO, SQL=TRACE" /> - <entry key="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" /> - <entry key="openjpa.jdbc.MappingDefaults" - value="ForeignKeyDeleteAction=restrict,JoinForeignKeyDeleteAction=restrict"/> - </map> - </property> - - </bean> - - <bean name="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" > - <property name="entityManagerFactory" ref="entityManagerFactory" /> - </bean> - - <tx:annotation-driven /> - <!-- **** jpa init *** --> - - <bean name="userConfiguration#default" class="org.apache.archiva.redback.configuration.DefaultUserConfiguration"> - <property name="registry" ref="test-conf"/> - </bean> - - <bean name="commons-configuration" class="org.apache.archiva.redback.components.registry.commons.CommonsConfigurationRegistry"> - </bean> - - <alias name="commons-configuration" alias="test-conf"/> - -</beans> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0537b856/redback-users/redback-users-providers/redback-users-jdo/pom.xml ---------------------------------------------------------------------- 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 9b889a6..0000000 --- a/redback-users/redback-users-providers/redback-users-jdo/pom.xml +++ /dev/null @@ -1,176 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ 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. - --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.archiva.redback</groupId> - <artifactId>redback-users-providers</artifactId> - <version>2.5-SNAPSHOT</version> - </parent> - - <artifactId>redback-users-jdo</artifactId> - <packaging>jar</packaging> - <name>Redback :: Users Provider :: JDO</name> - - <dependencies> - <dependency> - <groupId>org.codehaus.plexus</groupId> - <artifactId>plexus-utils</artifactId> - </dependency> - <dependency> - <groupId>org.apache.archiva.redback</groupId> - <artifactId>redback-common-jdo</artifactId> - </dependency> - <dependency> - <groupId>org.apache.archiva.redback</groupId> - <artifactId>redback-policy</artifactId> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-context-support</artifactId> - </dependency> - <dependency> - <groupId>javax.annotation</groupId> - <artifactId>jsr250-api</artifactId> - </dependency> - <dependency> - <groupId>org.apache.archiva.redback</groupId> - <artifactId>redback-users-tests</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.hsqldb</groupId> - <artifactId>hsqldb</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>net.java.dev.stax-utils</groupId> - <artifactId>stax-utils</artifactId> - <version>20060502</version> - <exclusions> - <exclusion> - <groupId>com.bea.xml</groupId> - <artifactId>jsr173-ri</artifactId> - </exclusion> - </exclusions> - </dependency> - - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-simple</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>jul-to-slf4j</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <executions> - <execution> - <id>bundle-manifest</id> - <phase>process-classes</phase> - <goals> - <goal>manifest</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <configuration> - <archive> - <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> - </archive> - </configuration> - </plugin> - <plugin> - <groupId>org.codehaus.modello</groupId> - <artifactId>modello-maven-plugin</artifactId> - <configuration> - <version>1.0.1</version> - <packageWithVersion>false</packageWithVersion> - <models> - <model>src/main/mdo/user.mdo</model> - </models> - </configuration> - <executions> - <execution> - <id>modello-java</id> - <goals> - <goal>java</goal> - <goal>stax-reader</goal> - <goal>stax-writer</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.archiva.redback.components.modello</groupId> - <artifactId>jpox-modello-maven-plugin</artifactId> - <configuration> - <version>1.0.1</version> - <packageWithVersion>false</packageWithVersion> - <models> - <model>src/main/mdo/user.mdo</model> - </models> - </configuration> - <executions> - <execution> - <id>modello-jpox</id> - <goals> - <goal>jpox-metadata-class</goal> - </goals> - </execution> - <execution> - <id>jpox-jdo-mapping</id> - <goals> - <goal>jpox-jdo-mapping</goal> - </goals> - <configuration> - <outputDirectory>${project.build.outputDirectory}/org/apache/archiva/redback/users/jdo</outputDirectory> - </configuration> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>jpox-maven-plugin</artifactId> - <executions> - <execution> - <goals> - <goal>enhance</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> - -</project> http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0537b856/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/JdoUserManager.java ---------------------------------------------------------------------- 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 2369a16..0000000 --- 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 <a href="mailto:[email protected]">Joakim Erdfelt</a> - */ -@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<User> getUsers() - { - return getAllObjectsDetached( null ); - } - - public List<User> getUsers( boolean orderAscending ) - { - String ordering = orderAscending ? "username ascending" : "username descending"; - - return getAllObjectsDetached( ordering ); - } - - @SuppressWarnings("unchecked") - private List<User> getAllObjectsDetached( String ordering ) - { - return RedbackJdoUtils.getAllObjectsDetached( getPersistenceManager(), JdoUser.class, ordering, (String) null ); - } - - public List<User> findUsersByUsernameKey( String usernameKey, boolean orderAscending ) - { - return findUsers( "username", usernameKey, orderAscending ); - } - - public List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending ) - { - return findUsers( "fullName", fullNameKey, orderAscending ); - } - - public List<User> findUsersByEmailKey( String emailKey, boolean orderAscending ) - { - return findUsers( "email", emailKey, orderAscending ); - } - - @SuppressWarnings("unchecked") - public List<User> 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<User> result = (List<User>) query.executeWithArray( uq.getSearchKeys() ); - - result = (List<User>) pm.detachCopyAll( result ); - - tx.commit(); - - return result; - } - finally - { - rollback( tx ); - } - } - - @SuppressWarnings("unchecked") - private List<User> 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<User> result = (List<User>) query.execute( searchKey ); - - result = (List<User>) 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<User> 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"; - } -} http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0537b856/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/JdoUserQuery.java ---------------------------------------------------------------------- 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 2a06caa..0000000 --- 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<String> terms = new HashSet<String>(); - - 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<String> keys = new ArrayList<String>(); - - 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<String> params = new ArrayList<String>(); - - 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(), ", " ); - } -} http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0537b856/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/Messages.java ---------------------------------------------------------------------- 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 d067548..0000000 --- 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 <a href="mailto:[email protected]">Joakim Erdfelt</a> - * - */ -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() - { - } -} http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/0537b856/redback-users/redback-users-providers/redback-users-jdo/src/main/mdo/user.mdo ---------------------------------------------------------------------- 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 b7ca9bb..0000000 --- a/redback-users/redback-users-providers/redback-users-jdo/src/main/mdo/user.mdo +++ /dev/null @@ -1,162 +0,0 @@ -<?xml version="1.0"?> - -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one - ~ or more contributor license agreements. See the NOTICE file - ~ distributed with this work for additional information - ~ regarding copyright ownership. The ASF licenses this file - ~ to you under the Apache License, Version 2.0 (the - ~ "License"); you may not use this file except in compliance - ~ with the License. You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, - ~ software distributed under the License is distributed on an - ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - ~ KIND, either express or implied. See the License for the - ~ specific language governing permissions and limitations - ~ under the License. - --> -<model> - <id>redback-users-jdo</id> - <name>UsersManagement</name> - <version>1.0.1</version> - <description>Archiva Redback Users object model.</description> - <defaults> - <default> - <key>package</key> - <value>org.apache.archiva.redback.users.jdo</value> - </default> - </defaults> - - <classes> - <class stash.storable="false" rootElement="true"> - <name>UserDatabase</name> - <version>1.0.1+</version> - <fields> - <field> - <name>users</name> - <version>1.0.1+</version> - <association> - <type>JdoUser</type> - <multiplicity>*</multiplicity> - </association> - </field> - </fields> - </class> - <class stash.storable="true" jpox.use-identifiers-as-primary-key="false"> - <name>JdoUser</name> - <version>1.0.0+</version> - <interfaces> - <interface>org.apache.archiva.redback.users.User</interface> - </interfaces> - <description></description> - <fields> - <field jpox.primary-key="true" jpox.value-strategy="off" jpox.persistence-modifier="persistent"> - <name>username</name> - <version>1.0.0+</version> - <type>String</type> - <identifier>true</identifier> - </field> - <field jpox.column="USER_PASSWORD"> - <name>password</name> - <version>1.0.0+</version> - <type>String</type> - <identifier>true</identifier> - </field> - <field> - <name>encodedPassword</name> - <version>1.0.0+</version> - <type>String</type> - <identifier>true</identifier> - </field> - <field> - <name>fullName</name> - <version>1.0.0+</version> - <type>String</type> - <identifier>true</identifier> - </field> - <field> - <name>email</name> - <version>1.0.0+</version> - <type>String</type> - <identifier>true</identifier> - </field> - <field xml.format="long"> - <name>lastPasswordChange</name> - <version>1.0.0+</version> - <type>Date</type> - </field> - <field xml.format="long"> - <name>lastLoginDate</name> - <version>1.0.0+</version> - <type>Date</type> - </field> - <field> - <name>countFailedLoginAttempts</name> - <version>1.0.0+</version> - <type>int</type> - </field> - <field> - <name>locked</name> - <version>1.0.0+</version> - <type>boolean</type> - <defaultValue>false</defaultValue> - <identifier>true</identifier> - </field> - <field> - <name>permanent</name> - <version>1.0.0+</version> - <type>boolean</type> - <defaultValue>false</defaultValue> - <identifier>true</identifier> - </field> - <field> - <name>validated</name> - <version>1.0.0+</version> - <type>boolean</type> - <defaultValue>false</defaultValue> - <identifier>true</identifier> - </field> - <field> - <name>passwordChangeRequired</name> - <version>1.0.0+</version> - <type>boolean</type> - <defaultValue>false</defaultValue> - <identifier>true</identifier> - </field> - <field> - <name>previousEncodedPasswords</name> - <version>1.0.0+</version> - <association stash.part="true"> - <type>String</type> - <multiplicity>*</multiplicity> - </association> - </field> - <field xml.format="long"> - <name>accountCreationDate</name> - <version>1.0.0+</version> - <type>Date</type> - </field> - </fields> - <codeSegments> - <codeSegment> - <version>1.0.0+</version> - <code><![CDATA[ - public JdoUser() - { - // Intentionally initialize List to avoid JPOX NullPointerException Issues. - previousEncodedPasswords = new java.util.ArrayList<String>(); - } - public String getUserManagerId() - { - return "jdo"; - } - - ]]></code> - </codeSegment> - </codeSegments> - </class> - </classes> -</model>
