Search in sources :

Example 6 with Role

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

the class EjbBundleRuntimeNode method addDescriptor.

@Override
public void addDescriptor(Object newDescriptor) {
    if (newDescriptor instanceof SecurityRoleMapping) {
        SecurityRoleMapping roleMap = (SecurityRoleMapping) newDescriptor;
        descriptor.addSecurityRoleMapping(roleMap);
        Application app = descriptor.getApplication();
        if (app != null) {
            Role role = new Role(roleMap.getRoleName());
            SecurityRoleMapper rm = app.getRoleMapper();
            if (rm != null) {
                List<PrincipalNameDescriptor> principals = roleMap.getPrincipalNames();
                for (int i = 0; i < principals.size(); i++) {
                    rm.assignRole(principals.get(i).getPrincipal(), role, descriptor);
                }
                List<String> groups = roleMap.getGroupNames();
                for (int i = 0; i < groups.size(); i++) {
                    rm.assignRole(new Group(groups.get(i)), role, descriptor);
                }
            }
        }
    } else if (newDescriptor instanceof ResourcePropertyDescriptor) {
        ResourcePropertyDescriptor desc = (ResourcePropertyDescriptor) newDescriptor;
        if ("default-role-mapping".equals(desc.getName())) {
            descriptor.setDefaultGroupPrincipalMapping(ConfigBeansUtilities.toBoolean(desc.getValue()));
        }
    }
}
Also used : Role(org.glassfish.security.common.Role) Group(org.glassfish.security.common.Group) SecurityRoleMapping(com.sun.enterprise.deployment.runtime.common.SecurityRoleMapping) SecurityRoleMapper(org.glassfish.deployment.common.SecurityRoleMapper) ResourcePropertyDescriptor(com.sun.enterprise.deployment.ResourcePropertyDescriptor) PrincipalNameDescriptor(com.sun.enterprise.deployment.runtime.common.PrincipalNameDescriptor) Application(com.sun.enterprise.deployment.Application)

Example 7 with Role

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

the class DynamicWebServletRegistrationImpl method setSecurityConfig.

