Search in sources :

Example 1 with PrivilegedLookup

use of org.glassfish.security.services.common.PrivilegedLookup in project Payara by payara.

the class RoleMappingServiceImpl method initialize.

/**
 * Initialize the Role Mapping service with the configured role mapping provider.
 */
@Override
public void initialize(SecurityConfiguration securityServiceConfiguration) {
    if (InitializationState.NOT_INITIALIZED != initialized) {
        return;
    }
    try {
        // Get the Role Mapping Service configuration
        config = (org.glassfish.security.services.config.RoleMappingService) securityServiceConfiguration;
        if (config != null) {
            // Get the role mapping provider configuration
            // Consider only one provider for now and take the first provider found!
            List<SecurityProvider> providersConfig = config.getSecurityProviders();
            SecurityProvider roleProviderConfig = null;
            if (providersConfig != null)
                roleProviderConfig = providersConfig.get(0);
            if (roleProviderConfig != null) {
                // Get the provider
                String providerName = roleProviderConfig.getName();
                if (isDebug()) {
                    logger.log(DEBUG_LEVEL, "Attempting to get Role Mapping Provider \"{0}\".", providerName);
                }
                provider = AccessController.doPrivileged(new PrivilegedLookup<RoleMappingProvider>(serviceLocator, RoleMappingProvider.class, providerName));
                if (provider == null) {
                    throw new IllegalStateException(localStrings.getLocalString("service.role.not_provider", "Role Mapping Provider {0} not found.", providerName));
                }
                // Initialize the provider
                provider.initialize(roleProviderConfig);
                // Service setup complete
                initialized = InitializationState.SUCCESS_INIT;
                reasonInitFailed = null;
                // Log initialized
                logger.log(Level.INFO, ROLEMAPSVC_INITIALIZED);
            }
        }
    } catch (Exception e) {
        String eMsg = e.getMessage();
        String eClass = e.getClass().getName();
        reasonInitFailed = localStrings.getLocalString("service.role.init_failed", "Role Mapping Service initialization failed, exception {0}, message {1}", eClass, eMsg);
        logger.log(Level.WARNING, ROLEMAPSVC_INIT_FAILED, new Object[] { eClass, eMsg });
        throw new RuntimeException(reasonInitFailed, e);
    } finally {
        if (InitializationState.SUCCESS_INIT != initialized) {
            initialized = InitializationState.FAILED_INIT;
        }
    }
}
Also used : PrivilegedLookup(org.glassfish.security.services.common.PrivilegedLookup) SecurityProvider(org.glassfish.security.services.config.SecurityProvider)

Aggregations

PrivilegedLookup (org.glassfish.security.services.common.PrivilegedLookup)1 SecurityProvider (org.glassfish.security.services.config.SecurityProvider)1