List of usage examples for java.security Permission getActions
public abstract String getActions();
From source file:cn.vlabs.duckling.vwb.service.auth.policy.PolicyUtil.java
public static void remove(Acl policy, PolicyData pd) { Enumeration<AclEntry> entryEnum = policy.entries(); while (entryEnum.hasMoreElements()) { AclEntry entry = entryEnum.nextElement(); Principal principal = entry.getPrincipal(); String principalClass = principal.getClass().getName(); String principalName = principal.getName(); if (principalClass == null || principalName == null) continue; if (principalClass.equals(pd.getPrincipalClass()) && principalName.equals(pd.getPrincipalName())) { Enumeration<Permission> permissEnum = entry.permissions(); while (permissEnum.hasMoreElements()) { Permission permission = permissEnum.nextElement(); String permissionClass = permission.getClass().getName(); String permissionName = permission.getName(); String permissionActions = permission.getActions(); if (permissionClass == null || permissionName == null || permissionActions == null) continue; if (permissionClass.equals(pd.getPermissionClass()) && permissionName.equals(pd.getPermissionName()) && permissionActions.equals(pd.getPermissionActions())) { // AclEntry policyEntry = policy.getEntry(principal); policyEntry.removePermission(permission); }/*from ww w .j ava 2 s .c om*/ } } } }
From source file:cn.vlabs.duckling.vwb.service.auth.policy.PolicyUtil.java
private static String permiss2PolicyString(Permission permission) { StringBuffer sb = new StringBuffer(); sb.append("permission ").append(permission.getClass().getName()).append(" \""); if (permission instanceof UserPermission) { sb.append(((UserPermission) permission).getWiki()); } else if (permission instanceof VWBPermission) { sb.append("*"); } else if (permission instanceof PagePermission) { sb.append(((PagePermission) permission).getPage()); } else if (permission instanceof AllPermission) { sb.append("*"); } else {//from w w w. j a v a 2s .co m sb.append(permission.getName()); } sb.append("\""); String actions = permission.getActions(); if (actions != null) { sb.append(" \"").append(actions).append("\""); } sb.append(";\n\r"); return sb.toString(); }
From source file:cn.vlabs.duckling.vwb.service.auth.policy.PolicyUtil.java
public static List<PolicyData> acl2PolicyData(Acl acl) { List<PolicyData> pdl = new ArrayList<PolicyData>(); Enumeration<AclEntry> entryEnum = acl.entries(); while (entryEnum.hasMoreElements()) { AclEntry entry = entryEnum.nextElement(); Principal principal = entry.getPrincipal(); String principalClass = principal.getClass().getName(); String principalName = principal.getName(); String objectname = null; if (principalClass.equals("cn.vlabs.duckling.vwb.service.auth.Role") && principalName.equalsIgnoreCase("All")) { objectname = ""; }//from w w w . j a va2 s . c o m if (principalClass.equals("cn.vlabs.duckling.vwb.service.auth.GroupPrincipal")) { objectname = ""; } if (objectname == null) { continue; } Enumeration<Permission> permissEnum = entry.permissions(); while (permissEnum.hasMoreElements()) { Permission permission = permissEnum.nextElement(); String permissionClass = permission.getClass().getName(); String permissionType = null; if (permissionClass.equals("cn.vlabs.duckling.vwb.service.auth.permissions.PagePermission")) { permissionType = "?"; } if (permissionClass.equals("cn.vlabs.duckling.vwb.service.auth.permissions.VWBPermission")) { permissionType = ""; } if (permissionType == null) { continue; } String permissionActions = permission.getActions(); String operations = permissionActions; String permissionName = permission.getName(); String resource = null; if (permission instanceof UserPermission) { resource = ((UserPermission) permission).getWiki(); } else if (permission instanceof VWBPermission) { resource = "*"; } else if (permission instanceof PagePermission) { resource = ((PagePermission) permission).getPage(); } else if (permission instanceof AllPermission) { resource = "*"; } else { resource = permission.getName(); } PolicyData pd = new PolicyData(); pd.setId(pdl.size()); pd.setPrincipalClass(principalClass); pd.setPrincipalName(principalName); pd.setPermissionClass(permissionClass); pd.setPermissionActions(permissionActions); pd.setPermissionName(permissionName); pd.setPrincipal(objectname); pd.setPermission(permissionType); pd.setOperation(operations); pd.setResource(resource); pdl.add(pd); } } return pdl; }
From source file:cn.vlabs.duckling.vwb.service.auth.policy.PolicyUtil.java
public static PolicyData add(String voGroup, Acl policy, String principalAlias, String permissionAlias, String operation, String resource) { Principal principal = null;//from w w w .j av a2 s. c o m if (principalAlias.equals("All")) { principal = new Role("All"); principalAlias = ""; } else if (principalAlias.equals("VO")) { principal = new GroupPrincipal(voGroup); principalAlias = ""; } else { return null; } AclEntry policyEntry = policy.getEntry(principal); Permission permission = null; if (permissionAlias.equals("Page")) { permission = new PagePermission(resource, operation); permissionAlias = "?"; } else if (permissionAlias.equals("VWB")) { permission = new VWBPermission(resource, operation); permissionAlias = ""; } else { return null; } policyEntry.addPermission(permission); PolicyData pd = new PolicyData(); pd.setPrincipalClass(principal.getClass().getName()); pd.setPrincipalName(principal.getName()); pd.setPrincipal(principalAlias); pd.setPermissionClass(permission.getClass().getName()); pd.setPermissionName(permission.getName()); pd.setPermissionActions(permission.getActions()); pd.setPermission(permissionAlias); pd.setOperation(operation); pd.setResource(resource); return pd; }
From source file:com.ecyrd.jspwiki.content.Exporter.java
private void exportAcl(Acl acl) { if (acl != null) { ArrayList<String> propval = new ArrayList<String>(); for (Enumeration<AclEntry> ee = acl.entries(); ee.hasMoreElements();) { AclEntry ae = ee.nextElement(); StringBuilder sb = new StringBuilder(); sb.append("ALLOW \""); sb.append(ae.getPrincipal().getName()); sb.append("\" "); for (Enumeration<Permission> permissions = ae.permissions(); permissions.hasMoreElements();) { Permission perm = permissions.nextElement(); sb.append(perm.getActions()); sb.append(","); }/*from ww w .j ava 2 s. c o m*/ propval.add(sb.toString()); } exportProperty("wiki:acl", propval.toArray(new String[propval.size()]), STRING); } }
From source file:edu.ku.brc.af.auth.specify.permission.BasicSpPermission.java
/** * Checks if permission passed as parameter is implied by this permission */// ww w. ja v a 2 s . c o m public boolean implies(final Permission p) { // check implication of name according to BasicPermission rules if (!super.implies(p) || !(p instanceof BasicSpPermission)) { // short circuit and return false if p doesn't imply this return false; } // now check if p implies this according to both permissions actions String[] thisActions = actions.split(","); String[] pActions = p.getActions().split(","); for (String pAction : pActions) { boolean found = false; for (String action : thisActions) { if (action.equals(pAction)) { found = true; break; } } if (!found) return false; } return true; }
From source file:de.ingrid.usermanagement.jetspeed.IngridPermissionManager.java
/** * <p>//w w w .ja va 2 s . c om * Returns the {@link InternalPermission} from a Permission. * </p> * * @param permission The permission. * @return The {@link InternalPermission}. */ InternalPermission getInternalPermission(Permission permission) { Criteria filter = new Criteria(); filter.addEqualTo("classname", permission.getClass().getName()); filter.addEqualTo("name", permission.getName()); filter.addEqualTo("actions", permission.getActions()); Query query = QueryFactory.newQuery(InternalPermissionImpl.class, filter); InternalPermission internalPermission = (InternalPermission) broker.getObjectByQuery(query); return internalPermission; }
From source file:de.ingrid.usermanagement.jetspeed.IngridPermissionManager.java
/** * @see org.apache.jetspeed.security.PermissionManager#addPermission(java.security.Permission) *///from w w w .j av a 2 s .com public void addPermission(Permission permission) throws SecurityException { ArgUtil.notNull(new Object[] { permission }, new String[] { "permission" }, "addPermission(java.security.Permission)"); InternalPermission internalPermission = new InternalPermissionImpl(permission.getClass().getName(), permission.getName(), permission.getActions()); try { broker.beginTransaction(); broker.store(internalPermission); broker.commitTransaction(); } catch (Exception e) { KeyedMessage msg = SecurityException.UNEXPECTED.create("PermissionManager.addPermission", "store", e.getMessage()); log.error(msg, e); broker.abortTransaction(); throw new SecurityException(msg, e); } }
From source file:de.ingrid.usermanagement.jetspeed.IngridPermissionManager.java
/** * <p>/*from w w w .j a v a 2 s. 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:com.ecyrd.jspwiki.auth.SecurityVerifier.java
/** * Prints a <td> HTML element with the results of a permission test. * @param perm the permission to format//w ww.j a v a 2 s . c om * @param allowed whether the permission is allowed */ private final String printPermissionTest(Permission permission, Principal principal, int cols) { StringBuffer s = new StringBuffer(); if (permission == null) { s.append(" <td colspan=\"" + cols + "\" align=\"center\" title=\"N/A\">"); s.append(" </td>\n"); } else { boolean allowed = verifyStaticPermission(principal, permission); s.append(" <td colspan=\"" + cols + "\" align=\"center\" title=\""); s.append(allowed ? "ALLOW: " : "DENY: "); s.append(permission.getClass().getName()); s.append(" ""); s.append(permission.getName()); s.append("""); if (permission.getName() != null) { s.append(",""); s.append(permission.getActions()); s.append("""); } s.append(" "); s.append(principal.getClass().getName()); s.append(" ""); s.append(principal.getName()); s.append("""); s.append("\""); s.append(allowed ? BG_GREEN + ">" : BG_RED + ">"); s.append(" </td>\n"); } return s.toString(); }