Example usage for java.security Permissions add

List of usage examples for java.security Permissions add

Introduction

In this page you can find the example usage for java.security Permissions add.

Prototype

@Override
public void add(Permission permission) 

Source Link

Document

Adds a permission object to the PermissionCollection for the class the permission belongs to.

Usage

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   w  w  w.jav  a2 s.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 w w w  .j ava  2  s .  c o  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.jwebsocket.plugins.scripting.Settings.java

/**
 * Gets application security permissions.
 *
 * @param aAppName/*from www.ja  v  a 2 s.c  om*/
 * @param aAppPath
 * @return
 */
public Permissions getAppPermissions(String aAppName, String aAppPath) {
    if (mCachedAppPermissions.containsKey(aAppName)) {
        return mCachedAppPermissions.get(aAppName);
    }

    Permissions lPerms = new Permissions();
    Permission lPermission;

    // processing global permissions
    for (String lStrPerm : getGlobalSecurityPermissions()) {
        lPermission = Tools.stringToPermission(JWebSocketConfig.expandEnvVarsAndProps(
                lStrPerm.replace("${APP_HOME}", aAppPath).replace("${EXT}", mExtensionsDirectoryPath)));

        if (null != lPermission) {
            lPerms.add(lPermission);
        }
    }

    // processing app permissions
    if (getAppsSecurityPermissions().containsKey(aAppName)) {
        for (String lStrPerm : getAppsSecurityPermissions().get(aAppName)) {
            lPermission = Tools.stringToPermission(JWebSocketConfig.expandEnvVarsAndProps(
                    lStrPerm.replace("${APP_HOME}", aAppPath).replace("${EXT}", mExtensionsDirectoryPath)));

            if (null != lPermission) {
                lPerms.add(lPermission);
            }
        }
    }

    mCachedAppPermissions.put(aAppName, lPerms);
    return lPerms;
}