Java Code Examples for javax.security.jacc.PolicyConfiguration#addToRole()

The following examples show how to use javax.security.jacc.PolicyConfiguration#addToRole() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AuthorizationPreInitializer.java    From piranha with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void setPermissions(ServletContext servletContext, AuthorizationService authorizationService) throws ServletException {
    // Add permissions to the policy configuration, which is the repository that the policy (authorization module)
    // uses
    PolicyConfiguration policyConfiguration = authorizationService.getPolicyConfiguration();

    try {
        List<Permission> unchecked = getOptionalAttribute(servletContext, UNCHECKED_PERMISSIONS);
        if (unchecked != null) {
            for (Permission permission : unchecked) {
                policyConfiguration.addToUncheckedPolicy(permission);
            }
        }

        List<Entry<String, Permission>> perRole = getOptionalAttribute(servletContext, PERROLE_PERMISSIONS);
        if (perRole != null) {
            for (Entry<String, Permission> perRoleEntry : perRole) {
                policyConfiguration.addToRole(perRoleEntry.getKey(), perRoleEntry.getValue());
            }
        }

        // TODO: Move commit moment to after all ServletContainerInitializer, Filters and Servlets have initialized
        policyConfiguration.commit();
    } catch (PolicyContextException e) {
        throw new IllegalStateException(e);
    }
}
 
Example 2
Source File: AuthorizationPreInitializer.java    From piranha with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void addToRole(PolicyConfiguration policyConfiguration, String role, Permission permission) {
    try {
        policyConfiguration.addToRole(role, permission);
    } catch (PolicyContextException e) {
        throw new IllegalStateException(e);
    }
}