Search in sources :

Example 21 with Role

use of org.glassfish.security.common.Role in project Payara by payara.

the class AppSecurityRole method check.

/**
 * The Application role-name element contains the name of a security role.
 *
 * @param descriptor the Application deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(Application descriptor) {
    Result result = getInitializedResult();
    if (!descriptor.getRoles().isEmpty()) {
        boolean oneFailed = false;
        boolean foundIt = false;
        // get the security role name's in this app
        Set sc = descriptor.getRoles();
        Iterator itr = sc.iterator();
        while (itr.hasNext()) {
            foundIt = false;
            Role role = (Role) itr.next();
            String roleName = role.getName();
            if (roleName.length() > 0) {
                foundIt = true;
            } else {
                foundIt = false;
            }
            if (foundIt) {
                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "The security role name [ {0} ] found within application [ {1} ]", new Object[] { roleName, descriptor.getName() }));
            } else {
                if (!oneFailed) {
                    oneFailed = true;
                }
                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: The security role name [ {0} ] not found within application [ {1} ]", new Object[] { roleName, descriptor.getName() }));
            }
        }
        if (oneFailed) {
            result.setStatus(Result.FAILED);
        } else {
            result.setStatus(Result.PASSED);
        }
    } else {
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no role-name elements within the application [ {0} ]", new Object[] { descriptor.getName() }));
    }
    return result;
}
Also used : Role(org.glassfish.security.common.Role)

Example 22 with Role

use of org.glassfish.security.common.Role in project Payara by payara.

the class MapValue method removePolicyStatements.

/**
 * Remove All Policy Statements from Configuration config must be in open state when this method is called
 *
 * @param pc
 * @param wbd
 * @throws javax.security.jacc.PolicyContextException
 */
public static void removePolicyStatements(PolicyConfiguration pc, WebBundleDescriptor wbd) throws javax.security.jacc.PolicyContextException {
    pc.removeUncheckedPolicy();
    pc.removeExcludedPolicy();
    // iteration done for old providers
    Set<Role> roleSet = wbd.getRoles();
    for (Role r : roleSet) {
        pc.removeRole(r.getName());
    }
    // 1st call will remove "*" role if present. 2nd will remove all roles (if supported).
    pc.removeRole("*");
    pc.removeRole("*");
}
Also used : Role(org.glassfish.security.common.Role)

Example 23 with Role

use of org.glassfish.security.common.Role in project Payara by payara.

the class DeclareRolesHandler method processAnnotation.

protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
    DeclareRoles rolesRefAn = (DeclareRoles) ainfo.getAnnotation();
    for (EjbContext ejbContext : ejbContexts) {
        EjbDescriptor ejbDescriptor = ejbContext.getDescriptor();
        for (String roleName : rolesRefAn.value()) {
            if (ejbDescriptor.getRoleReferenceByName(roleName) == null) {
                RoleReference roleRef = new RoleReference(roleName, "");
                roleRef.setRolename(roleName);
                roleRef.setSecurityRoleLink(new SecurityRoleDescriptor(roleName, ""));
                ejbDescriptor.addRoleReference(roleRef);
            }
            Role role = new Role(roleName);
            ejbDescriptor.getEjbBundleDescriptor().addRole(role);
        }
    }
    return getDefaultProcessedResult();
}
Also used : Role(org.glassfish.security.common.Role) EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext) DeclareRoles(javax.annotation.security.DeclareRoles)

Example 24 with Role

use of org.glassfish.security.common.Role in project Payara by payara.

the class RunAsHandler method processAnnotation.

protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
    RunAs runAsAn = (RunAs) ainfo.getAnnotation();
    for (EjbContext ejbContext : ejbContexts) {
        EjbDescriptor ejbDesc = ejbContext.getDescriptor();
        // override by xml
        if (ejbDesc.getUsesCallerIdentity() != null) {
            continue;
        }
        String roleName = runAsAn.value();
        Role role = new Role(roleName);
        // add Role if not exists
        ejbDesc.getEjbBundleDescriptor().addRole(role);
        RunAsIdentityDescriptor runAsDesc = new RunAsIdentityDescriptor();
        runAsDesc.setRoleName(roleName);
        ejbDesc.setUsesCallerIdentity(false);
        if (ejbDesc.getRunAsIdentity() == null) {
            ejbDesc.setRunAsIdentity(runAsDesc);
        }
    }
    return getDefaultProcessedResult();
}
Also used : Role(org.glassfish.security.common.Role) RunAsIdentityDescriptor(com.sun.enterprise.deployment.RunAsIdentityDescriptor) EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext) RunAs(javax.annotation.security.RunAs) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor)

Example 25 with Role

use of org.glassfish.security.common.Role in project Payara by payara.

the class WebBundleDescriptorImpl method getSecurityRoles.

/**
 * Returns an Enumeration of my SecurityRole objects.
 * @return
 */
@Override
public Enumeration<SecurityRoleDescriptor> getSecurityRoles() {
    Vector<SecurityRoleDescriptor> securityRoles = new Vector<SecurityRoleDescriptor>();
    for (Role r : super.getRoles()) {
        SecurityRoleDescriptor srd = new SecurityRoleDescriptor(r);
        securityRoles.add(srd);
    }
    return securityRoles.elements();
}
Also used : SecurityRole(com.sun.enterprise.deployment.web.SecurityRole) Role(org.glassfish.security.common.Role) SecurityRoleDescriptor(com.sun.enterprise.deployment.SecurityRoleDescriptor) Vector(java.util.Vector)

Aggregations

Role (org.glassfish.security.common.Role)38 RunAsIdentityDescriptor (com.sun.enterprise.deployment.RunAsIdentityDescriptor)7 Iterator (java.util.Iterator)5 DeclareRoles (javax.annotation.security.DeclareRoles)5 RunAs (javax.annotation.security.RunAs)5 Group (org.glassfish.security.common.Group)5 MethodPermission (com.sun.enterprise.deployment.MethodPermission)4 RoleReference (com.sun.enterprise.deployment.RoleReference)4 WebComponentDescriptor (com.sun.enterprise.deployment.WebComponentDescriptor)4 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)4 Result (com.sun.enterprise.tools.verifier.Result)4 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)4 SecurityRoleMapper (org.glassfish.deployment.common.SecurityRoleMapper)4 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)3 PrincipalNameDescriptor (com.sun.enterprise.deployment.runtime.common.PrincipalNameDescriptor)3 SecurityRoleMapping (com.sun.enterprise.deployment.runtime.common.SecurityRoleMapping)3 SecurityConstraint (com.sun.enterprise.deployment.web.SecurityConstraint)3 SecurityRole (com.sun.enterprise.deployment.web.SecurityRole)3 UserDataConstraint (com.sun.enterprise.deployment.web.UserDataConstraint)3 Set (java.util.Set)3