You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@turbine.apache.org by pa...@apache.org on 2019/03/25 14:29:47 UTC
svn commit: r1856202 - in
/turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security:
model/dynamic/DynamicAccessControlListImpl.java
model/turbine/TurbineAccessControlListImpl.java util/SecuritySet.java
Author: painter
Date: Mon Mar 25 14:29:46 2019
New Revision: 1856202
URL: http://svn.apache.org/viewvc?rev=1856202&view=rev
Log:
Enforce turbine coding standards, cleanup a couple PMD reported items
Modified:
turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/model/dynamic/DynamicAccessControlListImpl.java
turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/model/turbine/TurbineAccessControlListImpl.java
turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/util/SecuritySet.java
Modified: turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/model/dynamic/DynamicAccessControlListImpl.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/model/dynamic/DynamicAccessControlListImpl.java?rev=1856202&r1=1856201&r2=1856202&view=diff
==============================================================================
--- turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/model/dynamic/DynamicAccessControlListImpl.java (original)
+++ turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/model/dynamic/DynamicAccessControlListImpl.java Mon Mar 25 14:29:46 2019
@@ -18,6 +18,7 @@ package org.apache.fulcrum.security.mode
* specific language governing permissions and limitations
* under the License.
*/
+
import java.util.Map;
import org.apache.fulcrum.security.entity.Group;
@@ -32,10 +33,10 @@ import org.apache.fulcrum.security.util.
* has a given Permission. It also determines if a User has a a particular Role.
*
* @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
- * @version $Id: DynamicAccessControlListImpl.java 1372918 2012-08-14 15:19:40Z
- * tv $
+ * @version $Id$
*/
-public class DynamicAccessControlListImpl implements DynamicAccessControlList {
+public class DynamicAccessControlListImpl implements DynamicAccessControlList
+{
// TODO Need to rethink the two maps.. Why not just a single list of groups?
// That would then cascade down to all the other roles and so on..
@@ -46,12 +47,16 @@ public class DynamicAccessControlListImp
/** The sets of roles that the user has in different groups */
private Map<? extends Group, ? extends RoleSet> roleSets;
+
/** The sets of permissions that the user has in different groups */
private Map<? extends Role, ? extends PermissionSet> permissionSets;
+
/** The distinct list of groups that this user is part of */
private GroupSet groupSet = new GroupSet();
+
/** The distinct list of roles that this user is part of */
private RoleSet roleSet = new RoleSet();
+
/** the distinct list of permissions that this user has */
private PermissionSet permissionSet = new PermissionSet();
@@ -76,13 +81,16 @@ public class DynamicAccessControlListImp
Map<? extends Role, ? extends PermissionSet> permissionSets) {
this.roleSets = roleSets;
this.permissionSets = permissionSets;
- for (Map.Entry<? extends Group, ? extends RoleSet> entry : roleSets.entrySet()) {
+ for (Map.Entry<? extends Group, ? extends RoleSet> entry : roleSets.entrySet())
+ {
Group group = entry.getKey();
groupSet.add(group);
RoleSet rs = entry.getValue();
roleSet.add(rs);
}
- for (Map.Entry<? extends Role, ? extends PermissionSet> entry : permissionSets.entrySet()) {
+
+ for (Map.Entry<? extends Role, ? extends PermissionSet> entry : permissionSets.entrySet())
+ {
Role role = entry.getKey();
roleSet.add(role);
PermissionSet ps = entry.getValue();
@@ -97,7 +105,8 @@ public class DynamicAccessControlListImp
* @return the set of Roles this user has within the Group.
*/
public RoleSet getRoles(Group group) {
- if (group == null) {
+ if (group == null)
+ {
return null;
}
@@ -121,9 +130,12 @@ public class DynamicAccessControlListImp
*/
public PermissionSet getPermissions(Group group) {
PermissionSet permissionSet = new PermissionSet();
- if (roleSets.containsKey(group)) {
- for (Role role : roleSets.get(group)) {
- if (permissionSets.containsKey(role)) {
+ if (roleSets.containsKey(group))
+ {
+ for (Role role : roleSets.get(group))
+ {
+ if (permissionSets.containsKey(role))
+ {
permissionSet.add(permissionSets.get(role));
}
}
@@ -149,7 +161,8 @@ public class DynamicAccessControlListImp
*/
public boolean hasRole(Role role, Group group) {
RoleSet set = getRoles(group);
- if (set == null || role == null) {
+ if (set == null || role == null)
+ {
return false;
}
return set.contains(role);
@@ -164,13 +177,16 @@ public class DynamicAccessControlListImp
* given Groups.
*/
public boolean hasRole(Role role, GroupSet groupset) {
- if (role == null) {
+ if (role == null)
+ {
return false;
}
- for (Group group : groupset) {
+ for (Group group : groupset)
+ {
RoleSet roles = getRoles(group);
- if (roles != null && roles.contains(role)) {
+ if (roles != null && roles.contains(role))
+ {
return true;
}
}
@@ -186,15 +202,20 @@ public class DynamicAccessControlListImp
*/
public boolean hasRole(String role, String group) {
boolean roleFound = false;
- try {
- for (Map.Entry<? extends Group, ? extends RoleSet> entry : roleSets.entrySet()) {
+ try
+ {
+ for (Map.Entry<? extends Group, ? extends RoleSet> entry : roleSets.entrySet())
+ {
Group g = entry.getKey();
- if (g.getName().equalsIgnoreCase(group)) {
+ if (g.getName().equalsIgnoreCase(group))
+ {
RoleSet rs = entry.getValue();
roleFound = rs.containsName(role);
}
}
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
roleFound = false;
}
return roleFound;
@@ -210,17 +231,25 @@ public class DynamicAccessControlListImp
*/
public boolean hasRole(String rolename, GroupSet groupset) {
Role role;
- try {
+ try
+ {
role = roleSet.getByName(rolename);
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
return false;
}
- if (role == null) {
+
+ if (role == null)
+ {
return false;
}
- for (Group group : groupset) {
+
+ for (Group group : groupset)
+ {
RoleSet roles = getRoles(group);
- if (roles != null && roles.contains(role)) {
+ if (roles != null && roles.contains(role))
+ {
return true;
}
}
@@ -245,9 +274,12 @@ public class DynamicAccessControlListImp
* @return <code>true</code> if the user is assigned the Role .
*/
public boolean hasRole(String role) {
- try {
+ try
+ {
return roleSet.containsName(role);
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
return false;
}
}
@@ -262,7 +294,8 @@ public class DynamicAccessControlListImp
*/
public boolean hasPermission(Permission permission, Group group) {
PermissionSet set = getPermissions(group);
- if (set == null || permission == null) {
+ if (set == null || permission == null)
+ {
return false;
}
return set.contains(permission);
@@ -278,12 +311,16 @@ public class DynamicAccessControlListImp
* the given Groups.
*/
public boolean hasPermission(Permission permission, GroupSet groupset) {
- if (permission == null) {
+ if (permission == null)
+ {
return false;
}
- for (Group group : groupset) {
+
+ for (Group group : groupset)
+ {
PermissionSet permissions = getPermissions(group);
- if (permissions != null && permissions.contains(permission)) {
+ if (permissions != null && permissions.contains(permission))
+ {
return true;
}
}
@@ -299,9 +336,12 @@ public class DynamicAccessControlListImp
* Group.
*/
public boolean hasPermission(String permission, String group) {
- try {
+ try
+ {
return hasPermission(permissionSet.getByName(permission), groupSet.getByName(group));
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
return false;
}
}
@@ -315,9 +355,12 @@ public class DynamicAccessControlListImp
* Group.
*/
public boolean hasPermission(String permission, Group group) {
- try {
+ try
+ {
return hasPermission(permissionSet.getByName(permission), group);
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
return false;
}
}
@@ -333,20 +376,24 @@ public class DynamicAccessControlListImp
*/
public boolean hasPermission(String permissionName, GroupSet groupset) {
Permission permission;
- try {
+ try
+ {
permission = permissionSet.getByName(permissionName);
} catch (Exception e) {
return false;
}
- if (permission == null) {
+
+ if (permission == null)
+ {
return false;
}
- for (Group group : groupset) {
+
+ for (Group group : groupset)
+ {
PermissionSet permissions = getPermissions(group);
- if (permissions != null) {
- if (permissions.contains(permission)) {
- return true;
- }
+ if (permissions != null && permissions.contains(permission))
+ {
+ return true;
}
}
return false;
@@ -370,9 +417,12 @@ public class DynamicAccessControlListImp
* global Group.
*/
public boolean hasPermission(String permission) {
- try {
+ try
+ {
return permissionSet.containsName(permission);
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
return false;
}
}
Modified: turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/model/turbine/TurbineAccessControlListImpl.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/model/turbine/TurbineAccessControlListImpl.java?rev=1856202&r1=1856201&r2=1856202&view=diff
==============================================================================
--- turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/model/turbine/TurbineAccessControlListImpl.java (original)
+++ turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/model/turbine/TurbineAccessControlListImpl.java Mon Mar 25 14:29:46 2019
@@ -1,6 +1,5 @@
package org.apache.fulcrum.security.model.turbine;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -20,7 +19,6 @@ package org.apache.fulcrum.security.mode
* under the License.
*/
-
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@@ -48,8 +46,9 @@ import org.apache.fulcrum.security.util.
* @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
* @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
* @author <a href="mailto:marco@intermeta.de">Marco Knüttel</a>
- * @version $Id: TurbineAccessControlList.java 1096130 2011-04-23 10:37:19Z ludwig $
+ * @version $Id: TurbineAccessControlList.java 1096130 2019-03-25 10:37:19Z painter $
*/
+@SuppressWarnings("rawtypes")
public class TurbineAccessControlListImpl
implements TurbineAccessControlList
{
@@ -58,16 +57,22 @@ public class TurbineAccessControlListImp
/** The sets of roles that the user has in different groups */
private Map<Group, RoleSet> roleSets;
+
/** The sets of permissions that the user has in different groups */
private Map<Group, PermissionSet> permissionSets;
+
/** The global group */
private Group globalGroup;
+
/** The group manager */
private GroupManager groupManager;
+
/** The distinct list of groups that this user is part of */
private GroupSet groupSet = new GroupSet();
+
/** The distinct list of roles that this user is part of */
private RoleSet roleSet = new RoleSet();
+
/** the distinct list of permissions that this user has */
private PermissionSet permissionSet = new PermissionSet();
@@ -434,19 +439,18 @@ public class TurbineAccessControlListImp
{
return false;
}
+
if (permission == null)
{
return false;
}
+
for (Group group : groupset)
{
PermissionSet permissions = getPermissions(group);
- if (permissions != null)
+ if (permissions != null && permissions.contains(permission))
{
- if (permissions.contains(permission))
- {
- return true;
- }
+ return true;
}
}
return false;
Modified: turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/util/SecuritySet.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/util/SecuritySet.java?rev=1856202&r1=1856201&r2=1856202&view=diff
==============================================================================
--- turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/util/SecuritySet.java (original)
+++ turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/util/SecuritySet.java Mon Mar 25 14:29:46 2019
@@ -58,7 +58,8 @@ public abstract class SecuritySet<T exte
/**
* Constructs an empty Set
*/
- public SecuritySet() {
+ public SecuritySet()
+ {
nameMap = new TreeMap<String, T>(String.CASE_INSENSITIVE_ORDER);
idMap = new TreeMap<Object, T>();
}
@@ -69,7 +70,8 @@ public abstract class SecuritySet<T exte
* @return A Set Object
*
*/
- public Set<T> getSet() {
+ public Set<T> getSet()
+ {
return new HashSet<T>(idMap.values());
}
@@ -78,7 +80,8 @@ public abstract class SecuritySet<T exte
*
* @return The Set of Names in this Object, backed by the actual data.
*/
- public Set<String> getNames() {
+ public Set<String> getNames()
+ {
return nameMap.keySet();
}
@@ -87,7 +90,8 @@ public abstract class SecuritySet<T exte
*
* @return The Set of Ids in this Object, backed by the actual data.
*/
- public Set<Object> getIds() {
+ public Set<Object> getIds()
+ {
return idMap.keySet();
}
@@ -95,7 +99,8 @@ public abstract class SecuritySet<T exte
* Removes all Objects from this Set.
*/
@Override
- public void clear() {
+ public void clear()
+ {
nameMap.clear();
idMap.clear();
}
@@ -106,8 +111,9 @@ public abstract class SecuritySet<T exte
* @param name Name of the Security Object.
* @return True if argument matched an Object in this Set; false if no match.
*/
- public boolean containsName(String name) {
- return (StringUtils.isNotEmpty(name)) ? nameMap.containsKey(name) : false;
+ public boolean containsName(String name)
+ {
+ return StringUtils.isNotEmpty(name) ? nameMap.containsKey(name) : false;
}
/**
@@ -116,7 +122,8 @@ public abstract class SecuritySet<T exte
* @param id Id of the Security Object.
* @return True if argument matched an Object in this Set; false if no match.
*/
- public boolean containsId(Object id) {
+ public boolean containsId(Object id)
+ {
return (id == null) ? false : idMap.containsKey(id);
}
@@ -126,7 +133,8 @@ public abstract class SecuritySet<T exte
* @return An iterator for the Set
*/
@Override
- public Iterator<T> iterator() {
+ public Iterator<T> iterator()
+ {
return idMap.values().iterator();
}
@@ -136,7 +144,8 @@ public abstract class SecuritySet<T exte
* @return The cardinality of this Set.
*/
@Override
- public int size() {
+ public int size()
+ {
return idMap.size();
}
@@ -146,7 +155,8 @@ public abstract class SecuritySet<T exte
* @return The string representation of this Set.
*/
@Override
- public String toString() {
+ public String toString()
+ {
StringBuilder sbuf = new StringBuilder(12 * size());
for (Iterator<T> it = iterator(); it.hasNext();) {
@@ -169,15 +179,20 @@ public abstract class SecuritySet<T exte
* @see java.util.Collection#add(java.lang.Object)
*/
@Override
- public boolean add(T o) {
- if (contains(o)) {
+ public boolean add(T o)
+ {
+ if (contains(o))
+ {
return false;
}
- if (o.getId() != null) {
+ if (o.getId() != null)
+ {
idMap.put(o.getId(), o);
}
- if (o.getName() != null) {
+
+ if (o.getName() != null)
+ {
nameMap.put(o.getName(), o);
}
@@ -191,30 +206,35 @@ public abstract class SecuritySet<T exte
* @return True if this Set changed as a result; false if no change to this Set
* occurred (this Set already contained all members of the added Set).
*/
- public boolean add(Collection<? extends T> collection) {
+ public boolean add(Collection<? extends T> collection)
+ {
return addAll(collection);
}
@Override
- public boolean addAll(Collection<? extends T> collection) {
+ public boolean addAll(Collection<? extends T> collection)
+ {
boolean res = false;
- for (T o : collection) {
+ for (T o : collection)
res |= add(o);
- }
return res;
}
@Override
- public boolean isEmpty() {
+ public boolean isEmpty()
+ {
return idMap.isEmpty();
}
@Override
- public boolean containsAll(Collection<?> collection) {
- for (Object object : collection) {
- if (!contains(object)) {
+ public boolean containsAll(Collection<?> collection)
+ {
+ for (Object object : collection)
+ {
+ if (!contains(object))
+ {
return false;
}
}
@@ -222,11 +242,14 @@ public abstract class SecuritySet<T exte
}
@Override
- public boolean removeAll(Collection<?> collection) {
+ public boolean removeAll(Collection<?> collection)
+ {
boolean changed = false;
- for (Object object : collection) {
+ for (Object object : collection)
+ {
boolean result = remove(object);
- if (result) {
+ if (result)
+ {
changed = true;
}
}
@@ -235,7 +258,8 @@ public abstract class SecuritySet<T exte
}
@Override
- public boolean retainAll(Collection<?> collection) {
+ public boolean retainAll(Collection<?> collection)
+ {
throw new RuntimeException("not implemented");
}
@@ -245,7 +269,8 @@ public abstract class SecuritySet<T exte
* @see java.util.Collection#toArray()
*/
@Override
- public Object[] toArray() {
+ public Object[] toArray()
+ {
return getSet().toArray();
}
@@ -256,10 +281,14 @@ public abstract class SecuritySet<T exte
* @return True if this Set contains the entity, false otherwise.
*/
@Override
- public boolean contains(Object o) {
- if (o == null || !(o instanceof SecurityEntity)) {
+ public boolean contains(Object o)
+ {
+ if (o == null || !(o instanceof SecurityEntity))
+ {
return false;
- } else {
+ }
+ else
+ {
return containsId(((SecurityEntity) o).getId());
}
}
@@ -271,8 +300,10 @@ public abstract class SecuritySet<T exte
* @return True if this Set contained the entity before it was removed.
*/
@Override
- public boolean remove(Object o) {
- if (o instanceof SecurityEntity) {
+ public boolean remove(Object o)
+ {
+ if (o instanceof SecurityEntity)
+ {
boolean res = contains(o);
idMap.remove(((SecurityEntity) o).getId());
nameMap.remove(((SecurityEntity) o).getName());
@@ -286,7 +317,8 @@ public abstract class SecuritySet<T exte
* @see java.util.Set#toArray(java.lang.Object[])
*/
@Override
- public <A> A[] toArray(A[] a) {
+ public <A> A[] toArray(A[] a)
+ {
return getSet().toArray(a);
}
@@ -297,7 +329,8 @@ public abstract class SecuritySet<T exte
* @param name Name of entity.
* @return entity if argument matched an entity in this Set; null if no match.
*/
- public T getByName(String name) {
+ public T getByName(String name)
+ {
return nameMap.get(name);
}
@@ -307,7 +340,8 @@ public abstract class SecuritySet<T exte
* @param id ID of entity.
* @return entity if argument matched an entity in this Set; null if no match.
*/
- public T getById(Object id) {
+ public T getById(Object id)
+ {
return idMap.get(id);
}
}