Search in sources :

Example 1 with SecurityConfigurations

use of org.glassfish.security.services.config.SecurityConfigurations in project Payara by payara.

the class ServiceFactory method getSecurityServiceConfiguration.

/**
 * Get the security service configuration for the specified service type.
 *
 * Attempt to obtain the service configuration marked as default
 * otherwise use the first configured service instance.
 *
 * @param domain The current Domain configuration object
 * @param type The type of the security service configuration
 *
 * @return null when no service configurations are found
 */
public static <T extends SecurityConfiguration> T getSecurityServiceConfiguration(Domain domain, Class<T> type) {
    T config = null;
    // Look for security service configurations
    SecurityConfigurations secConfigs = domain.getExtensionByType(SecurityConfigurations.class);
    if (secConfigs != null) {
        // Look for the service configuration marked default
        config = secConfigs.getDefaultSecurityServiceByType(type);
        if (config == null) {
            // Obtain the first service configuration listed
            List<T> configs = secConfigs.getSecurityServicesByType(type);
            if (!configs.isEmpty())
                config = configs.get(0);
        }
    }
    // Return the service configuration
    return config;
}
Also used : SecurityConfigurations(org.glassfish.security.services.config.SecurityConfigurations)

Example 2 with SecurityConfigurations

use of org.glassfish.security.services.config.SecurityConfigurations in project Payara by payara.

the class CreateSecurityService method execute.

/**
 * Execute the create-security-service admin command.
 */
@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    // Setup the service type and configuration handler
    if (AUTHENTICATION.equalsIgnoreCase(serviceType)) {
        clazzServiceType = AuthenticationService.class;
        serviceConfigHandler = new AuthenticationConfigHandler();
    } else {
        report.setMessage("Invalid security service type specified: " + serviceType);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // Add service configuration to the security configurations
    // TODO - Add validation logic required for base service configuration
    SecurityConfiguration config = null;
    try {
        config = (SecurityConfiguration) ConfigSupport.apply(new SingleConfigCode<SecurityConfigurations>() {

            @Override
            public Object run(SecurityConfigurations param) throws PropertyVetoException, TransactionFailure {
                SecurityConfiguration svcConfig = param.createChild(clazzServiceType);
                svcConfig.setName(serviceName);
                svcConfig.setDefault(enableDefault.toString());
                param.getSecurityServices().add(svcConfig);
                return svcConfig;
            }
        }, secConfigs);
    } catch (TransactionFailure transactionFailure) {
        report.setMessage("Unable to create security service: " + transactionFailure.getMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(transactionFailure);
        return;
    }
    // TODO - Add validation logic required for specific service configuration
    if ((config != null) && (configuration != null) && (!configuration.isEmpty())) {
        serviceConfigHandler.setupConfiguration(report, config);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) SecurityConfigurations(org.glassfish.security.services.config.SecurityConfigurations) SecurityConfiguration(org.glassfish.security.services.config.SecurityConfiguration) ActionReport(org.glassfish.api.ActionReport)

Example 3 with SecurityConfigurations

use of org.glassfish.security.services.config.SecurityConfigurations in project Payara by payara.

the class CLIUtil method findSecurityConfiguration.

public static SecurityConfiguration findSecurityConfiguration(final Domain domain, final String serviceName, final ActionReport report) {
    // Lookup the security configurations
    SecurityConfigurations secConfigs = domain.getExtensionByType(SecurityConfigurations.class);
    if (secConfigs == null) {
        report.setMessage("Unable to locate security configurations");
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return null;
    }
    // Get the security service
    SecurityConfiguration ssc = secConfigs.getSecurityServiceByName(serviceName);
    if (ssc == null) {
        report.setMessage("Unable to locate security service: " + serviceName);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return null;
    }
    return ssc;
}
Also used : SecurityConfigurations(org.glassfish.security.services.config.SecurityConfigurations) SecurityConfiguration(org.glassfish.security.services.config.SecurityConfiguration)

Aggregations

SecurityConfigurations (org.glassfish.security.services.config.SecurityConfigurations)3 SecurityConfiguration (org.glassfish.security.services.config.SecurityConfiguration)2 PropertyVetoException (java.beans.PropertyVetoException)1 ActionReport (org.glassfish.api.ActionReport)1 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)1