From 8521ca8f94a60482e1ed92d0eea60824412566e1 Mon Sep 17 00:00:00 2001 From: Joe Grandja Date: Thu, 21 Sep 2017 15:32:04 -0400 Subject: [PATCH] Polish gh-4560 --- ...OAuth2ClientTemplatePropertiesLoader.java} | 28 ++++++------ ...ecurity-oauth2-client-templates.properties | 44 +++++++++++++++++++ ...ng-security-oauth2-client-types.properties | 44 ------------------- 3 files changed, 57 insertions(+), 59 deletions(-) rename config/src/main/java/org/springframework/security/config/oauth2/client/{OAuth2ClientPropertiesUtil.java => OAuth2ClientTemplatePropertiesLoader.java} (52%) create mode 100644 config/src/main/resources/org/springframework/security/config/oauth2/client/spring-security-oauth2-client-templates.properties delete mode 100644 config/src/main/resources/org/springframework/security/config/oauth2/client/spring-security-oauth2-client-types.properties diff --git a/config/src/main/java/org/springframework/security/config/oauth2/client/OAuth2ClientPropertiesUtil.java b/config/src/main/java/org/springframework/security/config/oauth2/client/OAuth2ClientTemplatePropertiesLoader.java similarity index 52% rename from config/src/main/java/org/springframework/security/config/oauth2/client/OAuth2ClientPropertiesUtil.java rename to config/src/main/java/org/springframework/security/config/oauth2/client/OAuth2ClientTemplatePropertiesLoader.java index 7a1733e538..c3e59025d7 100644 --- a/config/src/main/java/org/springframework/security/config/oauth2/client/OAuth2ClientPropertiesUtil.java +++ b/config/src/main/java/org/springframework/security/config/oauth2/client/OAuth2ClientTemplatePropertiesLoader.java @@ -16,36 +16,34 @@ package org.springframework.security.config.oauth2.client; -import org.springframework.core.env.PropertiesPropertySource; import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.support.ResourcePropertySource; +import org.springframework.core.io.support.PropertiesLoaderUtils; import java.io.IOException; +import java.util.Map; /** - * Utility methods for OAuth 2.0 client properties. + * A resource loader for OAuth 2.0 client template(s) properties. * * @author Joe Grandja * @since 5.0.0 */ -public final class OAuth2ClientPropertiesUtil { +public final class OAuth2ClientTemplatePropertiesLoader { - public static final String CLIENT_TYPES_PROPERTY_PREFIX = "spring.security.oauth2.client.client-types"; + public static final String CLIENT_TEMPLATES_PROPERTY_PREFIX = "spring.security.oauth2.client.templates"; - private static final String CLIENT_TYPES_RESOURCE_LOCATION = "spring-security-oauth2-client-types.properties"; + private static final String CLIENT_TEMPLATES_RESOURCE_LOCATION = "spring-security-oauth2-client-templates.properties"; - private OAuth2ClientPropertiesUtil() { + private OAuth2ClientTemplatePropertiesLoader() { } - public static PropertiesPropertySource loadClientTypesPropertySource() { + public static Map loadClientTemplates() { try { - return new ResourcePropertySource( - new ClassPathResource(CLIENT_TYPES_RESOURCE_LOCATION, OAuth2ClientPropertiesUtil.class)); - } - catch (IOException ioe) { - throw new RuntimeException("Failed to load OAuth 2.0 client types resource: " - + CLIENT_TYPES_RESOURCE_LOCATION, ioe); + return (Map) PropertiesLoaderUtils.loadProperties( + new ClassPathResource(CLIENT_TEMPLATES_RESOURCE_LOCATION, OAuth2ClientTemplatePropertiesLoader.class)); + } catch (IOException ioe) { + throw new RuntimeException("Failed to load OAuth 2.0 client templates resource: " + + CLIENT_TEMPLATES_RESOURCE_LOCATION, ioe); } } } - diff --git a/config/src/main/resources/org/springframework/security/config/oauth2/client/spring-security-oauth2-client-templates.properties b/config/src/main/resources/org/springframework/security/config/oauth2/client/spring-security-oauth2-client-templates.properties new file mode 100644 index 0000000000..2e529e4393 --- /dev/null +++ b/config/src/main/resources/org/springframework/security/config/oauth2/client/spring-security-oauth2-client-templates.properties @@ -0,0 +1,44 @@ +# Google +spring.security.oauth2.client.templates.google.client-authentication-method=basic +spring.security.oauth2.client.templates.google.authorization-grant-type=authorization_code +spring.security.oauth2.client.templates.google.redirect-uri={scheme}://{serverName}:{serverPort}{contextPath}/oauth2/authorize/code/{clientAlias} +spring.security.oauth2.client.templates.google.scope=openid, profile, email, address, phone +spring.security.oauth2.client.templates.google.authorization-uri=https://accounts.google.com/o/oauth2/v2/auth +spring.security.oauth2.client.templates.google.token-uri=https://www.googleapis.com/oauth2/v4/token +spring.security.oauth2.client.templates.google.user-info-uri=https://www.googleapis.com/oauth2/v3/userinfo +spring.security.oauth2.client.templates.google.jwk-set-uri=https://www.googleapis.com/oauth2/v3/certs +spring.security.oauth2.client.templates.google.client-name=Google +spring.security.oauth2.client.templates.google.client-alias=google + +# GitHub +spring.security.oauth2.client.templates.github.client-authentication-method=basic +spring.security.oauth2.client.templates.github.authorization-grant-type=authorization_code +spring.security.oauth2.client.templates.github.redirect-uri={scheme}://{serverName}:{serverPort}{contextPath}/oauth2/authorize/code/{clientAlias} +spring.security.oauth2.client.templates.github.scope=user +spring.security.oauth2.client.templates.github.authorization-uri=https://github.com/login/oauth/authorize +spring.security.oauth2.client.templates.github.token-uri=https://github.com/login/oauth/access_token +spring.security.oauth2.client.templates.github.user-info-uri=https://api.github.com/user +spring.security.oauth2.client.templates.github.user-name-attribute-name=name +spring.security.oauth2.client.templates.github.client-name=GitHub +spring.security.oauth2.client.templates.github.client-alias=github + +# Facebook +spring.security.oauth2.client.templates.facebook.client-authentication-method=post +spring.security.oauth2.client.templates.facebook.authorization-grant-type=authorization_code +spring.security.oauth2.client.templates.facebook.redirect-uri={scheme}://{serverName}:{serverPort}{contextPath}/oauth2/authorize/code/{clientAlias} +spring.security.oauth2.client.templates.facebook.scope=public_profile, email +spring.security.oauth2.client.templates.facebook.authorization-uri=https://www.facebook.com/v2.8/dialog/oauth +spring.security.oauth2.client.templates.facebook.token-uri=https://graph.facebook.com/v2.8/oauth/access_token +spring.security.oauth2.client.templates.facebook.user-info-uri=https://graph.facebook.com/me +spring.security.oauth2.client.templates.facebook.user-name-attribute-name=name +spring.security.oauth2.client.templates.facebook.client-name=Facebook +spring.security.oauth2.client.templates.facebook.client-alias=facebook + +# Okta +spring.security.oauth2.client.templates.okta.client-authentication-method=basic +spring.security.oauth2.client.templates.okta.authorization-grant-type=authorization_code +spring.security.oauth2.client.templates.okta.redirect-uri={scheme}://{serverName}:{serverPort}{contextPath}/oauth2/authorize/code/{clientAlias} +spring.security.oauth2.client.templates.okta.scope=openid, profile, email, address, phone +spring.security.oauth2.client.templates.okta.client-name=Okta +spring.security.oauth2.client.templates.okta.client-alias=okta + diff --git a/config/src/main/resources/org/springframework/security/config/oauth2/client/spring-security-oauth2-client-types.properties b/config/src/main/resources/org/springframework/security/config/oauth2/client/spring-security-oauth2-client-types.properties deleted file mode 100644 index 1447daa32e..0000000000 --- a/config/src/main/resources/org/springframework/security/config/oauth2/client/spring-security-oauth2-client-types.properties +++ /dev/null @@ -1,44 +0,0 @@ -# Google -spring.security.oauth2.client.client-types.google.client-authentication-method=basic -spring.security.oauth2.client.client-types.google.authorization-grant-type=authorization_code -spring.security.oauth2.client.client-types.google.redirect-uri={scheme}://{serverName}:{serverPort}{contextPath}/oauth2/authorize/code/{clientAlias} -spring.security.oauth2.client.client-types.google.scope=openid, profile, email, address, phone -spring.security.oauth2.client.client-types.google.authorization-uri=https://accounts.google.com/o/oauth2/v2/auth -spring.security.oauth2.client.client-types.google.token-uri=https://www.googleapis.com/oauth2/v4/token -spring.security.oauth2.client.client-types.google.user-info-uri=https://www.googleapis.com/oauth2/v3/userinfo -spring.security.oauth2.client.client-types.google.jwk-set-uri=https://www.googleapis.com/oauth2/v3/certs -spring.security.oauth2.client.client-types.google.client-name=Google -spring.security.oauth2.client.client-types.google.client-alias=google - -# GitHub -spring.security.oauth2.client.client-types.github.client-authentication-method=basic -spring.security.oauth2.client.client-types.github.authorization-grant-type=authorization_code -spring.security.oauth2.client.client-types.github.redirect-uri={scheme}://{serverName}:{serverPort}{contextPath}/oauth2/authorize/code/{clientAlias} -spring.security.oauth2.client.client-types.github.scope=user -spring.security.oauth2.client.client-types.github.authorization-uri=https://github.com/login/oauth/authorize -spring.security.oauth2.client.client-types.github.token-uri=https://github.com/login/oauth/access_token -spring.security.oauth2.client.client-types.github.user-info-uri=https://api.github.com/user -spring.security.oauth2.client.client-types.github.user-name-attribute-name=name -spring.security.oauth2.client.client-types.github.client-name=GitHub -spring.security.oauth2.client.client-types.github.client-alias=github - -# Facebook -spring.security.oauth2.client.client-types.facebook.client-authentication-method=post -spring.security.oauth2.client.client-types.facebook.authorization-grant-type=authorization_code -spring.security.oauth2.client.client-types.facebook.redirect-uri={scheme}://{serverName}:{serverPort}{contextPath}/oauth2/authorize/code/{clientAlias} -spring.security.oauth2.client.client-types.facebook.scope=public_profile, email -spring.security.oauth2.client.client-types.facebook.authorization-uri=https://www.facebook.com/v2.8/dialog/oauth -spring.security.oauth2.client.client-types.facebook.token-uri=https://graph.facebook.com/v2.8/oauth/access_token -spring.security.oauth2.client.client-types.facebook.user-info-uri=https://graph.facebook.com/me -spring.security.oauth2.client.client-types.facebook.user-name-attribute-name=name -spring.security.oauth2.client.client-types.facebook.client-name=Facebook -spring.security.oauth2.client.client-types.facebook.client-alias=facebook - -# Okta -spring.security.oauth2.client.client-types.okta.client-authentication-method=basic -spring.security.oauth2.client.client-types.okta.authorization-grant-type=authorization_code -spring.security.oauth2.client.client-types.okta.redirect-uri={scheme}://{serverName}:{serverPort}{contextPath}/oauth2/authorize/code/{clientAlias} -spring.security.oauth2.client.client-types.okta.scope=openid, profile, email, address, phone -spring.security.oauth2.client.client-types.okta.client-name=Okta -spring.security.oauth2.client.client-types.okta.client-alias=okta -