From 892308472780286f05a3f373cbc11f6f2a32a811 Mon Sep 17 00:00:00 2001 From: Erik Brakkee Date: Fri, 30 Apr 2010 22:20:14 +0000 Subject: [PATCH] --- .../authorization/AuthorizationService.java | 17 ++++++---- .../main/java/org/wamblee/usermgt/Group.java | 4 +-- .../org/wamblee/usermgt/InMemoryGroupSet.java | 14 ++++---- .../org/wamblee/usermgt/jpa/JpaGroupSet.java | 33 +++++++++++-------- .../persistence/PersistentFactory.java | 8 ++--- .../support/ThreadSpecificProxyFactory.java | 27 +++++++++------ 6 files changed, 60 insertions(+), 43 deletions(-) diff --git a/security/impl/src/main/java/org/wamblee/security/authorization/AuthorizationService.java b/security/impl/src/main/java/org/wamblee/security/authorization/AuthorizationService.java index 7a0816a9..349ef757 100644 --- a/security/impl/src/main/java/org/wamblee/security/authorization/AuthorizationService.java +++ b/security/impl/src/main/java/org/wamblee/security/authorization/AuthorizationService.java @@ -12,7 +12,7 @@ * 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 org.wamblee.usermgt.UserAccessor; @@ -37,12 +37,17 @@ public interface AuthorizationService { boolean isAllowed(Object aResource, Operation aOperation); /** - * Checks if the given operation is allowed on the resource. - * @param Type of resource - * @param aResource Resource. - * @param aOperation Operation. + * Checks if the given operation is allowed on the resource. + * + * @param + * Type of resource + * @param aResource + * Resource. + * @param aOperation + * Operation. * @return Resource passed in in case access is allowed - * @throws AuthorizationException In case access is denied. + * @throws AuthorizationException + * In case access is denied. */ T check(T aResource, Operation aOperation); diff --git a/security/impl/src/main/java/org/wamblee/usermgt/Group.java b/security/impl/src/main/java/org/wamblee/usermgt/Group.java index 87ab4ac7..b203c63d 100644 --- a/security/impl/src/main/java/org/wamblee/usermgt/Group.java +++ b/security/impl/src/main/java/org/wamblee/usermgt/Group.java @@ -145,8 +145,8 @@ public class Group implements Serializable, Comparable { public Long getPrimaryKey() { return primaryKey; } - - public void setPrimaryKey(Long aKey) { + + public void setPrimaryKey(Long aKey) { primaryKey = aKey; } diff --git a/security/impl/src/main/java/org/wamblee/usermgt/InMemoryGroupSet.java b/security/impl/src/main/java/org/wamblee/usermgt/InMemoryGroupSet.java index 227e8853..ce2d7b8b 100644 --- a/security/impl/src/main/java/org/wamblee/usermgt/InMemoryGroupSet.java +++ b/security/impl/src/main/java/org/wamblee/usermgt/InMemoryGroupSet.java @@ -12,7 +12,7 @@ * 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.usermgt; import java.util.ArrayList; @@ -27,9 +27,9 @@ import java.util.concurrent.atomic.AtomicLong; * @author Erik Brakkee */ public class InMemoryGroupSet implements GroupSet { - + private AtomicLong pk = new AtomicLong(1l); - + /** * Groups. */ @@ -49,8 +49,8 @@ public class InMemoryGroupSet implements GroupSet { * org.wamblee.usermgt.GroupSet#groupModified(org.wamblee.usermgt.Group) */ public void groupModified(Group aGroup) { - for (int i = 0; i < groups.size(); i++) { - if (groups.get(i).getPrimaryKey().equals(aGroup.getPrimaryKey())) { + for (int i = 0; i < groups.size(); i++) { + if (groups.get(i).getPrimaryKey().equals(aGroup.getPrimaryKey())) { groups.remove(i); groups.add(aGroup); return; @@ -89,8 +89,8 @@ public class InMemoryGroupSet implements GroupSet { */ public boolean add(Group aGroup) { aGroup.setPrimaryKey(pk.getAndIncrement()); - if ( find(aGroup.getName()) != null ) { - return false; + if (find(aGroup.getName()) != null) { + return false; } return groups.add(aGroup); } diff --git a/security/impl/src/main/java/org/wamblee/usermgt/jpa/JpaGroupSet.java b/security/impl/src/main/java/org/wamblee/usermgt/jpa/JpaGroupSet.java index 763fced4..b9db2397 100644 --- a/security/impl/src/main/java/org/wamblee/usermgt/jpa/JpaGroupSet.java +++ b/security/impl/src/main/java/org/wamblee/usermgt/jpa/JpaGroupSet.java @@ -12,10 +12,10 @@ import org.wamblee.usermgt.Group; import org.wamblee.usermgt.GroupSet; public class JpaGroupSet implements GroupSet { - - private EntityManager em; - - public JpaGroupSet(EntityManager aEm) { + + private EntityManager em; + + public JpaGroupSet(EntityManager aEm) { em = aEm; } @@ -31,12 +31,13 @@ public class JpaGroupSet implements GroupSet { @Override public boolean contains(Group aGroup) { - return find(aGroup.getName()) != null; + return find(aGroup.getName()) != null; } @Override public Group find(String aName) { - TypedQuery query = em.createNamedQuery(Group.QUERY_FIND_BY_NAME, Group.class); + TypedQuery query = em.createNamedQuery(Group.QUERY_FIND_BY_NAME, + Group.class); query.setParameter(Group.NAME_PARAM, aName); List groups = query.getResultList(); if (groups.size() > 1) { @@ -54,25 +55,28 @@ public class JpaGroupSet implements GroupSet { public void groupModified(Group aGroup) { assert aGroup.getPrimaryKey() != null; Group merged = em.merge(aGroup); - // Need to flush so that version of the merged instance is updated so we can use - // the updated version in the original group passed in. That allows the same - // group object to continue to be used as a detached object. + // Need to flush so that version of the merged instance is updated so we + // can use + // the updated version in the original group passed in. That allows the + // same + // group object to continue to be used as a detached object. em.flush(); JpaMergeSupport.merge(merged, aGroup); } @Override public Set list() { - List groups = em.createNamedQuery(Group.QUERY_ALL_GROUPS, Group.class).getResultList(); + List groups = em.createNamedQuery(Group.QUERY_ALL_GROUPS, + Group.class).getResultList(); Set res = new TreeSet(groups); - return res; + return res; } @Override public boolean remove(Group aGroup) { Group group = find(aGroup.getName()); - if ( group == null ) { - return false; + if (group == null) { + return false; } em.remove(group); return true; @@ -80,7 +84,8 @@ public class JpaGroupSet implements GroupSet { @Override public int size() { - Long res = (Long)em.createNamedQuery(Group.QUERY_COUNT_GROUPS).getSingleResult(); + Long res = (Long) em.createNamedQuery(Group.QUERY_COUNT_GROUPS) + .getSingleResult(); return res.intValue(); } } diff --git a/support/general/src/main/java/org/wamblee/persistence/PersistentFactory.java b/support/general/src/main/java/org/wamblee/persistence/PersistentFactory.java index fddc76b9..c633f955 100644 --- a/support/general/src/main/java/org/wamblee/persistence/PersistentFactory.java +++ b/support/general/src/main/java/org/wamblee/persistence/PersistentFactory.java @@ -171,16 +171,16 @@ public class PersistentFactory { @Override public Number getPersistedVersion() { - if ( accessor == null || accessor.getVersion() == null) { - return null; + if (accessor == null || accessor.getVersion() == null) { + return null; } return (Number) accessor.getVersion().get(entity); } @Override public void setPersistedVersion(Number aVersion) { - if ( accessor == null || accessor.getVersion() == null) { - return; + if (accessor == null || accessor.getVersion() == null) { + return; } accessor.getVersion().set(entity, aVersion); } diff --git a/test/enterprise/src/main/java/org/wamblee/support/ThreadSpecificProxyFactory.java b/test/enterprise/src/main/java/org/wamblee/support/ThreadSpecificProxyFactory.java index 1e9c3468..e47c037a 100644 --- a/test/enterprise/src/main/java/org/wamblee/support/ThreadSpecificProxyFactory.java +++ b/test/enterprise/src/main/java/org/wamblee/support/ThreadSpecificProxyFactory.java @@ -49,28 +49,34 @@ public class ThreadSpecificProxyFactory { private Class clazz; /** - * Constructs the factory. - * @param aClass Interface class of the service to proxy. + * Constructs the factory. + * + * @param aClass + * Interface class of the service to proxy. */ public ThreadSpecificProxyFactory(Class aClass) { - if ( !aClass.isInterface() ) { - throw new IllegalArgumentException("Class " + aClass.getName() + " is not an interface"); + if (!aClass.isInterface()) { + throw new IllegalArgumentException("Class " + aClass.getName() + + " is not an interface"); } clazz = aClass; } /** - * Sets the thread-specific service. - * @param aService Service, use null value to reset. + * Sets the thread-specific service. + * + * @param aService + * Service, use null value to reset. */ public void set(T aService) { svc.set(aService); } /** - * Gets the proxy that delegates to the thread-specific instance set by + * Gets the proxy that delegates to the thread-specific instance set by * {@link #set(Object)} - * @return Proxy. + * + * @return Proxy. */ public T getProxy() { InvocationHandler handler = new ThreadSpecificInvocationHandler(); @@ -82,8 +88,9 @@ public class ThreadSpecificProxyFactory { new Class[] { InvocationHandler.class }).newInstance( new Object[] { handler }); return proxy; - } catch (Exception e) { - throw new RuntimeException("Could not create proxy for " + clazz.getName(), e); + } catch (Exception e) { + throw new RuntimeException("Could not create proxy for " + + clazz.getName(), e); } } } -- 2.31.1