correction to DatabaseUtils for deletion order of db tables.
*/
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;
import org.wamblee.usermgt.User;
*
* @author Erik Brakkee
*/
-public interface AuthorizationRule extends Persistent {
+@Entity
+@Table(name = "SEC_AUTH_RULE")
+@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
+@DiscriminatorColumn(name = "TYPE")
+public abstract class AuthorizationRule {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Long primaryKey;
+
+ @Version
+ private int version;
+
+ public AuthorizationRule() {
+ // Empty
+ }
+
+ public AuthorizationRule(AuthorizationRule aRule) {
+ primaryKey = aRule.primaryKey;
+ version = aRule.version;
+ }
+
/**
* Returns the supported object types for which this authorization rule
* applies. This can be used by the authorization service for optimization.
*
* @return Array of supported types.
*/
- Class[] getSupportedTypes();
+ public abstract Class[] getSupportedTypes();
/**
* Determines whether an operation is allowed on a certain resource. The
*
* @return Authorization result.
*/
- AuthorizationResult isAllowed(Object aResource, Operation aOperation,
+ public abstract AuthorizationResult isAllowed(Object aResource, Operation aOperation,
User aUser);
}
*/
package org.wamblee.security.authorization;
+import javax.persistence.Access;
+import javax.persistence.AccessType;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Transient;
+
import org.apache.log4j.Logger;
import static org.wamblee.security.authorization.AuthorizationResult.DENIED;
* 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 AuthorizationRule {
private static final Logger LOGGER = Logger
.getLogger(UrlAuthorizationRule.class);
* @see
* org.wamblee.security.authorization.AuthorizationRule#getSupportedTypes()
*/
+ @Transient
public Class[] getSupportedTypes() {
return new Class[] { resourceClass };
}
*
* @return Result.
*/
+ @Column(name = "AUTH_RESULT", nullable = false)
protected String getAuthorizationResultString() {
if (result == null) {
return null;
result = AuthorizationResult.valueOf(aResult);
}
+ @Column(name = "RES_CLASSNAME", nullable = false)
protected String getResourceClassName() {
if (resourceClass == null) {
return "";
*
* @return Returns the operationCondition.
*/
+ @ManyToOne(cascade = CascadeType.ALL)
+ @JoinColumn(name = "OPER_COND_PK")
public OperationCondition getOperationCondition() {
return operationCondition;
}
*
* @return Returns the pathCondition.
*/
+ @ManyToOne(cascade = CascadeType.ALL)
+ @JoinColumn(name = "PATH_COND_PK")
public PathCondition getPathCondition() {
return pathCondition;
}
*
* @return Returns the userCondition.
*/
+ @ManyToOne(cascade = CascadeType.ALL)
+ @JoinColumn(name = "USER_COND_PK")
public UserCondition getUserCondition() {
return userCondition;
}
import static org.wamblee.security.authorization.AuthorizationResult.DENIED;
import static org.wamblee.security.authorization.AuthorizationResult.GRANTED;
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+import javax.persistence.Transient;
+
import org.wamblee.usermgt.User;
/**
*
* @author Erik Brakkee
*/
+@Entity
+@DiscriminatorValue("TEST")
public class TestAuthorizationRule extends UrlAuthorizationRule {
/**
* Counts the number of matches.
*/
+ @Transient
private int matches = 0;
/**
<class>org.wamblee.security.authorization.PathCondition</class>
<class>org.wamblee.security.authorization.RegexpPathCondition</class>
<class>org.wamblee.security.authorization.StartsWithPathCondition</class>
+ <class>org.wamblee.security.authorization.AuthorizationRule</class>
+ <class>org.wamblee.security.authorization.UrlAuthorizationRule</class>
+ <class>org.wamblee.security.authorization.TestAuthorizationRule</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
return null;
}
});
- for (String table : tables) {
-
- }
}
public void cleanDatabase(ITableFilterSimple aSelection) throws Exception {
public void emptyTable(String aTable) throws Exception {
executeSql("delete from " + aTable);
}
-
- public void dropTables() throws Exception {
- executeOnTables(tables, new TableSetOperation() {
-
- public void execute(String aTable) throws Exception {
- dropTable(aTable);
- }
- });
+
+ public void dropTables() throws Exception {
+ dropTables(tables);
}
public void dropTables(ITableFilterSimple aTables) throws Exception {
- executeOnTables(aTables, new TableSetOperation() {
+ final String[] tables = getTableNames(aTables);
+ String[] sortedTables = executeInTransaction(new JdbcUnitOfWork<String[]>() {
- public void execute(String aTable) throws Exception {
- dropTable(aTable);
+ public String[] execute(Connection aConnection) throws Exception {
+ IDatabaseConnection connection = new DatabaseConnection(
+ aConnection);
+ ITableFilter filter = new DatabaseSequenceFilter(connection,
+ tables);
+ IDataSet dataset = new FilteredDataSet(filter, connection
+ .createDataSet(tables));
+ return dataset.getTableNames();
}
});
+ for (int i = sortedTables.length-1; i >= 0; i--) {
+ dropTable(sortedTables[i]);
+ }
}
-
+
/**
* @return
* @throws SQLException