List of usage examples for java.security Permission getName
public final String getName()
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/*ww w . ja 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(); }
From source file:org.jboss.dashboard.security.PermissionManager.java
/** * Find the permission descriptor for given principal and permission *//*from ww w. j a va 2 s. c om*/ public PermissionDescriptor find(final Principal prpal, final Permission perm) { final List<PermissionDescriptor> results = new ArrayList<PermissionDescriptor>(1); HibernateTxFragment txFragment = new HibernateTxFragment() { protected void txFragment(Session session) throws Exception { StringBuffer buf = new StringBuffer(); buf.append( " from " + PermissionDescriptor.class.getName() + " as item where item.dbid is not null "); if (prpal != null) { buf.append(" and item.principalClass = :principalClass "); buf.append(" and item.principalName = :principalName "); } buf.append( "and item.permissionClass = :permissionClass and item.permissionResource = :permissionResource"); Query query = session.createQuery(buf.toString()); if (prpal != null) { query.setString("principalClass", prpal.getClass().getName()); query.setString("principalName", prpal.getName()); } query.setString("permissionClass", perm.getClass().getName()); query.setString("permissionResource", perm.getName()); query.setCacheable(true); FlushMode oldFlushMode = session.getFlushMode(); session.setFlushMode(FlushMode.NEVER); results.addAll(query.list()); session.setFlushMode(oldFlushMode); } }; try { txFragment.execute(); if (!results.isEmpty()) return results.get(0); else return null; } catch (Exception e) { log.error("Error retrieving PermissionDescriptor", e); return null; } }
From source file:de.ingrid.usermanagement.jetspeed.IngridPermissionManager.java
/** * @see org.apache.jetspeed.security.PermissionManager#revokePermission(java.security.Principal, * java.security.Permission)/* ww w .ja v a2 s. c o m*/ */ public void revokePermission(Principal principal, Permission permission) throws SecurityException { String fullPath = SecurityHelper.getPreferencesFullPath(principal); ArgUtil.notNull(new Object[] { fullPath, permission }, new String[] { "fullPath", "permission" }, "revokePermission(java.security.Principal, java.security.Permission)"); // Remove permissions on principal. InternalPrincipal internalPrincipal = getInternalPrincipal(fullPath); if (null != internalPrincipal) { Collection internalPermissions = internalPrincipal.getPermissions(); if (null != internalPermissions) { boolean revokePermission = false; ArrayList newInternalPermissions = new ArrayList(); Iterator internalPermissionsIter = internalPermissions.iterator(); while (internalPermissionsIter.hasNext()) { InternalPermission internalPermission = (InternalPermission) internalPermissionsIter.next(); if (!((internalPermission.getClassname().equals(permission.getClass().getName())) && (internalPermission.getName().equals(permission.getName())) && (internalPermission.getActions().equals(permission.getActions())))) { newInternalPermissions.add(internalPermission); } else { revokePermission = true; } } if (revokePermission) { try { internalPrincipal.setModifiedDate(new Timestamp(System.currentTimeMillis())); internalPrincipal.setPermissions(newInternalPermissions); broker.beginTransaction(); broker.store(internalPrincipal); broker.commitTransaction(); } catch (Exception e) { KeyedMessage msg = SecurityException.UNEXPECTED.create("PermissionManager.revokePermission", "store", e.getMessage()); log.error(msg, e); broker.abortTransaction(); throw new SecurityException(msg, e); } } } } }
From source file:de.ingrid.usermanagement.jetspeed.IngridPermissionManager.java
/** * @see org.apache.jetspeed.security.PermissionManager#grantPermission(java.security.Principal, * java.security.Permission)// w w w . j a v a2 s .c o m */ public void grantPermission(Principal principal, Permission permission) throws SecurityException { String fullPath = SecurityHelper.getPreferencesFullPath(principal); ArgUtil.notNull(new Object[] { fullPath, permission }, new String[] { "fullPath", "permission" }, "grantPermission(java.security.Principal, java.security.Permission)"); Collection internalPermissions = new ArrayList(); InternalPrincipal internalPrincipal = getInternalPrincipal(fullPath); if (null == internalPrincipal) { if (principal instanceof UserPrincipal) { throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST.create(principal.getName())); } else if (principal instanceof RolePrincipal) { throw new SecurityException(SecurityException.ROLE_DOES_NOT_EXIST.create(principal.getName())); } // must/should be GroupPrincipal throw new SecurityException(SecurityException.GROUP_DOES_NOT_EXIST.create(principal.getName())); } InternalPermission internalPermission = getInternalPermission(permission); if (null == internalPermission) { throw new SecurityException(SecurityException.PERMISSION_DOES_NOT_EXIST.create(permission.getName())); } if (null != internalPrincipal.getPermissions()) { internalPermissions.addAll(internalPrincipal.getPermissions()); } if (!internalPermissions.contains(internalPermission)) { internalPermissions.add(internalPermission); } try { internalPrincipal.setModifiedDate(new Timestamp(System.currentTimeMillis())); internalPrincipal.setPermissions(internalPermissions); broker.beginTransaction(); broker.store(internalPrincipal); broker.commitTransaction(); } catch (Exception e) { KeyedMessage msg = SecurityException.UNEXPECTED.create("PermissionManager.grantPermission", "store", e.getMessage()); log.error(msg, e); broker.abortTransaction(); throw new SecurityException(msg, e); } }