Search in sources :

Example 1 with PolicyConfiguration

use of javax.security.jacc.PolicyConfiguration in project wildfly by wildfly.

the class JaccService method start.

/** {@inheritDoc} */
@Override
public void start(StartContext context) throws StartException {
    try {
        PolicyConfigurationFactory pcf = getPolicyConfigurationFactory();
        synchronized (pcf) {
            // synchronize on the factory
            policyConfiguration = pcf.getPolicyConfiguration(contextId, false);
            if (metaData != null) {
                createPermissions(metaData, policyConfiguration);
            } else {
                SecurityLogger.ROOT_LOGGER.debugf("Cannot create permissions with 'null' metaData for id=%s", contextId);
            }
            if (!standalone) {
                PolicyConfiguration parent = parentPolicy.getValue();
                if (parent != null) {
                    parent = pcf.getPolicyConfiguration(parent.getContextID(), false);
                    parent.linkConfiguration(policyConfiguration);
                    policyConfiguration.commit();
                    parent.commit();
                } else {
                    SecurityLogger.ROOT_LOGGER.debugf("Could not retrieve parent policy for policy %s", contextId);
                }
            } else {
                policyConfiguration.commit();
            }
            // Allow the policy to incorporate the policy configs
            Policy.getPolicy().refresh();
        }
    } catch (Exception e) {
        throw SecurityLogger.ROOT_LOGGER.unableToStartException("JaccService", e);
    }
}
Also used : PolicyConfiguration(javax.security.jacc.PolicyConfiguration) PolicyConfigurationFactory(javax.security.jacc.PolicyConfigurationFactory) PolicyContextException(javax.security.jacc.PolicyContextException) ModuleLoadException(org.jboss.modules.ModuleLoadException) StartException(org.jboss.msc.service.StartException)

Example 2 with PolicyConfiguration

use of javax.security.jacc.PolicyConfiguration in project tomee by apache.

the class JaccPermissionsBuilder method install.

public void install(final PolicyContext policyContext) throws OpenEJBException {
    if (SystemInstance.get().hasProperty("openejb.geronimo")) {
        return;
    }
    try {
        final PolicyConfigurationFactory factory = PolicyConfigurationFactory.getPolicyConfigurationFactory();
        final PolicyConfiguration policy = factory.getPolicyConfiguration(policyContext.getContextID(), false);
        policy.addToExcludedPolicy(policyContext.getExcludedPermissions());
        policy.addToUncheckedPolicy(policyContext.getUncheckedPermissions());
        for (final Map.Entry<String, PermissionCollection> entry : policyContext.getRolePermissions().entrySet()) {
            policy.addToRole(entry.getKey(), entry.getValue());
        }
        policy.commit();
    } catch (final ClassNotFoundException e) {
        throw new OpenEJBException("PolicyConfigurationFactory class not found", e);
    } catch (final PolicyContextException e) {
        throw new OpenEJBException("JACC PolicyConfiguration failed: ContextId=" + policyContext.getContextID(), e);
    }
}
Also used : PermissionCollection(java.security.PermissionCollection) OpenEJBException(org.apache.openejb.OpenEJBException) PolicyConfiguration(javax.security.jacc.PolicyConfiguration) PolicyContextException(javax.security.jacc.PolicyContextException) PolicyConfigurationFactory(javax.security.jacc.PolicyConfigurationFactory) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

PolicyConfiguration (javax.security.jacc.PolicyConfiguration)2 PolicyConfigurationFactory (javax.security.jacc.PolicyConfigurationFactory)2 PolicyContextException (javax.security.jacc.PolicyContextException)2 PermissionCollection (java.security.PermissionCollection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 OpenEJBException (org.apache.openejb.OpenEJBException)1 ModuleLoadException (org.jboss.modules.ModuleLoadException)1 StartException (org.jboss.msc.service.StartException)1