Search in sources :

Example 1 with PolicyConfigurationFactory

use of javax.security.jacc.PolicyConfigurationFactory 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 PolicyConfigurationFactory

use of javax.security.jacc.PolicyConfigurationFactory 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)

Example 3 with PolicyConfigurationFactory

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

the class JaccService method stop.

/** {@inheritDoc} */
@Override
public void stop(StopContext context) {
    try {
        PolicyConfigurationFactory pcf = PolicyConfigurationFactory.getPolicyConfigurationFactory();
        synchronized (pcf) {
            // synchronize on the factory
            policyConfiguration = pcf.getPolicyConfiguration(contextId, false);
            policyConfiguration.delete();
        }
    } catch (Exception e) {
        SecurityLogger.ROOT_LOGGER.errorDeletingJACCPolicy(e);
    }
    policyConfiguration = null;
}
Also used : PolicyConfigurationFactory(javax.security.jacc.PolicyConfigurationFactory) PolicyContextException(javax.security.jacc.PolicyContextException) ModuleLoadException(org.jboss.modules.ModuleLoadException) StartException(org.jboss.msc.service.StartException)

Aggregations

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