public void setSecurityConfig(SecurityConfig config) {
    if (config == null) {
        return;
    }
    this.config = config;
    LoginConfig lc = config.getLoginConfig();
    if (lc != null) {
        LoginConfiguration loginConf = new LoginConfigurationImpl();
        loginConf.setAuthenticationMethod(lc.getAuthMethod().name());
        loginConf.setRealmName(lc.getRealmName());
        FormLoginConfig form = lc.getFormLoginConfig();
        if (form != null) {
            loginConf.setFormErrorPage(form.getFormErrorPage());
            loginConf.setFormLoginPage(form.getFormLoginPage());
        }
        LoginConfigDecorator decorator = new LoginConfigDecorator(loginConf);
        setLoginConfig(decorator);
        getWebBundleDescriptor().setLoginConfiguration(loginConf);
    }
    Set<org.glassfish.embeddable.web.config.SecurityConstraint> securityConstraints = config.getSecurityConstraints();
    for (org.glassfish.embeddable.web.config.SecurityConstraint sc : securityConstraints) {
        com.sun.enterprise.deployment.web.SecurityConstraint securityConstraint = new SecurityConstraintImpl();
        Set<org.glassfish.embeddable.web.config.WebResourceCollection> wrcs = sc.getWebResourceCollection();
        for (org.glassfish.embeddable.web.config.WebResourceCollection wrc : wrcs) {
            WebResourceCollectionImpl webResourceColl = new WebResourceCollectionImpl();
            webResourceColl.setDisplayName(wrc.getName());
            for (String urlPattern : wrc.getUrlPatterns()) {
                webResourceColl.addUrlPattern(urlPattern);
            }
            securityConstraint.addWebResourceCollection(webResourceColl);
            AuthorizationConstraintImpl ac = null;
            if (sc.getAuthConstraint() != null && sc.getAuthConstraint().length > 0) {
                ac = new AuthorizationConstraintImpl();
                for (String roleName : sc.getAuthConstraint()) {
                    Role role = new Role(roleName);
                    getWebBundleDescriptor().addRole(role);
                    ac.addSecurityRole(roleName);
                }
            } else {
                // DENY
                ac = new AuthorizationConstraintImpl();
            }
            securityConstraint.setAuthorizationConstraint(ac);
            UserDataConstraint udc = new UserDataConstraintImpl();
            udc.setTransportGuarantee(((sc.getDataConstraint() == TransportGuarantee.CONFIDENTIAL) ? UserDataConstraint.CONFIDENTIAL_TRANSPORT : UserDataConstraint.NONE_TRANSPORT));
            securityConstraint.setUserDataConstraint(udc);
            if (wrc.getHttpMethods() != null) {
                for (String httpMethod : wrc.getHttpMethods()) {
                    webResourceColl.addHttpMethod(httpMethod);
                }
            }
            if (wrc.getHttpMethodOmissions() != null) {
                for (String httpMethod : wrc.getHttpMethodOmissions()) {
                    webResourceColl.addHttpMethodOmission(httpMethod);
                }
            }
            getWebBundleDescriptor().addSecurityConstraint(securityConstraint);
            TomcatDeploymentConfig.configureSecurityConstraint(this, getWebBundleDescriptor());
        }
    }
    if (pipeline != null) {
        GlassFishValve basic = pipeline.getBasic();
        if ((basic != null) && (basic instanceof java.net.Authenticator)) {
            removeValve(basic);
        }
        GlassFishValve[] valves = pipeline.getValves();
        for (int i = 0; i < valves.length; i++) {
            if (valves[i] instanceof java.net.Authenticator) {
                removeValve(valves[i]);
            }
        }
    }
    if (realm != null && realm instanceof RealmInitializer) {
        ((RealmInitializer) realm).initializeRealm(this.getWebBundleDescriptor(), false, ((VirtualServer) parent).getAuthRealmName());
        ((RealmInitializer) realm).setVirtualServer(getParent());
        ((RealmInitializer) realm).updateWebSecurityManager();
        setRealm(realm);
    }
}
Also used : WebResourceCollection(com.sun.enterprise.deployment.web.WebResourceCollection) RealmInitializer(com.sun.enterprise.security.integration.RealmInitializer) AuthorizationConstraintImpl(org.glassfish.web.deployment.descriptor.AuthorizationConstraintImpl) SecurityConstraint(com.sun.enterprise.deployment.web.SecurityConstraint) LoginConfigurationImpl(org.glassfish.web.deployment.descriptor.LoginConfigurationImpl) FormLoginConfig(org.glassfish.embeddable.web.config.FormLoginConfig) LoginConfig(org.glassfish.embeddable.web.config.LoginConfig) SecurityConstraintImpl(org.glassfish.web.deployment.descriptor.SecurityConstraintImpl) UserDataConstraint(com.sun.enterprise.deployment.web.UserDataConstraint) FormLoginConfig(org.glassfish.embeddable.web.config.FormLoginConfig) UserDataConstraintImpl(org.glassfish.web.deployment.descriptor.UserDataConstraintImpl) LoginConfiguration(com.sun.enterprise.deployment.web.LoginConfiguration) SecurityConstraint(com.sun.enterprise.deployment.web.SecurityConstraint) UserDataConstraint(com.sun.enterprise.deployment.web.UserDataConstraint) SecurityConstraint(com.sun.enterprise.deployment.web.SecurityConstraint) WebServiceEndpoint(com.sun.enterprise.deployment.WebServiceEndpoint) GlassFishValve(org.glassfish.web.valve.GlassFishValve) Role(org.glassfish.security.common.Role) LoginConfigDecorator(com.sun.enterprise.web.deploy.LoginConfigDecorator) WebResourceCollectionImpl(org.glassfish.web.deployment.descriptor.WebResourceCollectionImpl)

