X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=security%2Fimpl%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fsecurity%2Fauthorization%2FUrlAuthorizationRule.java;h=c68457559a42892ca2e3aa8739ee34ea88e41b73;hb=c95984208ca007c2c285df8ba52457cca7e4ab30;hp=adeb93c157f0ebaa9522e20ef1fd01cabbcaf9e9;hpb=4565fa62b5e77ce0ffbac381bc0ef1813da94af7;p=utils
diff --git a/security/impl/src/main/java/org/wamblee/security/authorization/UrlAuthorizationRule.java b/security/impl/src/main/java/org/wamblee/security/authorization/UrlAuthorizationRule.java
index adeb93c1..c6845755 100644
--- a/security/impl/src/main/java/org/wamblee/security/authorization/UrlAuthorizationRule.java
+++ b/security/impl/src/main/java/org/wamblee/security/authorization/UrlAuthorizationRule.java
@@ -15,15 +15,19 @@
*/
package org.wamblee.security.authorization;
-import org.apache.log4j.Logger;
+import static org.wamblee.security.authorization.AuthorizationResult.*;
-import org.wamblee.persistence.AbstractPersistent;
-import static org.wamblee.security.authorization.AuthorizationResult.DENIED;
-import static org.wamblee.security.authorization.AuthorizationResult.GRANTED;
-import static org.wamblee.security.authorization.AuthorizationResult.UNDECIDED;
-import static org.wamblee.security.authorization.AuthorizationResult.UNSUPPORTED_RESOURCE;
+import javax.persistence.Access;
+import javax.persistence.AccessType;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.JoinColumn;
+import javax.persistence.OneToOne;
+import javax.persistence.Transient;
-import org.wamblee.usermgt.User;
+import org.apache.log4j.Logger;
+import org.wamblee.security.authentication.UserAdministration;
/**
* Utility base class for implementation of authentication rules based on the
@@ -31,12 +35,12 @@ import org.wamblee.usermgt.User;
*
The path of the resource. To obtain the path of a resource, subclasses
* must implement {@link #getResourcePath(Object)}. Whether a path is
* appropriate is determined by a
- * {@link org.wamblee.security.authorization.PathCondition}.
+ * {@link org.wamblee.security.authorization.AbstractPathCondition}.
* The user identity with which the resource is accessed. Whether a user is
* appropriate is determined by a
- * {@link org.wamblee.security.authorization.UserCondition}.
+ * {@link org.wamblee.security.authorization.AbstractUserCondition}.
* The operation that is requested. Whether the operation is appropriate is
- * determined by a {@link org.wamblee.security.authorization.OperationCondition}
+ * determined by a {@link org.wamblee.security.authorization.AbstractOperationCondition}
* .
*
* In case all three conditions match, the condition returns the configured
@@ -44,8 +48,9 @@ import org.wamblee.usermgt.User;
* the specified type, the result is UNSUPPORTED_RESOURCE, otherwise, the result
* is UNDECIDED.
*/
-public abstract class UrlAuthorizationRule extends AbstractPersistent implements
- AuthorizationRule {
+@Entity
+@Access(AccessType.PROPERTY)
+public abstract class UrlAuthorizationRule extends AbstractAuthorizationRule {
private static final Logger LOGGER = Logger
.getLogger(UrlAuthorizationRule.class);
@@ -72,6 +77,7 @@ public abstract class UrlAuthorizationRule extends AbstractPersistent implements
/**
* Operation that this rule is for.
*/
+
private OperationCondition operationCondition;
/**
@@ -134,6 +140,7 @@ public abstract class UrlAuthorizationRule extends AbstractPersistent implements
* @see
* org.wamblee.security.authorization.AuthorizationRule#getSupportedTypes()
*/
+ @Transient
public Class[] getSupportedTypes() {
return new Class[] { resourceClass };
}
@@ -146,14 +153,14 @@ public abstract class UrlAuthorizationRule extends AbstractPersistent implements
* .Object, org.wamblee.security.authorization.Operation)
*/
public AuthorizationResult isAllowed(Object aResource,
- Operation aOperation, User aUser) {
+ Operation aOperation, String aUser) {
if (!resourceClass.isInstance(aResource)) {
return UNSUPPORTED_RESOURCE;
}
String path = getResourcePath(aResource);
- return isAllowed(path, aOperation, aUser);
+ return isAllowedWithPath(path, aOperation, aUser);
}
/**
@@ -168,8 +175,8 @@ public abstract class UrlAuthorizationRule extends AbstractPersistent implements
*
* @return Authorization result,
*/
- protected AuthorizationResult isAllowed(String aPath, Operation aOperation,
- User aUser) {
+ protected AuthorizationResult isAllowedWithPath(String aPath, Operation aOperation,
+ String aUser) {
if (!pathCondition.matches(aPath)) {
return UNDECIDED;
}
@@ -213,6 +220,7 @@ public abstract class UrlAuthorizationRule extends AbstractPersistent implements
*
* @return Result.
*/
+ @Column(name = "AUTH_RESULT", nullable = false)
protected String getAuthorizationResultString() {
if (result == null) {
return null;
@@ -231,6 +239,7 @@ public abstract class UrlAuthorizationRule extends AbstractPersistent implements
result = AuthorizationResult.valueOf(aResult);
}
+ @Column(name = "RES_CLASSNAME", nullable = false)
protected String getResourceClassName() {
if (resourceClass == null) {
return "";
@@ -253,6 +262,8 @@ public abstract class UrlAuthorizationRule extends AbstractPersistent implements
*
* @return Returns the operationCondition.
*/
+ @OneToOne(cascade = CascadeType.ALL, targetEntity = AbstractOperationCondition.class, orphanRemoval = true)
+ @JoinColumn(name = "OPER_COND_PK")
public OperationCondition getOperationCondition() {
return operationCondition;
}
@@ -270,6 +281,8 @@ public abstract class UrlAuthorizationRule extends AbstractPersistent implements
*
* @return Returns the pathCondition.
*/
+ @OneToOne(cascade = CascadeType.ALL, targetEntity = AbstractPathCondition.class, orphanRemoval = true)
+ @JoinColumn(name = "PATH_COND_PK")
public PathCondition getPathCondition() {
return pathCondition;
}
@@ -287,6 +300,8 @@ public abstract class UrlAuthorizationRule extends AbstractPersistent implements
*
* @return Returns the userCondition.
*/
+ @OneToOne(cascade = CascadeType.ALL, targetEntity = AbstractUserCondition.class, orphanRemoval = true)
+ @JoinColumn(name = "USER_COND_PK")
public UserCondition getUserCondition() {
return userCondition;
}
@@ -299,4 +314,10 @@ public abstract class UrlAuthorizationRule extends AbstractPersistent implements
protected void setUserCondition(UserCondition aUserCondition) {
userCondition = aUserCondition;
}
+
+ @Override
+ public void setUserAdministration(UserAdministration aAdmin) {
+ userCondition.setUserAdmin(aAdmin);
+ }
+
}