[jboss-cvs] jboss-seam/src/main/org/jboss/seam/security/acl ...
Shane Bryzak
Shane_Bryzak at symantec.com
Sat Dec 16 02:44:21 EST 2006
User: sbryzak2
Date: 06/12/16 02:44:21
Modified: src/main/org/jboss/seam/security/acl AclProvider.java
Removed: src/main/org/jboss/seam/security/acl
AbstractAclProvider.java PersistentAclProvider.java
Log:
consolidate the acl provider stuff into a single Seam component
Revision Changes Path
1.4 +91 -3 jboss-seam/src/main/org/jboss/seam/security/acl/AclProvider.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: AclProvider.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/security/acl/AclProvider.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- AclProvider.java 8 Nov 2006 23:28:38 -0000 1.3
+++ AclProvider.java 16 Dec 2006 07:44:21 -0000 1.4
@@ -2,13 +2,24 @@
import java.security.Principal;
import java.security.acl.Acl;
+import java.security.acl.AclEntry;
+import java.security.acl.NotOwnerException;
+import java.security.acl.Permission;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+//import org.jboss.seam.annotations.Name;
+import org.jboss.seam.security.Identity;
/**
* Provides a list of Acls for an object.
*
* @author Shane Bryzak
*/
-public interface AclProvider
+//@Name("org.jboss.seam.security.aclProvider")
+public abstract class AclProvider
{
public enum RecipientType {role, user};
@@ -18,7 +29,10 @@
* @param value Object
* @return Acl
*/
- Acl getAcls(Object value);
+ public Acl getAcls(Object obj)
+ {
+ return internalGetAcls(obj, null);
+ }
/**
* Return all Acls for the specified object that apply to the specified Principal.
@@ -27,5 +41,79 @@
* @param principal Principal
* @return Acl
*/
- Acl getAcls(Object value, Principal principal);
+ public Acl getAcls(Object obj, Principal principal)
+ {
+ if (principal == null)
+ throw new IllegalArgumentException("Principal cannot be null");
+
+ return internalGetAcls(obj, principal);
+ }
+
+ protected Acl internalGetAcls(Object obj, Principal principal)
+ {
+ Principal owner = Identity.instance();
+
+ Acl acl = new AclImpl(owner);
+
+ AclEntry entry = new AclEntryImpl();
+
+ if (principal != null)
+ {
+ entry.setPrincipal(principal);
+
+ for (Permission p : getPermissions(obj, principal))
+ {
+ entry.addPermission(p);
+ }
+ }
+
+ try
+ {
+ acl.addEntry(owner, entry);
+ }
+ catch (NotOwnerException ex) { } // caller is owner
+
+ return acl;
+ }
+
+
+ protected Set<Permission> convertToPermissions(Principal principal, Object target, Object perms)
+ {
+ if (perms == null)
+ return null;
+
+ //SeamSecurityManager.instance().get
+
+ if (List.class.isAssignableFrom(perms.getClass()))
+ {
+ Set<Permission> permissions = new HashSet<Permission>();
+
+ for (Object o : (List) perms)
+ {
+ if (o instanceof Object[])
+ {
+ Object[] values = (Object[]) o;
+ int mask = (Integer) values[0];
+ String recipient = (String) values[1];
+ RecipientType recipientType = (RecipientType) values[2];
+
+// DefinePermissions def = target.getClass().getAnnotation(DefinePermissions.class);
+// for (org.jboss.seam.annotations.security.AclProvider provider : def.permissions())
+// {
+// if ((provider.mask() & mask) > 0)
+ /** todo - use the correct name to create the permission */
+// permissions.add(new SeamPermission("permissionName", provider.action()));
+// }
+ }
+ }
+
+ return permissions;
+ }
+ else
+ throw new IllegalArgumentException(String.format(
+ "Permissions [%s] must be an instance of java.util.List", perms));
+ }
+
+ protected abstract Set<Permission> getPermissions(Object obj, Principal principal);
+ protected abstract Map<Principal,Set<Permission>> getPermissions(Object obj);
}
More information about the jboss-cvs-commits
mailing list