List of usage examples for java.security Permissions elements
@Override
public Enumeration<Permission> elements()
From source file:de.ingrid.usermanagement.jetspeed.IngridPermissionManager.java
/** * <p>/* www . j a v a2s. c o m*/ * Iterate through a collection of {@link InternalPermission}and build a * unique collection of {@link java.security.Permission}. * </p> * * @param omPermissions The collection of {@link InternalPermission}. * @return The collection of {@link java.security.Permission}. */ private Permissions appendSecurityPermissions(Collection omPermissions, Permissions permissions) { Iterator internalPermissionsIter = omPermissions.iterator(); while (internalPermissionsIter.hasNext()) { InternalPermission internalPermission = (InternalPermission) internalPermissionsIter.next(); Permission permission = null; try { Class permissionClass = Class.forName(internalPermission.getClassname()); Class[] parameterTypes = { String.class, String.class }; Constructor permissionConstructor = permissionClass.getConstructor(parameterTypes); Object[] initArgs = { internalPermission.getName(), internalPermission.getActions() }; permission = (Permission) permissionConstructor.newInstance(initArgs); if (!Collections.list(permissions.elements()).contains(permission)) { if (log.isDebugEnabled()) { log.debug("Adding permimssion: [class, " + permission.getClass().getName() + "], " + "[name, " + permission.getName() + "], " + "[actions, " + permission.getActions() + "]"); } permissions.add(permission); } } catch (Exception e) { e.printStackTrace(); } } return permissions; }
From source file:org.jboss.dashboard.security.UIPolicy.java
public void removePermissions(Principal p, String resourceName) { Permissions prpalPermissions = (Permissions) permissionMap.get(p); if (prpalPermissions != null && resourceName != null) { // Search for permissions related with the specified resource. List toRemove = new ArrayList(); Enumeration en = prpalPermissions.elements(); DefaultPermission resPerm = new DefaultPermission(resourceName, null); DefaultPermission regPerm = new DefaultPermission(resourceName, null); while (en.hasMoreElements()) { Permission permission = (Permission) en.nextElement(); regPerm.setResourceName(permission.getName()); if (resPerm.implies(regPerm)) toRemove.add(permission); }/*from www .ja v a 2s . co m*/ // Remove permissions Iterator it = toRemove.iterator(); while (it.hasNext()) this.removePermission(p, (Permission) it.next()); } }
From source file:org.jboss.dashboard.security.UIPolicy.java
public synchronized void removePermission(Principal p, Permission perm) { // Update buffers PermissionDescriptor pd = PermissionManager.lookup().find(p, perm); if (pd != null && !pd.isReadonly()) { int pos = updateBuffer.indexOf(pd); if (pos != -1) updateBuffer.remove(pos);/*from www .j ava 2s . co m*/ pos = deleteBuffer.indexOf(pd); if (pos == -1) deleteBuffer.add(pd); // Remove the permission from memory if (log.isDebugEnabled()) log.debug("Removing permission " + perm + " for principal " + p); Permissions prpalPermissions = (Permissions) permissionMap.get(p); if (prpalPermissions != null) { Permissions newPermissions = new Permissions(); Enumeration en = prpalPermissions.elements(); while (en.hasMoreElements()) { Permission permission = (Permission) en.nextElement(); if (!perm.equals(permission)) newPermissions.add(permission); } permissionMap.put(p, newPermissions); } } }
From source file:org.jboss.dashboard.security.UIPolicy.java
public PermissionCollection getPermissions(Subject usr) { Permissions userPermissions = new Permissions(); Iterator it = usr.getPrincipals().iterator(); while (it.hasNext()) { Principal principal = (Principal) it.next(); Permissions permissions = (Permissions) permissionMap.get(principal); if (permissions != null) { Enumeration permEnum = permissions.elements(); while (permEnum.hasMoreElements()) { Permission perm = (Permission) permEnum.nextElement(); userPermissions.add(perm); }//from www . j a v a 2 s. co m } } // Also retrieve permission assigned to the unspecified principal Permissions permissions = (Permissions) permissionMap.get(UNSPECIFIED_PRINCIPAL); if (permissions != null) { Enumeration permEnum = permissions.elements(); while (permEnum.hasMoreElements()) { Permission perm = (Permission) permEnum.nextElement(); userPermissions.add(perm); } } return userPermissions; }
From source file:org.jboss.dashboard.security.UIPolicy.java
public Map getPermissions(Object resource, Class permClass) throws Exception { final Map results = new HashMap(); Method getResName = permClass.getMethod("getResourceName", new Class[] { Object.class }); String resourceName = (String) getResName.invoke(permClass, new Object[] { resource }); for (Iterator it = permissionMap.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); Permissions perms = (Permissions) entry.getValue(); for (Enumeration en = perms.elements(); en.hasMoreElements();) { Permission perm = (Permission) en.nextElement(); if (perm.getName().equals(resourceName) && permClass.equals(perm.getClass())) { results.put(entry.getKey(), perm); }/*from w ww . j av a 2s. c o m*/ } } return results; }