JPA mapping updates
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Tue, 11 May 2010 09:44:27 +0000 (09:44 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Tue, 11 May 2010 09:44:27 +0000 (09:44 +0000)
security/impl/src/main/java/org/wamblee/security/AbstractPersistent.java
security/impl/src/main/java/org/wamblee/security/authentication/Group.java
security/impl/src/main/java/org/wamblee/security/authentication/User.java
security/impl/src/main/java/org/wamblee/security/authorization/AbstractAuthorizationRule.java
security/impl/src/main/java/org/wamblee/security/authorization/AbstractAuthorizationService.java
security/impl/src/main/java/org/wamblee/security/authorization/AbstractOperationCondition.java
security/impl/src/main/java/org/wamblee/security/authorization/AbstractPathCondition.java
security/impl/src/main/java/org/wamblee/security/authorization/AbstractUserCondition.java
security/impl/src/main/java/org/wamblee/security/authorization/DefaultAuthorizationService.java
security/jpatest/src/test/java/org/wamblee/security/authentication/jpa/UserAdministrationTester.java
security/jpatest/src/test/java/org/wamblee/security/authorization/jpa/JpaAuthorizationServiceTest.java

index cd2837dd389187902af5345f40284aaad1a28cec..ced29a3f4c11d670816100971185f1d1ffb5df2c 100644 (file)
@@ -26,12 +26,12 @@ import org.wamblee.persistence.Persistent;
  */
 public abstract class AbstractPersistent implements Persistent {
    
-    private Serializable primaryKey;
+    private Serializable id;
 
     private Number version;
 
     protected AbstractPersistent() {
-        primaryKey = null;
+        id = null;
         version = -1;
     }
 
@@ -42,7 +42,7 @@ public abstract class AbstractPersistent implements Persistent {
      *            Object to copy.
      */
     protected AbstractPersistent(AbstractPersistent aPersistent) {
-        primaryKey = aPersistent.primaryKey;
+        id = aPersistent.id;
         version = aPersistent.version;
     }
 
@@ -53,7 +53,7 @@ public abstract class AbstractPersistent implements Persistent {
      */
     @Override
     public Serializable getPrimaryKey() {
-        return primaryKey;
+        return id;
     }
 
     /*
@@ -64,7 +64,7 @@ public abstract class AbstractPersistent implements Persistent {
      */
     @Override
     public void setPrimaryKey(Serializable aKey) {
-        primaryKey = aKey;
+        id = aKey;
     }
 
     /*
index ca77582fcd8cefc96f3430d263b8719a30ac44c5..1cac00f80ef3a60aba61869f75a73ce2a4c0354c 100644 (file)
@@ -48,7 +48,7 @@ public class Group implements Serializable, Comparable {
 
     @Id
     @GeneratedValue(strategy = GenerationType.AUTO)
-    private Long primaryKey;
+    private Long id;
 
     @Version
     private int version;
@@ -74,7 +74,7 @@ public class Group implements Serializable, Comparable {
      * 
      */
     public Group(Group aGroup) {
-        primaryKey = aGroup.primaryKey;
+        id = aGroup.id;
         version = aGroup.version;
         name = aGroup.name;
     }
@@ -143,11 +143,11 @@ public class Group implements Serializable, Comparable {
     }
 
     public Long getPrimaryKey() {
-        return primaryKey;
+        return id;
     }
 
     public void setPrimaryKey(Long aKey) {
-        primaryKey = aKey;
+        id = aKey;
     }
 
     /*
index 82a77303f6432b0dbedef95bfc6dbbd8fcfa0bc2..5e6666b7be9027520440e390c8fd6d4c9ab5d90d 100644 (file)
@@ -20,11 +20,14 @@ import java.util.Set;
 import java.util.TreeSet;
 
 import javax.persistence.CascadeType;
+import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.FetchType;
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
 import javax.persistence.ManyToMany;
 import javax.persistence.NamedQueries;
 import javax.persistence.NamedQuery;
@@ -58,7 +61,7 @@ public class User implements Serializable, Comparable {
 
     @Id
     @GeneratedValue(strategy = GenerationType.AUTO)
-    private Long primaryKey;
+    private Long id;
 
     @Version
     private int version;
@@ -77,6 +80,7 @@ public class User implements Serializable, Comparable {
      * Groups the user belongs to.
      */
     @ManyToMany(cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
+    @JoinTable(name = "SEC_USER_GROUP", joinColumns = { @JoinColumn(name = "USER_ID") }, inverseJoinColumns = { @JoinColumn(name = "GROUP_ID") })
     private Set<Group> groups;
 
     /**
@@ -115,7 +119,7 @@ public class User implements Serializable, Comparable {
      * 
      */
     public User(User aUser) {
-        primaryKey = aUser.primaryKey;
+        id = aUser.id;
         version = aUser.version;
         name = aUser.name;
         password = aUser.password;
@@ -393,6 +397,6 @@ public class User implements Serializable, Comparable {
     }
 
     public Long getPrimaryKey() {
-        return primaryKey;
+        return id;
     }
 }
index ebd52882749fffc1e95f225ea70f629af5e7715d..14ce434089b18163472428540101e8484b15c385 100644 (file)
@@ -43,7 +43,7 @@ public abstract class AbstractAuthorizationRule implements AuthorizationRule {
     
     @Id
     @GeneratedValue(strategy = GenerationType.AUTO)
-    private Long primaryKey;
+    private Long id;
 
     @Version
     private int version;
@@ -53,7 +53,7 @@ public abstract class AbstractAuthorizationRule implements AuthorizationRule {
     }
     
     public AbstractAuthorizationRule(AbstractAuthorizationRule aRule) { 
-        primaryKey = aRule.primaryKey;
+        id = aRule.id;
         version = aRule.version;
     }
 }
index e653455182677ec99d11e709003544a0338c3e61..6cdb4ca24f162f1375294f48b215486654bae97f 100644 (file)
@@ -50,7 +50,7 @@ public abstract class AbstractAuthorizationService implements AuthorizationServi
     
     @Id
     @GeneratedValue(strategy = GenerationType.AUTO)
-    private Long primaryKey;
+    private Long id;
 
     @Version
     private int version;
@@ -69,7 +69,7 @@ public abstract class AbstractAuthorizationService implements AuthorizationServi
     }
     
     public AbstractAuthorizationService(AbstractAuthorizationService aSvc) { 
-        primaryKey = aSvc.primaryKey;
+        id = aSvc.id;
         version = aSvc.version;
         name = aSvc.name;
     }
index 69048ebdab99f7f960a6411145d9649b2ec11184..f933309204bf243d51819d3bcabefb47f28a9dc0 100644 (file)
@@ -38,7 +38,7 @@ public abstract class AbstractOperationCondition implements OperationCondition {
     
     @Id
     @GeneratedValue(strategy = GenerationType.AUTO)
-    private Long primaryKey;
+    private Long id;
 
     @Version
     private int version;
@@ -48,7 +48,7 @@ public abstract class AbstractOperationCondition implements OperationCondition {
     }
     
     public AbstractOperationCondition(AbstractOperationCondition aCondition) { 
-        primaryKey = aCondition.primaryKey;
+        id = aCondition.id;
         version = aCondition.version;
     }
 }
index 6ec480174d61bb5f8e9e149cc7c8c4156b916ee2..f131dea31a9d799497747a31e5c083c6fb4b18c1 100644 (file)
@@ -38,7 +38,7 @@ public abstract class AbstractPathCondition implements PathCondition {
     
     @Id
     @GeneratedValue(strategy = GenerationType.AUTO)
-    private Long primaryKey;
+    private Long id;
 
     @Version
     private int version;
@@ -48,7 +48,7 @@ public abstract class AbstractPathCondition implements PathCondition {
     }
     
     public AbstractPathCondition(AbstractPathCondition aCondition) { 
-        primaryKey = aCondition.primaryKey;
+        id = aCondition.id;
         version = aCondition.version;
     }
 }
index e6bb53fce2d170e2e2ba828934db198de8f44d16..96952075c69370a3214e47ed6093a107b32bb55b 100644 (file)
@@ -40,7 +40,7 @@ public abstract class AbstractUserCondition implements UserCondition {
     
     @Id
     @GeneratedValue(strategy = GenerationType.AUTO)
-    private Long primaryKey;
+    private Long id;
 
     @Version
     private int version;
@@ -50,7 +50,7 @@ public abstract class AbstractUserCondition implements UserCondition {
     }
     
     public AbstractUserCondition(AbstractUserCondition aCondition) { 
-        primaryKey = aCondition.primaryKey;
+        id = aCondition.id;
         version = aCondition.version;
     }
 }
index 8e449b9e9e4ce1a46e4943b9845cbfc77b1c5345..a142712e395b999198fcd89d08ec065b2c64c221 100644 (file)
@@ -21,12 +21,12 @@ import java.util.List;
 import javax.persistence.CascadeType;
 import javax.persistence.DiscriminatorValue;
 import javax.persistence.Entity;
-import javax.persistence.ManyToMany;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
 import javax.persistence.OneToMany;
 import javax.persistence.OrderColumn;
 import javax.persistence.Transient;
 
-import org.wamblee.security.authentication.User;
 import org.wamblee.security.authentication.UserAccessor;
 import org.wamblee.security.authentication.UserAdministration;
 
@@ -48,6 +48,7 @@ public class DefaultAuthorizationService extends AbstractAuthorizationService {
      * List of ordered authorization rules.
      */
     @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, targetEntity = AbstractAuthorizationRule.class)
+    @JoinTable(name = "SEC_AUTH_SVC_RULE", joinColumns = { @JoinColumn(name = "SVC_ID") }, inverseJoinColumns = { @JoinColumn(name = "RULE_ID") })
     @OrderColumn(name = "RULE_INDEX")
     private List<AuthorizationRule> rules;
 
@@ -75,7 +76,7 @@ public class DefaultAuthorizationService extends AbstractAuthorizationService {
         super(aName);
         rules = new ArrayList<AuthorizationRule>();
         userAccessor = aAccessor;
-        userAdmin = aUserAdmin; 
+        userAdmin = aUserAdmin;
     }
 
     /**
@@ -84,19 +85,18 @@ public class DefaultAuthorizationService extends AbstractAuthorizationService {
     public DefaultAuthorizationService() {
         rules = new ArrayList<AuthorizationRule>();
         userAccessor = null;
-        userAdmin = null; 
+        userAdmin = null;
     }
 
-   
     @Override
     public void setUserAccessor(UserAccessor aUserAccessor) {
         userAccessor = aUserAccessor;
     }
-    
+
     @Override
     public void setUserAdministration(UserAdministration aUserAdmin) {
         userAdmin = aUserAdmin;
-        for (AuthorizationRule rule: rules) { 
+        for (AuthorizationRule rule : rules) {
             rule.setUserAdministration(userAdmin);
         }
     }
@@ -198,7 +198,7 @@ public class DefaultAuthorizationService extends AbstractAuthorizationService {
      */
     protected void setMappedRules(List<AuthorizationRule> aRules) {
         rules = aRules;
-        for (AuthorizationRule rule: rules) { 
+        for (AuthorizationRule rule : rules) {
             rule.setUserAdministration(userAdmin);
         }
     }
index 366ec6a981e134165eb0afada69a829c6ca65e90..634e10ed5ddd39f09329a9e619c450b136a7c088 100644 (file)
@@ -28,6 +28,7 @@ import org.wamblee.security.authentication.UserSet;
 import org.wamblee.security.encryption.Md5HexMessageDigester;
 import org.wamblee.security.encryption.MessageDigester;
 import org.wamblee.support.persistence.JpaTester;
+import org.wamblee.support.persistence.PersistenceUnitDescription;
 import org.wamblee.support.persistence.TransactionProxyFactory;
 
 /**
@@ -38,12 +39,14 @@ import org.wamblee.support.persistence.TransactionProxyFactory;
  */
 public class UserAdministrationTester {
 
+    private PersistenceUnitDescription persistenceUnit; 
     private JpaTester jpaTester;
     private Cache<String, User> userCache;
     private UserAdministration userAdmin; 
 
     public UserAdministrationTester() {
-        jpaTester = new JpaTester(new SecurityPersistenceUnit());
+        persistenceUnit = new SecurityPersistenceUnit(); 
+        jpaTester = new JpaTester(persistenceUnit);
     }
 
     public void start() throws Exception {
@@ -72,6 +75,9 @@ public class UserAdministrationTester {
         userAdmin = factory.getProxy(userAdminImpl);
     }
    
+    public PersistenceUnitDescription getPersistenceUnit() {
+        return persistenceUnit;
+    }
     
     public JpaTester getJpaTester() {
         return jpaTester;
index afb0d405f23f91b5331928e1611db000e8f17866..d2053c2c5f42f1ee0f88cda40fd8d1dd4f719ba3 100644 (file)
@@ -43,7 +43,7 @@ public class JpaAuthorizationServiceTest extends AuthorizationServiceTest {
 
     private static final String RULES_TABLE = "SEC_AUTH_RULE";
 
-    private static final String SERVICE_RULES_TABLE = "SEC_AUTH_SVC_SEC_AUTH_RULE";
+    private static final String SERVICE_RULES_TABLE = "SEC_AUTH_SVC_RULE";
 
     private static final String OPERATIONCOND_TABLE = "SEC_OPERATION_CONDITION";