Search in sources :

Example 1 with SunWebApp

use of com.sun.enterprise.deployment.runtime.web.SunWebApp in project Payara by payara.

the class WebSecurityManager method initialise.

private void initialise(String appName) throws PolicyContextException {
    getPolicyFactory();
    CODEBASE = removeSpaces(CONTEXT_ID);
    // V3:Commented if(VirtualServer.ADMIN_VS.equals(getVirtualServers(appName))){
    if (Constants.ADMIN_VS.equals(getVirtualServers(appName))) {
        LoginConfiguration lgConf = wbd.getLoginConfiguration();
        if (lgConf != null) {
            String realmName = lgConf.getRealmName();
            SunWebApp sunDes = wbd.getSunDescriptor();
            if (sunDes != null) {
                SecurityRoleMapping[] srms = sunDes.getSecurityRoleMapping();
                if (srms != null) {
                    for (SecurityRoleMapping srm : srms) {
                        String[] principals = srm.getPrincipalName();
                        if (principals != null) {
                            for (String principal : principals) {
                                wsmf.ADMIN_PRINCIPAL.put(realmName + principal, new PrincipalImpl(principal));
                            }
                        }
                        for (String group : srm.getGroupNames()) {
                            wsmf.ADMIN_GROUP.put(realmName + group, new Group(group));
                        }
                    }
                }
                SecurityRoleAssignment[] sras = sunDes.getSecurityRoleAssignments();
                if (sras != null) {
                    for (SecurityRoleAssignment sra : sras) {
                        List<String> principals = sra.getPrincipalNames();
                        if (sra.isExternallyDefined()) {
                            wsmf.ADMIN_GROUP.put(realmName + sra.getRoleName(), new Group(sra.getRoleName()));
                            continue;
                        }
                        for (String principal : principals) {
                            wsmf.ADMIN_PRINCIPAL.put(realmName + principal, new PrincipalImpl(principal));
                        }
                    }
                }
            }
        }
    }
    // will require stuff in hash format for reference later on.
    try {
        java.net.URI uri = null;
        try {
            if (logger.isLoggable(Level.FINE))
                logger.log(Level.FINE, "[Web-Security] Creating a Codebase URI with = {0}", CODEBASE);
            uri = new java.net.URI("file:///" + CODEBASE);
            if (uri != null) {
                codesource = new CodeSource(new URL(uri.toString()), (java.security.cert.Certificate[]) null);
            }
        } catch (java.net.URISyntaxException use) {
            // manually create the URL
            logger.log(Level.FINE, "[Web-Security] Error Creating URI ", use);
            throw new RuntimeException(use);
        }
    } catch (java.net.MalformedURLException mue) {
        logger.log(Level.SEVERE, "[Web-Security] Exception while getting the CodeSource", mue);
        throw new RuntimeException(mue);
    }
    if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, "[Web-Security] Context id (id under which  WEB component in application will be created) = {0}", CONTEXT_ID);
        logger.log(Level.FINE, "[Web-Security] Codebase (module id for web component) {0}", CODEBASE);
    }
    loadPolicyConfiguration();
    if (uncheckedPermissionCache == null) {
        if (register) {
            uncheckedPermissionCache = PermissionCacheFactory.createPermissionCache(this.CONTEXT_ID, codesource, protoPerms, null);
            allResourcesCP = new CachedPermissionImpl(uncheckedPermissionCache, allResources);
            allConnectionsCP = new CachedPermissionImpl(uncheckedPermissionCache, allConnections);
        }
    } else {
        uncheckedPermissionCache.reset();
    }
}
Also used : SunWebApp(com.sun.enterprise.deployment.runtime.web.SunWebApp) Group(org.glassfish.security.common.Group) SecurityRoleMapping(com.sun.enterprise.deployment.runtime.common.SecurityRoleMapping) LoginConfiguration(com.sun.enterprise.deployment.web.LoginConfiguration) URL(java.net.URL) CachedPermissionImpl(com.sun.enterprise.security.ee.CachedPermissionImpl) PrincipalImpl(org.glassfish.security.common.PrincipalImpl) SecurityRoleAssignment(com.sun.enterprise.deployment.runtime.common.wls.SecurityRoleAssignment)

Example 2 with SunWebApp

use of com.sun.enterprise.deployment.runtime.web.SunWebApp in project Payara by payara.

the class WebModuleListener method startCacheManager.

private void startCacheManager(WebModule webModule) {
    SunWebApp bean = webModule.getIasWebAppConfigBean();
    // Configure the cache, cache-mapping and other settings
    if (bean != null) {
        CacheManager cm = null;
        try {
            cm = CacheModule.configureResponseCache(webModule, bean);
        } catch (Exception ee) {
            _logger.log(Level.WARNING, LogFacade.CACHE_MRG_EXCEPTION, ee);
        }
        if (cm != null) {
            try {
                // first start the CacheManager, if enabled
                cm.start();
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, LogFacade.CACHE_MANAGER_STARTED);
                }
                // set this manager as a context attribute so that
                // caching filters/tags can find it
                ServletContext ctxt = webModule.getServletContext();
                ctxt.setAttribute(CacheManager.CACHE_MANAGER_ATTR_NAME, cm);
            } catch (LifecycleException ee) {
                _logger.log(Level.WARNING, ee.getMessage(), ee.getCause());
            }
        }
    }
}
Also used : SunWebApp(com.sun.enterprise.deployment.runtime.web.SunWebApp) CacheManager(com.sun.appserv.web.cache.CacheManager) ServletContext(javax.servlet.ServletContext) NamingException(javax.naming.NamingException)

Aggregations

SunWebApp (com.sun.enterprise.deployment.runtime.web.SunWebApp)2 CacheManager (com.sun.appserv.web.cache.CacheManager)1 SecurityRoleMapping (com.sun.enterprise.deployment.runtime.common.SecurityRoleMapping)1 SecurityRoleAssignment (com.sun.enterprise.deployment.runtime.common.wls.SecurityRoleAssignment)1 LoginConfiguration (com.sun.enterprise.deployment.web.LoginConfiguration)1 CachedPermissionImpl (com.sun.enterprise.security.ee.CachedPermissionImpl)1 URL (java.net.URL)1 NamingException (javax.naming.NamingException)1 ServletContext (javax.servlet.ServletContext)1 Group (org.glassfish.security.common.Group)1 PrincipalImpl (org.glassfish.security.common.PrincipalImpl)1