Search in sources :

Example 1 with IdentityProvider

use of io.gravitee.rest.api.idp.api.IdentityProvider in project gravitee-management-rest-api by gravitee-io.

the class IdentityProviderPluginHandler method handle.

@Override
public void handle(Plugin plugin) {
    try {
        ClassLoader classloader = pluginClassLoaderFactory.getOrCreateClassLoader(plugin, this.getClass().getClassLoader());
        final Class<?> identityProviderClass = classloader.loadClass(plugin.clazz());
        LOGGER.info("Register a new identity provider plugin: {} [{}]", plugin.id(), plugin.clazz());
        Assert.isAssignable(IdentityProvider.class, identityProviderClass);
        IdentityProvider identityIdentityProvider = createInstance((Class<IdentityProvider>) identityProviderClass);
        identityProviderManager.register(new IdentityProviderDefinition(identityIdentityProvider, plugin));
    } catch (Exception iae) {
        LOGGER.error("Unexpected error while create identity provider instance", iae);
    }
}
Also used : IdentityProvider(io.gravitee.rest.api.idp.api.IdentityProvider)

Example 2 with IdentityProvider

use of io.gravitee.rest.api.idp.api.IdentityProvider in project gravitee-management-rest-api by gravitee-io.

the class BasicSecurityConfigurerAdapter method configure.

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    LOGGER.info("--------------------------------------------------------------");
    LOGGER.info("Management API BasicSecurity Config");
    LOGGER.info("Loading authentication identity providers for Basic authentication");
    List<io.gravitee.rest.api.security.authentication.AuthenticationProvider> providers = authenticationProviderManager.getIdentityProviders().stream().filter(authenticationProvider -> !authenticationProvider.external()).collect(Collectors.toList());
    for (io.gravitee.rest.api.security.authentication.AuthenticationProvider provider : providers) {
        LOGGER.info("Loading authentication provider of type {} at position {}", provider.type(), provider.index());
        boolean found = false;
        Collection<IdentityProvider> identityProviders = identityProviderManager.getAll();
        for (IdentityProvider identityProvider : identityProviders) {
            if (identityProvider.type().equalsIgnoreCase(provider.type())) {
                AuthenticationProvider authenticationProviderPlugin = identityProviderManager.loadIdentityProvider(identityProvider.type(), provider.configuration());
                if (authenticationProviderPlugin != null) {
                    Object authenticationProvider = authenticationProviderPlugin.configure();
                    if (authenticationProvider instanceof org.springframework.security.authentication.AuthenticationProvider) {
                        auth.authenticationProvider((org.springframework.security.authentication.AuthenticationProvider) authenticationProvider);
                    } else if (authenticationProvider instanceof SecurityConfigurer) {
                        auth.apply((SecurityConfigurer) authenticationProvider);
                    }
                    found = true;
                    break;
                }
            }
        }
        if (!found) {
            LOGGER.error("No authentication provider found for type: {}", provider.type());
        }
    }
    LOGGER.info("--------------------------------------------------------------");
}
Also used : TokenService(io.gravitee.rest.api.service.TokenService) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) HttpSecurity(org.springframework.security.config.annotation.web.builders.HttpSecurity) CookieCsrfSignedTokenRepository(io.gravitee.rest.api.security.csrf.CookieCsrfSignedTokenRepository) HeadersConfigurer(org.springframework.security.config.annotation.web.configurers.HeadersConfigurer) AuthoritiesProvider(io.gravitee.rest.api.security.utils.AuthoritiesProvider) CorsConfigurationSource(org.springframework.web.cors.CorsConfigurationSource) WebSecurityConfigurerAdapter(org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter) CookieGenerator(io.gravitee.rest.api.security.cookies.CookieGenerator) HttpServletRequest(javax.servlet.http.HttpServletRequest) AuthenticationManagerBuilder(org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) UserService(io.gravitee.rest.api.service.UserService) CsrfRequestMatcher(io.gravitee.rest.api.security.csrf.CsrfRequestMatcher) AuthenticationDetailsSource(org.springframework.security.authentication.AuthenticationDetailsSource) SecurityConfigurer(org.springframework.security.config.annotation.SecurityConfigurer) AuthenticationSuccessListener(io.gravitee.rest.api.security.listener.AuthenticationSuccessListener) AuthenticationProviderManager(io.gravitee.rest.api.security.authentication.AuthenticationProviderManager) ParameterService(io.gravitee.rest.api.service.ParameterService) BasicAuthenticationFilter(org.springframework.security.web.authentication.www.BasicAuthenticationFilter) Logger(org.slf4j.Logger) RecaptchaFilter(io.gravitee.rest.api.security.filter.RecaptchaFilter) Collection(java.util.Collection) CsrfFilter(org.springframework.security.web.csrf.CsrfFilter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpMethod(org.springframework.http.HttpMethod) IdentityProviderManager(io.gravitee.rest.api.idp.core.plugin.IdentityProviderManager) CsrfIncludeFilter(io.gravitee.rest.api.security.filter.CsrfIncludeFilter) IdentityProvider(io.gravitee.rest.api.idp.api.IdentityProvider) Collectors(java.util.stream.Collectors) Profile(org.springframework.context.annotation.Profile) Configuration(org.springframework.context.annotation.Configuration) AuthenticationFailureListener(io.gravitee.rest.api.security.listener.AuthenticationFailureListener) List(java.util.List) EventManager(io.gravitee.common.event.EventManager) TokenAuthenticationFilter(io.gravitee.rest.api.security.filter.TokenAuthenticationFilter) EnableWebSecurity(org.springframework.security.config.annotation.web.configuration.EnableWebSecurity) GraviteeAuthenticationDetails(io.gravitee.rest.api.security.authentication.GraviteeAuthenticationDetails) SessionCreationPolicy(org.springframework.security.config.http.SessionCreationPolicy) AuthenticationProvider(io.gravitee.rest.api.idp.api.authentication.AuthenticationProvider) Bean(org.springframework.context.annotation.Bean) ReCaptchaService(io.gravitee.rest.api.service.ReCaptchaService) SecurityConfigurer(org.springframework.security.config.annotation.SecurityConfigurer) AuthenticationProvider(io.gravitee.rest.api.idp.api.authentication.AuthenticationProvider) IdentityProvider(io.gravitee.rest.api.idp.api.IdentityProvider)

Example 3 with IdentityProvider

use of io.gravitee.rest.api.idp.api.IdentityProvider in project gravitee-management-rest-api by gravitee-io.

the class IdentityProviderManagerImpl method authenticationProvider.

private AuthenticationProvider authenticationProvider(String identityProviderType, Map<String, Object> properties) {
    LOGGER.debug("Looking for an authentication provider for [{}]", identityProviderType);
    IdentityProvider identityProvider = identityProviders.get(identityProviderType);
    if (identityProvider != null) {
        return create(identityProviderPlugins.get(identityProvider), identityProvider.authenticationProvider(), properties);
    } else {
        LOGGER.error("No identity provider is registered for type {}", identityProviderType);
        throw new IllegalStateException("No identity provider is registered for type " + identityProviderType);
    }
}
Also used : IdentityProvider(io.gravitee.rest.api.idp.api.IdentityProvider)

Example 4 with IdentityProvider

use of io.gravitee.rest.api.idp.api.IdentityProvider in project gravitee-management-rest-api by gravitee-io.

the class IdentityProviderManagerImpl method identityLookup.

private IdentityLookup identityLookup(String identityProviderType, Map<String, Object> properties) {
    LOGGER.debug("Looking for an identity lookup for [{}]", identityProviderType);
    IdentityProvider identityProvider = identityProviders.get(identityProviderType);
    if (identityProvider != null) {
        return create(identityProviderPlugins.get(identityProvider), identityProvider.identityLookup(), properties);
    } else {
        LOGGER.error("No identity provider is registered for type {}", identityProviderType);
        throw new IllegalStateException("No identity provider is registered for type " + identityProviderType);
    }
}
Also used : IdentityProvider(io.gravitee.rest.api.idp.api.IdentityProvider)

Example 5 with IdentityProvider

use of io.gravitee.rest.api.idp.api.IdentityProvider in project gravitee-management-rest-api by gravitee-io.

the class BasicSecurityConfigurerAdapter method configure.

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    LOGGER.info("--------------------------------------------------------------");
    LOGGER.info("Portal API BasicSecurity Config");
    LOGGER.info("Loading authentication identity providers for Basic authentication");
    List<io.gravitee.rest.api.security.authentication.AuthenticationProvider> providers = authenticationProviderManager.getIdentityProviders().stream().filter(authenticationProvider -> !authenticationProvider.external()).collect(Collectors.toList());
    for (AuthenticationProvider provider : providers) {
        String providerType = provider.type();
        LOGGER.info("Loading authentication provider of type {} at position {}", providerType, provider.index());
        Collection<IdentityProvider> identityProviders = identityProviderManager.getAll();
        if (identityProviders != null) {
            Optional<io.gravitee.rest.api.idp.api.authentication.AuthenticationProvider> authenticationProviderPlugin = identityProviders.stream().filter(ip -> ip.type().equalsIgnoreCase(providerType)).map(ip -> identityProviderManager.loadIdentityProvider(ip.type(), provider.configuration())).filter(Objects::nonNull).findFirst();
            if (authenticationProviderPlugin.isPresent()) {
                Object authenticationProvider = authenticationProviderPlugin.get().configure();
                if (authenticationProvider instanceof org.springframework.security.authentication.AuthenticationProvider) {
                    auth.authenticationProvider((org.springframework.security.authentication.AuthenticationProvider) authenticationProvider);
                } else if (authenticationProvider instanceof SecurityConfigurer) {
                    auth.apply((SecurityConfigurer) authenticationProvider);
                }
            } else {
                LOGGER.error("No authentication provider found for type: {}", providerType);
            }
        }
    }
    LOGGER.info("--------------------------------------------------------------");
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) HttpSecurity(org.springframework.security.config.annotation.web.builders.HttpSecurity) CookieCsrfSignedTokenRepository(io.gravitee.rest.api.security.csrf.CookieCsrfSignedTokenRepository) HeadersConfigurer(org.springframework.security.config.annotation.web.configurers.HeadersConfigurer) AuthoritiesProvider(io.gravitee.rest.api.security.utils.AuthoritiesProvider) CorsConfigurationSource(org.springframework.web.cors.CorsConfigurationSource) WebSecurityConfigurerAdapter(org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter) CookieGenerator(io.gravitee.rest.api.security.cookies.CookieGenerator) HttpServletRequest(javax.servlet.http.HttpServletRequest) AuthenticationManagerBuilder(org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) CsrfRequestMatcher(io.gravitee.rest.api.security.csrf.CsrfRequestMatcher) AuthenticationDetailsSource(org.springframework.security.authentication.AuthenticationDetailsSource) SecurityConfigurer(org.springframework.security.config.annotation.SecurityConfigurer) AuthenticationSuccessListener(io.gravitee.rest.api.security.listener.AuthenticationSuccessListener) AuthenticationProviderManager(io.gravitee.rest.api.security.authentication.AuthenticationProviderManager) ParameterService(io.gravitee.rest.api.service.ParameterService) BasicAuthenticationFilter(org.springframework.security.web.authentication.www.BasicAuthenticationFilter) Logger(org.slf4j.Logger) RecaptchaFilter(io.gravitee.rest.api.security.filter.RecaptchaFilter) Collection(java.util.Collection) CsrfFilter(org.springframework.security.web.csrf.CsrfFilter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpMethod(org.springframework.http.HttpMethod) IdentityProviderManager(io.gravitee.rest.api.idp.core.plugin.IdentityProviderManager) CsrfIncludeFilter(io.gravitee.rest.api.security.filter.CsrfIncludeFilter) IdentityProvider(io.gravitee.rest.api.idp.api.IdentityProvider) Collectors(java.util.stream.Collectors) Profile(org.springframework.context.annotation.Profile) Objects(java.util.Objects) Configuration(org.springframework.context.annotation.Configuration) AuthenticationFailureListener(io.gravitee.rest.api.security.listener.AuthenticationFailureListener) List(java.util.List) EventManager(io.gravitee.common.event.EventManager) TokenAuthenticationFilter(io.gravitee.rest.api.security.filter.TokenAuthenticationFilter) EnableWebSecurity(org.springframework.security.config.annotation.web.configuration.EnableWebSecurity) GraviteeAuthenticationDetails(io.gravitee.rest.api.security.authentication.GraviteeAuthenticationDetails) SessionCreationPolicy(org.springframework.security.config.http.SessionCreationPolicy) Optional(java.util.Optional) AuthenticationProvider(io.gravitee.rest.api.security.authentication.AuthenticationProvider) Bean(org.springframework.context.annotation.Bean) ReCaptchaService(io.gravitee.rest.api.service.ReCaptchaService) SecurityConfigurer(org.springframework.security.config.annotation.SecurityConfigurer) AuthenticationProvider(io.gravitee.rest.api.security.authentication.AuthenticationProvider) IdentityProvider(io.gravitee.rest.api.idp.api.IdentityProvider)

Aggregations

IdentityProvider (io.gravitee.rest.api.idp.api.IdentityProvider)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 EventManager (io.gravitee.common.event.EventManager)2 IdentityProviderManager (io.gravitee.rest.api.idp.core.plugin.IdentityProviderManager)2 AuthenticationProviderManager (io.gravitee.rest.api.security.authentication.AuthenticationProviderManager)2 GraviteeAuthenticationDetails (io.gravitee.rest.api.security.authentication.GraviteeAuthenticationDetails)2 CookieGenerator (io.gravitee.rest.api.security.cookies.CookieGenerator)2 CookieCsrfSignedTokenRepository (io.gravitee.rest.api.security.csrf.CookieCsrfSignedTokenRepository)2 CsrfRequestMatcher (io.gravitee.rest.api.security.csrf.CsrfRequestMatcher)2 CsrfIncludeFilter (io.gravitee.rest.api.security.filter.CsrfIncludeFilter)2 RecaptchaFilter (io.gravitee.rest.api.security.filter.RecaptchaFilter)2 TokenAuthenticationFilter (io.gravitee.rest.api.security.filter.TokenAuthenticationFilter)2 AuthenticationFailureListener (io.gravitee.rest.api.security.listener.AuthenticationFailureListener)2 AuthenticationSuccessListener (io.gravitee.rest.api.security.listener.AuthenticationSuccessListener)2 AuthoritiesProvider (io.gravitee.rest.api.security.utils.AuthoritiesProvider)2 ParameterService (io.gravitee.rest.api.service.ParameterService)2 ReCaptchaService (io.gravitee.rest.api.service.ReCaptchaService)2 Collection (java.util.Collection)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2