Search in sources :

Example 1 with JaccProvider

use of com.sun.enterprise.config.serverbeans.JaccProvider in project Payara by payara.

the class DeleteJaccProvider method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    try {
        List<JaccProvider> jaccProviders = securityService.getJaccProvider();
        JaccProvider jprov = null;
        for (JaccProvider jaccProv : jaccProviders) {
            if (jaccProv.getName().equals(jaccprovider)) {
                jprov = jaccProv;
                break;
            }
        }
        final JaccProvider jaccprov = jprov;
        ConfigSupport.apply(new SingleConfigCode<SecurityService>() {

            public Object run(SecurityService param) throws PropertyVetoException, TransactionFailure {
                param.getJaccProvider().remove(jaccprov);
                return null;
            }
        }, securityService);
    } catch (TransactionFailure e) {
        report.setMessage(localStrings.getLocalString("delete.jacc.provider.fail", "Deletion of JaccProvider {0} failed", jaccprovider) + "  " + e.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) JaccProvider(com.sun.enterprise.config.serverbeans.JaccProvider) SecurityService(com.sun.enterprise.config.serverbeans.SecurityService) ActionReport(org.glassfish.api.ActionReport)

Example 2 with JaccProvider

use of com.sun.enterprise.config.serverbeans.JaccProvider in project Payara by payara.

the class PolicyLoader method loadPolicy.

/**
 * Attempts to install the policy-provider. The policy-provider
 * element in domain.xml is consulted for the class to use. Note
 * that if the javax.security.jacc.policy.provider system property
 * is set it will override the domain.xml configuration. This will
 * normally not be the case in S1AS.
 *
 * <P>The J2EE 1.3 property javax.security.jacc.auth.policy.provider is
 * checked as a last resort. It should not be set in J2EE 1.4.
 */
public void loadPolicy() {
    if (isPolicyInstalled) {
        _logger.log(Level.FINE, "Policy already installed. Will not re-install.");
        return;
    }
    // get config object
    JaccProvider jacc = getConfiguredJaccProvider();
    // set config properties (see method comments)
    setPolicyConfigurationFactory(jacc);
    boolean j2ee13 = false;
    // check if system property is set
    String javaPolicy = System.getProperty(POLICY_PROVIDER_14);
    if (javaPolicy != null) {
        // inform user domain.xml is being ignored
        _logger.log(Level.INFO, SecurityLoggerInfo.policyProviderConfigOverrideMsg, new String[] { POLICY_PROVIDER_14, javaPolicy });
    } else {
        // otherwise obtain JACC policy-provider from domain.xml
        if (jacc != null) {
            javaPolicy = jacc.getPolicyProvider();
        }
    }
    if (javaPolicy == null) {
        javaPolicy = System.getProperty(POLICY_PROVIDER_13);
        if (javaPolicy != null) {
            // warn user j2ee13 property is being used
            j2ee13 = true;
            _logger.log(Level.WARNING, SecurityLoggerInfo.policyProviderConfigOverrideWarning, new String[] { POLICY_PROVIDER_13, javaPolicy });
        }
    }
    // now install the policy provider if one was identified
    if (javaPolicy != null) {
        try {
            _logger.log(Level.INFO, SecurityLoggerInfo.policyLoading, javaPolicy);
            // Object obj = Class.forName(javaPolicy).newInstance();
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
            Class javaPolicyClass = loader.loadClass(javaPolicy);
            Object obj = javaPolicyClass.newInstance();
            if (j2ee13) {
                // Use JDK 1.3 classes if j2ee1 3 property being used
                if (!(obj instanceof javax.security.auth.Policy)) {
                    String msg = sm.getString("enterprise.security.plcyload.not13");
                    throw new RuntimeException(msg);
                }
                javax.security.auth.Policy policy = (javax.security.auth.Policy) obj;
                javax.security.auth.Policy.setPolicy(policy);
                policy.refresh();
            } else {
                // Otherwise use JDK 1.4 classes.
                if (!(obj instanceof java.security.Policy)) {
                    String msg = sm.getString("enterprise.security.plcyload.not14");
                    throw new RuntimeException(msg);
                }
                java.security.Policy policy = (java.security.Policy) obj;
                java.security.Policy.setPolicy(policy);
                // in this case.
                if (System.getSecurityManager() == null) {
                    policy.refresh();
                }
            }
        } catch (Exception e) {
            _logger.log(Level.SEVERE, SecurityLoggerInfo.policyInstallError, e.getLocalizedMessage());
            throw new RuntimeException(e);
        }
        // Success.
        _logger.fine("Policy set to: " + javaPolicy);
        isPolicyInstalled = true;
    } else {
        // no value for policy provider found
        _logger.warning(SecurityLoggerInfo.policyNotLoadingWarning);
    }
}
Also used : JaccProvider(com.sun.enterprise.config.serverbeans.JaccProvider)

Example 3 with JaccProvider

use of com.sun.enterprise.config.serverbeans.JaccProvider in project Payara by payara.

the class ListJaccProviders method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    List<JaccProvider> jaccProviders = securityService.getJaccProvider();
    JaccProvider jprov = null;
    for (JaccProvider jaccProv : jaccProviders) {
        ActionReport.MessagePart part = report.getTopMessagePart().addChild();
        part.setMessage(jaccProv.getName());
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : JaccProvider(com.sun.enterprise.config.serverbeans.JaccProvider) ActionReport(org.glassfish.api.ActionReport)

Example 4 with JaccProvider

use of com.sun.enterprise.config.serverbeans.JaccProvider in project Payara by payara.

the class PolicyLoader method getConfiguredJaccProvider.

/**
 * Returns a JaccProvider object representing the jacc element from
 * domain.xml which is configured in security-service.
 *
 * @return The config object or null on errors.
 */
private JaccProvider getConfiguredJaccProvider() {
    JaccProvider jacc = null;
    try {
        String name = securityService.getJacc();
        jacc = getJaccProviderByName(name);
        if (jacc == null) {
            _logger.log(Level.WARNING, SecurityLoggerInfo.policyNoSuchName, name);
        }
    } catch (Exception e) {
        _logger.warning(SecurityLoggerInfo.policyReadingError);
        jacc = null;
    }
    return jacc;
}
Also used : JaccProvider(com.sun.enterprise.config.serverbeans.JaccProvider)

Example 5 with JaccProvider

use of com.sun.enterprise.config.serverbeans.JaccProvider in project Payara by payara.

the class CreateJACCProvider method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    // No duplicate auth realms found. So add one.
    try {
        ConfigSupport.apply(new SingleConfigCode<SecurityService>() {

            public Object run(SecurityService param) throws PropertyVetoException, TransactionFailure {
                JaccProvider newJacc = param.createChild(JaccProvider.class);
                newJacc.setName(jaccProviderName);
                newJacc.setPolicyConfigurationFactoryProvider(polConfFactoryClass);
                newJacc.setPolicyProvider(polProviderClass);
                configureProperties(newJacc);
                param.getJaccProvider().add(newJacc);
                return newJacc;
            }
        }, securityService);
    } catch (TransactionFailure e) {
        report.setMessage(localStrings.getLocalString("create.auth.realm.fail", "Creation of Authrealm {0} failed", jaccProviderName) + "  " + e.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) JaccProvider(com.sun.enterprise.config.serverbeans.JaccProvider) SecurityService(com.sun.enterprise.config.serverbeans.SecurityService) ActionReport(org.glassfish.api.ActionReport)

Aggregations

JaccProvider (com.sun.enterprise.config.serverbeans.JaccProvider)6 ActionReport (org.glassfish.api.ActionReport)4 SecurityService (com.sun.enterprise.config.serverbeans.SecurityService)2 PropertyVetoException (java.beans.PropertyVetoException)2 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)2