Example 8 with Role

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

the class DynamicWebServletRegistrationImpl method processServletAnnotations.

private void processServletAnnotations(Class<? extends Servlet> clazz, WebBundleDescriptor webBundleDescriptor, WebComponentDescriptor wcd, StandardWrapper wrapper) {
    // Process DeclareRoles annotation
    if (clazz.isAnnotationPresent(DeclareRoles.class)) {
        DeclareRoles declareRoles = (DeclareRoles) clazz.getAnnotation(DeclareRoles.class);
        for (String roleName : declareRoles.value()) {
            webBundleDescriptor.addRole(new Role(roleName));
            webModule.declareRoles(roleName);
        }
    }
    // Process MultipartConfig annotation
    if (clazz.isAnnotationPresent(MultipartConfig.class)) {
        MultipartConfig mpConfig = (MultipartConfig) clazz.getAnnotation(MultipartConfig.class);
        wrapper.setMultipartLocation(mpConfig.location());
        wrapper.setMultipartMaxFileSize(mpConfig.maxFileSize());
        wrapper.setMultipartMaxRequestSize(mpConfig.maxRequestSize());
        wrapper.setMultipartFileSizeThreshold(mpConfig.fileSizeThreshold());
    }
}
Also used : Role(org.glassfish.security.common.Role) MultipartConfig(javax.servlet.annotation.MultipartConfig) DeclareRoles(javax.annotation.security.DeclareRoles)

Example 9 with Role

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

the class DynamicWebServletRegistrationImpl method declareRoles.

@Override
public void declareRoles(String... roleNames) {
    super.declareRoles(roleNames);
    WebBundleDescriptor bundleDescriptor = getWebBundleDescriptor();
    for (String roleName : roleNames) {
        bundleDescriptor.addRole(new Role(roleName));
    }
    bundleDescriptor.setPolicyModified(true);
}
Also used : Role(org.glassfish.security.common.Role) WebBundleDescriptor(com.sun.enterprise.deployment.WebBundleDescriptor)

Example 10 with Role

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

the class DynamicWebServletRegistrationImpl method postProcessAnnotations.

void postProcessAnnotations() {
    Class<? extends Servlet> clazz = wrapper.getServletClass();
    if (clazz == null) {
        return;
    }
    // Process RunAs
    if (wcd.getRunAsIdentity() == null) {
        String roleName = runAsRoleName;
        if (roleName == null && clazz.isAnnotationPresent(RunAs.class)) {
            RunAs runAs = (RunAs) clazz.getAnnotation(RunAs.class);
            roleName = runAs.value();
        }
        if (roleName != null) {
            super.setRunAsRole(roleName);
            wbd.addRole(new Role(roleName));
            RunAsIdentityDescriptor runAsDesc = new RunAsIdentityDescriptor();
            runAsDesc.setRoleName(roleName);
            wcd.setRunAsIdentity(runAsDesc);
        }
    }
    // Process ServletSecurity
    ServletSecurityElement ssElement = servletSecurityElement;
    if (servletSecurityElement == null && clazz.isAnnotationPresent(ServletSecurity.class)) {
        ServletSecurity servletSecurity = (ServletSecurity) clazz.getAnnotation(ServletSecurity.class);
        ssElement = new ServletSecurityElement(servletSecurity);
    }
    if (ssElement != null) {
        webModule.processServletSecurityElement(ssElement, wbd, wcd);
    }
}
Also used : Role(org.glassfish.security.common.Role) RunAsIdentityDescriptor(com.sun.enterprise.deployment.RunAsIdentityDescriptor) ServletSecurity(javax.servlet.annotation.ServletSecurity) RunAs(javax.annotation.security.RunAs) ServletSecurityElement(javax.servlet.ServletSecurityElement)

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