import javax.persistence.Table;
import javax.persistence.Version;
-import org.wamblee.persistence.Persistent;
-
import org.wamblee.usermgt.User;
/**
*/
package org.wamblee.security.authorization;
-import org.wamblee.persistence.Persistent;
+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.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.Table;
+import javax.persistence.Version;
+
+import org.wamblee.usermgt.UserAccessor;
/**
* Service to determine if access to a certain resource is allowed.
*
* @author Erik Brakkee
*/
-public interface AuthorizationService extends Persistent {
+@Entity
+@Table(name = "SEC_AUTH_SVC")
+@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
+@DiscriminatorColumn(name = "TYPE")
+@NamedQueries(
+ @NamedQuery(name = AuthorizationService.QUERY_FIND_BY_NAME,
+ query = "select s from AuthorizationService s where s.name = :" +
+ AuthorizationService.NAME_PARAM)
+ )
+public abstract class AuthorizationService {
+
+ public static final String QUERY_FIND_BY_NAME = "AuthorizationService.findByName";
+ public static final String NAME_PARAM = "name";
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Long primaryKey;
+
+ @Version
+ private int version;
+
+ public AuthorizationService() {
+ // Empty.
+ }
+
+ public AuthorizationService(AuthorizationService aSvc) {
+ primaryKey = aSvc.primaryKey;
+ version = aSvc.version;
+ }
+
/**
* Checks whether an operation is allowed on a resource.
*
*
* @return Checks whether the operation is allowed on a resource.
*/
- boolean isAllowed(Object aResource, Operation aOperation);
+ public abstract boolean isAllowed(Object aResource, Operation aOperation);
- <T> T check(T aResource, Operation aOperation);
+ public abstract <T> T check(T aResource, Operation aOperation);
/**
* Gets the authorization rules.
*
* @return Rules.
*/
- AuthorizationRule[] getRules();
+ public abstract AuthorizationRule[] getRules();
/**
* Appends a new authorization rule to the end.
* @param aRule
* Rule to append.
*/
- void appendRule(AuthorizationRule aRule);
+ public abstract void appendRule(AuthorizationRule aRule);
/**
* Removes a rule.
* @param aIndex
* Index of the rule to remove.
*/
- void removeRule(int aIndex);
+ public abstract void removeRule(int aIndex);
/**
* Inserts a rule.
* @param aRule
* Rule to insert.
*/
- void insertRuleAfter(int aIndex, AuthorizationRule aRule);
+ public abstract void insertRuleAfter(int aIndex, AuthorizationRule aRule);
+
+ /**
+ * Sets the user accessor so that the authorization service can get access to the logged in
+ * user.
+ * @param aUserAccessor User accessor.
+ */
+ public abstract void setUserAccessor(UserAccessor aUserAccessor);
}
* 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.
- */
+ */
package org.wamblee.security.authorization;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
-import org.wamblee.security.AbstractPersistent;
import org.wamblee.usermgt.User;
import org.wamblee.usermgt.UserAccessor;
-import java.util.ArrayList;
-import java.util.List;
-
/**
* Default implementation of an authorization service. To determine whether
* access to a resource is allowed, the service consults a number of
*
* @author Erik Brakkee
*/
-public class DefaultAuthorizationService extends AbstractPersistent implements
- AuthorizationService {
+@Entity
+@DiscriminatorValue("DEFAULT")
+public class DefaultAuthorizationService extends AuthorizationService {
+
+
/**
* List of ordered authorization rules.
*/
* @param aUserAccessor
* User accessor.
*/
+ @Override
public void setUserAccessor(UserAccessor aUserAccessor) {
userAccessor = aUserAccessor;
}
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
-import org.wamblee.security.AbstractPersistent;
import org.wamblee.usermgt.User;
+
/**
* Checks if a user against a specific group.
*
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
-import org.wamblee.security.AbstractPersistent;
-
/**
* Determiens if an operation is a subclass of a specified operation.
*/
import javax.persistence.Table;
import javax.persistence.Version;
-import org.wamblee.persistence.Persistent;
-
/**
* Checks if an operation matches a condition.
*
import javax.persistence.Table;
import javax.persistence.Version;
-import org.wamblee.persistence.Persistent;
-
/**
* Checks if a path satisfies a condition.
*
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
-import org.wamblee.security.AbstractPersistent;
-
/**
* Condition to check whether a path matches a given regula expression.
*
*/
package org.wamblee.security.authorization;
+import static org.wamblee.security.authorization.AuthorizationResult.*;
+
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;
-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 org.wamblee.security.AbstractPersistent;
import org.wamblee.usermgt.User;
/**
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.Table;
import javax.persistence.Version;
-import org.wamblee.persistence.Persistent;
-
import org.wamblee.usermgt.User;
/**
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
-import javax.persistence.UniqueConstraint;
import javax.persistence.Version;
-import org.wamblee.security.AbstractPersistent;
-
/**
* Represents a group.
*
*/
package org.wamblee.usermgt;
-import org.wamblee.security.AbstractPersistent;
-import org.wamblee.security.encryption.MessageDigester;
-
-import org.wamblee.usermgt.UserMgtException.Reason;
-
import java.io.Serializable;
-
import java.util.Set;
import java.util.TreeSet;
import javax.persistence.Transient;
import javax.persistence.Version;
+import org.wamblee.security.encryption.MessageDigester;
+import org.wamblee.usermgt.UserMgtException.Reason;
+
/**
* Represents a user. The methods for managing the groups of the user have
* package scope. Managing the groups of the user should be done through the
*/
package org.wamblee.usermgt;
-import junit.framework.TestCase;
-
-import java.sql.SQLException;
-
import java.util.Set;
+import junit.framework.TestCase;
+
/**
* Tests the inmemory group set. Intended to be subclassed for other
* implementations of group set.
*/
package org.wamblee.security.authorization.hibernate;
-import org.springframework.orm.hibernate3.HibernateTemplate;
-
-import org.wamblee.persistence.hibernate.HibernateSupport;
+import java.util.List;
-import org.wamblee.security.AbstractPersistent;
+import org.springframework.orm.hibernate3.HibernateTemplate;
import org.wamblee.security.authorization.AuthorizationRule;
import org.wamblee.security.authorization.AuthorizationService;
import org.wamblee.security.authorization.DefaultAuthorizationService;
import org.wamblee.security.authorization.Operation;
-
import org.wamblee.usermgt.UserAccessor;
-import java.util.List;
-
/**
* Authorization service with persistent storage. This is a wrapper for
* {@link org.wamblee.security.authorization.DefaultAuthorizationService} which
*
* @author Erik Brakkee
*/
-public class PersistentAuthorizationService extends AbstractPersistent
- implements AuthorizationService {
+public class PersistentAuthorizationService extends AuthorizationService {
/**
* Name of query to find the service by name.
*/
userAccessor = aAccessor;
name = aName;
}
+
+ @Override
+ public void setUserAccessor(UserAccessor aUserAccessor) {
+ userAccessor = aUserAccessor;
+ }
/**
* Initialize service if needed.
* Saves any changes to the service state if necessary.
*/
private void save() {
- HibernateSupport.merge(template, service);
+ // HibernateSupport.merge(template, service);
}
}
*/
package org.wamblee.usermgt;
-import net.sf.ehcache.Ehcache;
+import java.util.HashMap;
+import java.util.Map;
import org.hibernate.SessionFactory;
-
import org.wamblee.cache.EhCache;
-
import org.wamblee.system.core.DefaultProvidedInterface;
import org.wamblee.system.core.DefaultRequiredInterface;
import org.wamblee.system.core.ProvidedInterface;
import org.wamblee.system.core.RequiredInterface;
import org.wamblee.system.spring.SpringComponent;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.TreeMap;
-
/**
*
* @author $author$
*/
package org.wamblee.security.authorization.hibernate;
-import org.apache.log4j.Logger;
+import java.sql.SQLException;
-import org.hibernate.annotations.AccessType;
+import org.apache.log4j.Logger;
import org.hibernate.cfg.Configuration;
-
-import org.hibernate.dialect.MySQL5Dialect;
import org.hibernate.dialect.MySQL5InnoDBDialect;
-
import org.hibernate.tool.hbm2ddl.SchemaExport;
-
import org.springframework.orm.hibernate3.HibernateTemplate;
-
-import org.wamblee.general.BeanKernel;
-
import org.wamblee.security.authorization.AuthorizationService;
import org.wamblee.security.authorization.AuthorizationServiceTest;
import org.wamblee.security.authorization.TestUserAccessor;
-
import org.wamblee.system.adapters.ClassConfiguration;
-import org.wamblee.system.adapters.ClassConfigurationTest;
import org.wamblee.system.adapters.DefaultContainer;
import org.wamblee.system.adapters.ObjectConfiguration;
import org.wamblee.system.components.DatabaseComponentFactory;
import org.wamblee.system.core.Scope;
import org.wamblee.system.spring.component.DatabaseTesterComponent;
import org.wamblee.system.spring.component.DatasourceComponent;
-
import org.wamblee.usermgt.UserAccessor;
import org.wamblee.usermgt.hibernate.AuthorizationComponent;
-import org.wamblee.usermgt.hibernate.HibernateUserAdministrationTest;
-import org.wamblee.usermgt.hibernate.UserAdministrationComponent;
-
-import java.sql.SQLException;
/**
* Unit test for the persistent authorization service.
import java.sql.Connection;
import java.sql.ResultSet;
-import java.sql.SQLException;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.wamblee.support.persistence.JpaTester;
import org.wamblee.support.persistence.TransactionProxyFactory;
import org.wamblee.support.persistence.DatabaseUtils.JdbcUnitOfWork;
*/
package org.wamblee.io;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.PrintStream;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Arrays;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
/**
*
* @author $author$
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
*/
package org.wamblee.concurrency;
-import junit.framework.Assert;
import junit.framework.TestCase;
/**
*/
package org.wamblee.io;
-import junit.framework.Assert;
-
import java.io.ByteArrayInputStream;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.MappedByteBuffer;
-import java.nio.channels.FileChannel;
+import junit.framework.Assert;
/**
* TestData provides a convenient interface for managing test output files.
*/
package org.wamblee.xml;
-import junit.framework.TestCase;
-
-import org.w3c.dom.Document;
-
-import org.wamblee.io.ClassPathResource;
-import org.wamblee.io.FileSystemUtils;
-import org.wamblee.io.InputResource;
-
import java.io.ByteArrayOutputStream;
-import java.io.File;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
+import junit.framework.TestCase;
+
+import org.w3c.dom.Document;
+import org.wamblee.io.ClassPathResource;
+import org.wamblee.io.FileSystemUtils;
+import org.wamblee.io.InputResource;
+
/**
* Tests the XSL transformer.
*
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.access.BeanFactoryLocator;
import org.springframework.beans.factory.access.BeanFactoryReference;
-
import org.springframework.context.access.ContextSingletonBeanFactoryLocator;
-
import org.wamblee.general.BeanFactory;
import org.wamblee.general.BeanFactoryException;
-import org.wamblee.general.BeanKernel;
/**
* Bean factory which uses Spring. This bean factory cannot be configured
*/
package org.wamblee.support.jndi;
-import java.util.HashMap;
import java.util.Hashtable;
-import java.util.Map;
import javax.naming.Context;
-import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.spi.InitialContextFactory;
*/
package org.wamblee.support.persistence;
-import java.util.Arrays;
-import java.util.List;
import java.util.logging.Logger;
import javax.sql.DataSource;
-import org.apache.commons.dbcp.ConnectionFactory;
-import org.apache.commons.dbcp.DriverManagerConnectionFactory;
-import org.apache.commons.dbcp.PoolableConnectionFactory;
-import org.apache.commons.dbcp.PoolingDataSource;
-import org.apache.commons.pool.impl.GenericObjectPool;
-
/**
* Database that encapsulates connection to an external database. Database
* connection details can be configured through system properties and
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
-import javax.management.RuntimeErrorException;
import javax.persistence.EntityManager;
import org.wamblee.support.ThreadSpecificProxyFactory;
*/
package org.wamblee.support;
-import javax.xml.ws.Holder;
+import static junit.framework.Assert.*;
+import static org.mockito.Matchers.*;
+import static org.mockito.Mockito.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import static junit.framework.TestCase.*;
-import static org.mockito.Mockito.*;
public class ThreadSpecificProxyFactoryTest {
*/
package org.wamblee.support.persistence;
+import static junit.framework.Assert.*;
+
import javax.persistence.EntityManager;
-import javax.persistence.Persistence;
-import javax.sql.DataSource;
-import org.dbunit.DataSourceDatabaseTester;
-import org.dbunit.DatabaseTestCase;
import org.dbunit.IDatabaseTester;
import org.dbunit.dataset.ITable;
-import org.dbunit.dataset.filter.ITableFilterSimple;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.wamblee.support.persistence.DatabaseUtils;
-import org.wamblee.support.persistence.JpaBuilder;
-import org.wamblee.support.persistence.JpaTester;
import org.wamblee.support.persistence.JpaBuilder.JpaUnitOfWork;
-import static junit.framework.Assert.*;
-
/**
* This class shows an example of how to test an entity using jpa.
*/
*/
package org.wamblee.support.persistence.hibernate;
-import static junit.framework.Assert.assertEquals;
-
-import org.dbunit.IDatabaseTester;
-
-import org.dbunit.dataset.ITable;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import org.wamblee.support.persistence.Database;
-import org.wamblee.support.persistence.DatabaseBuilder;
-import org.wamblee.support.persistence.DatabaseUtils;
import org.wamblee.support.persistence.DatabaseUtilsTestBase;
-import org.wamblee.support.persistence.JpaBuilder;
-import org.wamblee.support.persistence.JpaBuilder.JpaUnitOfWork;
-import org.wamblee.support.persistence.PersistenceUnitDescription;
-
-import javax.persistence.EntityManager;
-
-import javax.sql.DataSource;
/**
*
*/
package org.wamblee.support.persistence.hibernate;
-import static junit.framework.Assert.*;
-
-import org.dbunit.DataSourceDatabaseTester;
-import org.dbunit.DatabaseTestCase;
-import org.dbunit.IDatabaseTester;
-
-import org.dbunit.dataset.ITable;
-import org.dbunit.dataset.filter.ITableFilterSimple;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import org.wamblee.support.persistence.DatabaseUtils;
-import org.wamblee.support.persistence.JpaBuilder;
-import org.wamblee.support.persistence.JpaBuilder.JpaUnitOfWork;
-import org.wamblee.support.persistence.JpaTester;
import org.wamblee.support.persistence.MyEntityExampleTestBase;
-import javax.persistence.EntityManager;
-import javax.persistence.Persistence;
-
-import javax.sql.DataSource;
-
/**
* This class shows an example of how to test an entity using jpa.
*/