From bac5a4d56e975847a52e497bf2777c89b66aebfc Mon Sep 17 00:00:00 2001 From: Erik Brakkee Date: Fri, 30 Apr 2010 17:35:57 +0000 Subject: [PATCH] --- .../authorization/AnyUserCondition.java | 9 +++-- .../authorization/GroupUserCondition.java | 10 ++++-- .../authorization/IsaOperationCondition.java | 13 +++++-- .../authorization/OperationCondition.java | 35 ++++++++++++++++-- .../security/authorization/PathCondition.java | 35 ++++++++++++++++-- .../authorization/RegexpPathCondition.java | 8 +++-- .../StartsWithPathCondition.java | 5 +++ .../security/authorization/UserCondition.java | 36 +++++++++++++++++-- .../test/resources/META-INF/persistence.xml | 8 +++++ 9 files changed, 144 insertions(+), 15 deletions(-) diff --git a/security/impl/src/main/java/org/wamblee/security/authorization/AnyUserCondition.java b/security/impl/src/main/java/org/wamblee/security/authorization/AnyUserCondition.java index a9801cf0..137d6dbd 100644 --- a/security/impl/src/main/java/org/wamblee/security/authorization/AnyUserCondition.java +++ b/security/impl/src/main/java/org/wamblee/security/authorization/AnyUserCondition.java @@ -16,7 +16,9 @@ package org.wamblee.security.authorization; -import org.wamblee.security.AbstractPersistent; +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; + import org.wamblee.usermgt.User; /** @@ -24,8 +26,9 @@ import org.wamblee.usermgt.User; * * @author Erik Brakkee */ -public class AnyUserCondition extends AbstractPersistent implements - UserCondition { +@Entity +@DiscriminatorValue("ANYUSER") +public class AnyUserCondition extends UserCondition { /** * Constructs the condition. * diff --git a/security/impl/src/main/java/org/wamblee/security/authorization/GroupUserCondition.java b/security/impl/src/main/java/org/wamblee/security/authorization/GroupUserCondition.java index c981e00f..d4cde7f2 100644 --- a/security/impl/src/main/java/org/wamblee/security/authorization/GroupUserCondition.java +++ b/security/impl/src/main/java/org/wamblee/security/authorization/GroupUserCondition.java @@ -16,6 +16,10 @@ package org.wamblee.security.authorization; +import javax.persistence.Column; +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; + import org.wamblee.security.AbstractPersistent; import org.wamblee.usermgt.User; @@ -24,11 +28,13 @@ import org.wamblee.usermgt.User; * * @author Erik Brakkee */ -public class GroupUserCondition extends AbstractPersistent implements - UserCondition { +@Entity +@DiscriminatorValue("GROUP") +public class GroupUserCondition extends UserCondition { /** * Group the user must be in. */ + @Column(name = "GRP") private String group; /** diff --git a/security/impl/src/main/java/org/wamblee/security/authorization/IsaOperationCondition.java b/security/impl/src/main/java/org/wamblee/security/authorization/IsaOperationCondition.java index 14a8a9de..4e927437 100644 --- a/security/impl/src/main/java/org/wamblee/security/authorization/IsaOperationCondition.java +++ b/security/impl/src/main/java/org/wamblee/security/authorization/IsaOperationCondition.java @@ -15,13 +15,21 @@ */ package org.wamblee.security.authorization; +import javax.persistence.Access; +import javax.persistence.AccessType; +import javax.persistence.Column; +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; + import org.wamblee.security.AbstractPersistent; /** * Determiens if an operation is a subclass of a specified operation. */ -public class IsaOperationCondition extends AbstractPersistent implements - OperationCondition { +@Entity +@DiscriminatorValue("ISA") +@Access(AccessType.PROPERTY) +public class IsaOperationCondition extends OperationCondition { /** * Operation that the other operation must be a subclass of. */ @@ -61,6 +69,7 @@ public class IsaOperationCondition extends AbstractPersistent implements * * @return Operation string. */ + @Column(name = "CLASSNAME") protected String getOperationString() { if (operation == null) { return null; diff --git a/security/impl/src/main/java/org/wamblee/security/authorization/OperationCondition.java b/security/impl/src/main/java/org/wamblee/security/authorization/OperationCondition.java index 916ab19a..3e8f8fb4 100644 --- a/security/impl/src/main/java/org/wamblee/security/authorization/OperationCondition.java +++ b/security/impl/src/main/java/org/wamblee/security/authorization/OperationCondition.java @@ -15,6 +15,16 @@ */ package org.wamblee.security.authorization; +import javax.persistence.DiscriminatorColumn; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Table; +import javax.persistence.Version; + import org.wamblee.persistence.Persistent; /** @@ -22,7 +32,28 @@ import org.wamblee.persistence.Persistent; * * @author Erik Brakkee */ -public interface OperationCondition extends Persistent { +@Entity +@Table(name = "SEC_OPERATION_CONDITION") +@Inheritance(strategy = InheritanceType.SINGLE_TABLE) +@DiscriminatorColumn(name = "TYPE") +public abstract class OperationCondition { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long primaryKey; + + @Version + private int version; + + public OperationCondition() { + // Empty + } + + public OperationCondition(OperationCondition aCondition) { + primaryKey = aCondition.primaryKey; + version = aCondition.version; + } + /** * Determines if the operation matches. * @@ -31,5 +62,5 @@ public interface OperationCondition extends Persistent { * * @return True iff the operation matches. */ - boolean matches(Operation aOperation); + public abstract boolean matches(Operation aOperation); } diff --git a/security/impl/src/main/java/org/wamblee/security/authorization/PathCondition.java b/security/impl/src/main/java/org/wamblee/security/authorization/PathCondition.java index 4e03953f..b1c6670a 100644 --- a/security/impl/src/main/java/org/wamblee/security/authorization/PathCondition.java +++ b/security/impl/src/main/java/org/wamblee/security/authorization/PathCondition.java @@ -15,6 +15,16 @@ */ package org.wamblee.security.authorization; +import javax.persistence.DiscriminatorColumn; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Table; +import javax.persistence.Version; + import org.wamblee.persistence.Persistent; /** @@ -22,7 +32,28 @@ import org.wamblee.persistence.Persistent; * * @author Erik Brakkee */ -public interface PathCondition extends Persistent { +@Entity +@Table(name = "SEC_PATH_CONDITION") +@Inheritance(strategy = InheritanceType.SINGLE_TABLE) +@DiscriminatorColumn(name = "TYPE") +public abstract class PathCondition { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long primaryKey; + + @Version + private int version; + + public PathCondition() { + // Empty + } + + public PathCondition(PathCondition aCondition) { + primaryKey = aCondition.primaryKey; + version = aCondition.version; + } + /** * Checks if the path matches the condition. * @@ -31,5 +62,5 @@ public interface PathCondition extends Persistent { * * @return True iff the path matches. */ - boolean matches(String aPath); + public abstract boolean matches(String aPath); } diff --git a/security/impl/src/main/java/org/wamblee/security/authorization/RegexpPathCondition.java b/security/impl/src/main/java/org/wamblee/security/authorization/RegexpPathCondition.java index ca11c351..e1fa87d4 100644 --- a/security/impl/src/main/java/org/wamblee/security/authorization/RegexpPathCondition.java +++ b/security/impl/src/main/java/org/wamblee/security/authorization/RegexpPathCondition.java @@ -15,6 +15,9 @@ */ package org.wamblee.security.authorization; +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; + import org.wamblee.security.AbstractPersistent; /** @@ -22,8 +25,9 @@ import org.wamblee.security.AbstractPersistent; * * @author Erik Brakkee */ -public class RegexpPathCondition extends AbstractPersistent implements - PathCondition { +@Entity +@DiscriminatorValue("REGEXP") +public class RegexpPathCondition extends PathCondition { /** * String the path must start with. */ diff --git a/security/impl/src/main/java/org/wamblee/security/authorization/StartsWithPathCondition.java b/security/impl/src/main/java/org/wamblee/security/authorization/StartsWithPathCondition.java index a6c68b4e..9233d800 100644 --- a/security/impl/src/main/java/org/wamblee/security/authorization/StartsWithPathCondition.java +++ b/security/impl/src/main/java/org/wamblee/security/authorization/StartsWithPathCondition.java @@ -15,11 +15,16 @@ */ package org.wamblee.security.authorization; +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; + /** * Condition to check whether a path starts with a given string. * * @author Erik Brakkee */ +@Entity +@DiscriminatorValue("STARTSWITH") public class StartsWithPathCondition extends RegexpPathCondition { /** * Constructs the condition. diff --git a/security/impl/src/main/java/org/wamblee/security/authorization/UserCondition.java b/security/impl/src/main/java/org/wamblee/security/authorization/UserCondition.java index 9f0963b7..293869b4 100644 --- a/security/impl/src/main/java/org/wamblee/security/authorization/UserCondition.java +++ b/security/impl/src/main/java/org/wamblee/security/authorization/UserCondition.java @@ -15,6 +15,17 @@ */ package org.wamblee.security.authorization; +import javax.persistence.DiscriminatorColumn; +import javax.persistence.DiscriminatorType; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Table; +import javax.persistence.Version; + import org.wamblee.persistence.Persistent; import org.wamblee.usermgt.User; @@ -24,7 +35,28 @@ import org.wamblee.usermgt.User; * * @author Erik Brakkee */ -public interface UserCondition extends Persistent { +@Entity +@Table(name = "SEC_USER_CONDITION") +@Inheritance(strategy = InheritanceType.SINGLE_TABLE) +@DiscriminatorColumn(name = "TYPE") +public abstract class UserCondition { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long primaryKey; + + @Version + private int version; + + public UserCondition() { + // Empty. + } + + public UserCondition(UserCondition aCondition) { + primaryKey = aCondition.primaryKey; + version = aCondition.version; + } + /** * Determines if the condition matches. * @@ -33,5 +65,5 @@ public interface UserCondition extends Persistent { * * @return True if the condition matches, false otherwise. */ - boolean matches(User aUser); + public abstract boolean matches(User aUser); } diff --git a/security/jpatest/src/test/resources/META-INF/persistence.xml b/security/jpatest/src/test/resources/META-INF/persistence.xml index 58704f7e..f2d8ca1f 100644 --- a/security/jpatest/src/test/resources/META-INF/persistence.xml +++ b/security/jpatest/src/test/resources/META-INF/persistence.xml @@ -8,6 +8,14 @@ org.wamblee.usermgt.User org.wamblee.usermgt.Group + org.wamblee.security.authorization.UserCondition + org.wamblee.security.authorization.AnyUserCondition + org.wamblee.security.authorization.GroupUserCondition + org.wamblee.security.authorization.OperationCondition + org.wamblee.security.authorization.IsaOperationCondition + org.wamblee.security.authorization.PathCondition + org.wamblee.security.authorization.RegexpPathCondition + org.wamblee.security.authorization.StartsWithPathCondition true -- 2.31.1