* 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;
boolean isAllowed(Object aResource, Operation aOperation);
/**
- * Checks if the given operation is allowed on the resource.
- * @param <T> Type of resource
- * @param aResource Resource.
- * @param aOperation Operation.
+ * Checks if the given operation is allowed on the resource.
+ *
+ * @param <T>
+ * 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> T check(T aResource, Operation aOperation);
public Long getPrimaryKey() {
return primaryKey;
}
-
- public void setPrimaryKey(Long aKey) {
+
+ public void setPrimaryKey(Long aKey) {
primaryKey = aKey;
}
* 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;
* @author Erik Brakkee
*/
public class InMemoryGroupSet implements GroupSet {
-
+
private AtomicLong pk = new AtomicLong(1l);
-
+
/**
* Groups.
*/
* 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;
*/
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);
}
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;
}
@Override
public boolean contains(Group aGroup) {
- return find(aGroup.getName()) != null;
+ return find(aGroup.getName()) != null;
}
@Override
public Group find(String aName) {
- TypedQuery<Group> query = em.createNamedQuery(Group.QUERY_FIND_BY_NAME, Group.class);
+ TypedQuery<Group> query = em.createNamedQuery(Group.QUERY_FIND_BY_NAME,
+ Group.class);
query.setParameter(Group.NAME_PARAM, aName);
List<Group> groups = query.getResultList();
if (groups.size() > 1) {
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<Group> list() {
- List<Group> groups = em.createNamedQuery(Group.QUERY_ALL_GROUPS, Group.class).getResultList();
+ List<Group> groups = em.createNamedQuery(Group.QUERY_ALL_GROUPS,
+ Group.class).getResultList();
Set<Group> res = new TreeSet<Group>(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;
@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();
}
}
@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);
}
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<T> 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();
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);
}
}
}