parent
ee6c1f2ddd
commit
f3756cdd07
|
@ -204,24 +204,6 @@ public class ClientRegistration {
|
|||
this.registrationId = registrationId;
|
||||
}
|
||||
|
||||
public Builder(ClientRegistrationProperties clientRegistrationProperties) {
|
||||
this(clientRegistrationProperties.getRegistrationId());
|
||||
this.clientId(clientRegistrationProperties.getClientId());
|
||||
this.clientSecret(clientRegistrationProperties.getClientSecret());
|
||||
this.clientAuthenticationMethod(clientRegistrationProperties.getClientAuthenticationMethod());
|
||||
this.authorizationGrantType(clientRegistrationProperties.getAuthorizationGrantType());
|
||||
this.redirectUri(clientRegistrationProperties.getRedirectUri());
|
||||
if (!CollectionUtils.isEmpty(clientRegistrationProperties.getScope())) {
|
||||
this.scope(clientRegistrationProperties.getScope().toArray(new String[0]));
|
||||
}
|
||||
this.authorizationUri(clientRegistrationProperties.getAuthorizationUri());
|
||||
this.tokenUri(clientRegistrationProperties.getTokenUri());
|
||||
this.userInfoUri(clientRegistrationProperties.getUserInfoUri());
|
||||
this.userNameAttributeName(clientRegistrationProperties.getUserNameAttributeName());
|
||||
this.jwkSetUri(clientRegistrationProperties.getJwkSetUri());
|
||||
this.clientName(clientRegistrationProperties.getClientName());
|
||||
}
|
||||
|
||||
public Builder(ClientRegistration clientRegistration) {
|
||||
this(clientRegistration.getRegistrationId());
|
||||
this.clientId(clientRegistration.getClientId());
|
||||
|
|
|
@ -1,153 +0,0 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.security.oauth2.client.registration;
|
||||
|
||||
import org.springframework.security.oauth2.core.AuthorizationGrantType;
|
||||
import org.springframework.security.oauth2.core.ClientAuthenticationMethod;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A convenience class that provides a <i>"flattened"</i> property structure for {@link ClientRegistration}.
|
||||
*
|
||||
* <p>
|
||||
* This class may be used to <i>"bind"</i> property values located in the {@link org.springframework.core.env.Environment}
|
||||
* and then pass it to {@link ClientRegistration.Builder#Builder(ClientRegistrationProperties)}
|
||||
* to construct a {@link ClientRegistration} instance.
|
||||
*
|
||||
* @author Joe Grandja
|
||||
* @since 5.0
|
||||
* @see ClientRegistration
|
||||
*/
|
||||
public class ClientRegistrationProperties {
|
||||
private String registrationId;
|
||||
private String clientId;
|
||||
private String clientSecret;
|
||||
private ClientAuthenticationMethod clientAuthenticationMethod = ClientAuthenticationMethod.BASIC;
|
||||
private AuthorizationGrantType authorizationGrantType;
|
||||
private String redirectUri;
|
||||
private Set<String> scope;
|
||||
private String authorizationUri;
|
||||
private String tokenUri;
|
||||
private String userInfoUri;
|
||||
private String userNameAttributeName;
|
||||
private String jwkSetUri;
|
||||
private String clientName;
|
||||
|
||||
public String getRegistrationId() {
|
||||
return this.registrationId;
|
||||
}
|
||||
|
||||
public void setRegistrationId(String registrationId) {
|
||||
this.registrationId = registrationId;
|
||||
}
|
||||
|
||||
public String getClientId() {
|
||||
return this.clientId;
|
||||
}
|
||||
|
||||
public void setClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
public String getClientSecret() {
|
||||
return this.clientSecret;
|
||||
}
|
||||
|
||||
public void setClientSecret(String clientSecret) {
|
||||
this.clientSecret = clientSecret;
|
||||
}
|
||||
|
||||
public ClientAuthenticationMethod getClientAuthenticationMethod() {
|
||||
return this.clientAuthenticationMethod;
|
||||
}
|
||||
|
||||
public void setClientAuthenticationMethod(ClientAuthenticationMethod clientAuthenticationMethod) {
|
||||
this.clientAuthenticationMethod = clientAuthenticationMethod;
|
||||
}
|
||||
|
||||
public AuthorizationGrantType getAuthorizationGrantType() {
|
||||
return this.authorizationGrantType;
|
||||
}
|
||||
|
||||
public void setAuthorizationGrantType(AuthorizationGrantType authorizationGrantType) {
|
||||
this.authorizationGrantType = authorizationGrantType;
|
||||
}
|
||||
|
||||
public String getRedirectUri() {
|
||||
return this.redirectUri;
|
||||
}
|
||||
|
||||
public void setRedirectUri(String redirectUri) {
|
||||
this.redirectUri = redirectUri;
|
||||
}
|
||||
|
||||
public Set<String> getScope() {
|
||||
return this.scope;
|
||||
}
|
||||
|
||||
public void setScope(Set<String> scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
public String getAuthorizationUri() {
|
||||
return this.authorizationUri;
|
||||
}
|
||||
|
||||
public void setAuthorizationUri(String authorizationUri) {
|
||||
this.authorizationUri = authorizationUri;
|
||||
}
|
||||
|
||||
public String getTokenUri() {
|
||||
return this.tokenUri;
|
||||
}
|
||||
|
||||
public void setTokenUri(String tokenUri) {
|
||||
this.tokenUri = tokenUri;
|
||||
}
|
||||
|
||||
public String getUserInfoUri() {
|
||||
return this.userInfoUri;
|
||||
}
|
||||
|
||||
public void setUserInfoUri(String userInfoUri) {
|
||||
this.userInfoUri = userInfoUri;
|
||||
}
|
||||
|
||||
public String getUserNameAttributeName() {
|
||||
return this.userNameAttributeName;
|
||||
}
|
||||
|
||||
public void setUserNameAttributeName(String userNameAttributeName) {
|
||||
this.userNameAttributeName = userNameAttributeName;
|
||||
}
|
||||
|
||||
public String getJwkSetUri() {
|
||||
return this.jwkSetUri;
|
||||
}
|
||||
|
||||
public void setJwkSetUri(String jwkSetUri) {
|
||||
this.jwkSetUri = jwkSetUri;
|
||||
}
|
||||
|
||||
public String getClientName() {
|
||||
return this.clientName;
|
||||
}
|
||||
|
||||
public void setClientName(String clientName) {
|
||||
this.clientName = clientName;
|
||||
}
|
||||
}
|
|
@ -16,13 +16,11 @@
|
|||
package org.springframework.security.oauth2.client.web;
|
||||
|
||||
import org.springframework.security.oauth2.client.registration.ClientRegistration;
|
||||
import org.springframework.security.oauth2.client.registration.ClientRegistrationProperties;
|
||||
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
|
||||
import org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository;
|
||||
import org.springframework.security.oauth2.core.AuthorizationGrantType;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Joe Grandja
|
||||
|
@ -46,19 +44,18 @@ class TestUtil {
|
|||
}
|
||||
|
||||
static ClientRegistration googleClientRegistration(String redirectUri) {
|
||||
ClientRegistrationProperties clientRegistrationProperties = new ClientRegistrationProperties();
|
||||
clientRegistrationProperties.setRegistrationId(GOOGLE_REGISTRATION_ID);
|
||||
clientRegistrationProperties.setClientId("google-client-id");
|
||||
clientRegistrationProperties.setClientSecret("secret");
|
||||
clientRegistrationProperties.setAuthorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE);
|
||||
clientRegistrationProperties.setClientName("Google Client");
|
||||
clientRegistrationProperties.setAuthorizationUri("https://accounts.google.com/o/oauth2/auth");
|
||||
clientRegistrationProperties.setTokenUri("https://accounts.google.com/o/oauth2/token");
|
||||
clientRegistrationProperties.setUserInfoUri("https://www.googleapis.com/oauth2/v3/userinfo");
|
||||
clientRegistrationProperties.setJwkSetUri("https://www.googleapis.com/oauth2/v3/certs");
|
||||
clientRegistrationProperties.setRedirectUri(redirectUri);
|
||||
clientRegistrationProperties.setScope(Arrays.stream(new String[] {"openid", "email", "profile"}).collect(Collectors.toSet()));
|
||||
return new ClientRegistration.Builder(clientRegistrationProperties).build();
|
||||
return new ClientRegistration.Builder(GOOGLE_REGISTRATION_ID)
|
||||
.clientId("google-client-id")
|
||||
.clientSecret("secret")
|
||||
.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
|
||||
.clientName("Google Client")
|
||||
.authorizationUri("https://accounts.google.com/o/oauth2/auth")
|
||||
.tokenUri("https://accounts.google.com/o/oauth2/token")
|
||||
.userInfoUri("https://www.googleapis.com/oauth2/v3/userinfo")
|
||||
.jwkSetUri("https://www.googleapis.com/oauth2/v3/certs")
|
||||
.redirectUri(redirectUri)
|
||||
.scope("openid", "email", "profile")
|
||||
.build();
|
||||
}
|
||||
|
||||
static ClientRegistration githubClientRegistration() {
|
||||
|
@ -66,17 +63,16 @@ class TestUtil {
|
|||
}
|
||||
|
||||
static ClientRegistration githubClientRegistration(String redirectUri) {
|
||||
ClientRegistrationProperties clientRegistrationProperties = new ClientRegistrationProperties();
|
||||
clientRegistrationProperties.setRegistrationId(GITHUB_REGISTRATION_ID);
|
||||
clientRegistrationProperties.setClientId("github-client-id");
|
||||
clientRegistrationProperties.setClientSecret("secret");
|
||||
clientRegistrationProperties.setAuthorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE);
|
||||
clientRegistrationProperties.setClientName("GitHub Client");
|
||||
clientRegistrationProperties.setAuthorizationUri("https://github.com/login/oauth/authorize");
|
||||
clientRegistrationProperties.setTokenUri("https://github.com/login/oauth/access_token");
|
||||
clientRegistrationProperties.setUserInfoUri("https://api.github.com/user");
|
||||
clientRegistrationProperties.setRedirectUri(redirectUri);
|
||||
clientRegistrationProperties.setScope(Arrays.stream(new String[] {"user"}).collect(Collectors.toSet()));
|
||||
return new ClientRegistration.Builder(clientRegistrationProperties).build();
|
||||
return new ClientRegistration.Builder(GITHUB_REGISTRATION_ID)
|
||||
.clientId("github-client-id")
|
||||
.clientSecret("secret")
|
||||
.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
|
||||
.clientName("GitHub Client")
|
||||
.authorizationUri("https://github.com/login/oauth/authorize")
|
||||
.tokenUri("https://github.com/login/oauth/access_token")
|
||||
.userInfoUri("https://api.github.com/user")
|
||||
.redirectUri(redirectUri)
|
||||
.scope("user")
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue