Search in sources :

Example 6 with DhisOidcClientRegistration

use of org.hisp.dhis.security.oidc.DhisOidcClientRegistration in project dhis2-core by dhis2.

the class GoogleProvider method parse.

public static DhisOidcClientRegistration parse(Properties config) {
    Objects.requireNonNull(config, "DhisConfigurationProvider is missing!");
    Map<String, Set<String>> allKeysByProvider = GenericOidcProviderConfigParser.extractKeysGroupByProvider(config);
    // Skip parsing if there is no keys matching REGISTRATION_ID
    if (!allKeysByProvider.containsKey(REGISTRATION_ID) || allKeysByProvider.get(REGISTRATION_ID).isEmpty()) {
        return null;
    }
    Set<String> googleKeys = allKeysByProvider.get(REGISTRATION_ID);
    Map<String, Map<String, String>> externalClientConfigs = GenericOidcProviderConfigParser.getAllExternalClients(config, REGISTRATION_ID, googleKeys);
    ClientRegistration clientRegistration = buildClientRegistration(config);
    if (clientRegistration == null) {
        return null;
    }
    return DhisOidcClientRegistration.builder().clientRegistration(clientRegistration).mappingClaimKey(StringUtils.firstNonBlank(config.getProperty(OIDC_PROVIDER_GOOGLE_MAPPING_CLAIM.getKey()), "email")).loginIcon("../oidc/btn_google_light_normal_ios.svg").loginIconPadding("0px 0px").loginText("login_with_google").externalClients(externalClientConfigs).build();
}
Also used : Set(java.util.Set) ClientRegistration(org.springframework.security.oauth2.client.registration.ClientRegistration) DhisOidcClientRegistration(org.hisp.dhis.security.oidc.DhisOidcClientRegistration) Map(java.util.Map)

Example 7 with DhisOidcClientRegistration

use of org.hisp.dhis.security.oidc.DhisOidcClientRegistration in project dhis2-core by dhis2.

the class LoginAction method addRegisteredProviders.

private void addRegisteredProviders() {
    List<Map<String, String>> providers = new ArrayList<>();
    Set<String> allRegistrationIds = repository.getAllRegistrationId();
    for (String registrationId : allRegistrationIds) {
        DhisOidcClientRegistration clientRegistration = repository.getDhisOidcClientRegistration(registrationId);
        providers.add(ImmutableMap.of("id", registrationId, "icon", clientRegistration.getLoginIcon(), "iconPadding", clientRegistration.getLoginIconPadding(), "loginText", clientRegistration.getLoginText()));
    }
    if (!providers.isEmpty()) {
        oidcConfig.put("providers", providers);
    }
}
Also used : DhisOidcClientRegistration(org.hisp.dhis.security.oidc.DhisOidcClientRegistration) ArrayList(java.util.ArrayList) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

DhisOidcClientRegistration (org.hisp.dhis.security.oidc.DhisOidcClientRegistration)7 Map (java.util.Map)3 HashMap (java.util.HashMap)2 Properties (java.util.Properties)2 ClientRegistration (org.springframework.security.oauth2.client.registration.ClientRegistration)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 Test (org.junit.jupiter.api.Test)1 Jwt (org.springframework.security.oauth2.jwt.Jwt)1 JwtDecoder (org.springframework.security.oauth2.jwt.JwtDecoder)1 InvalidBearerTokenException (org.springframework.security.oauth2.server.resource.InvalidBearerTokenException)1