|
@@ -24,6 +24,8 @@ import java.util.Map;
|
|
|
import org.springframework.security.authentication.AuthenticationProvider;
|
|
|
import org.springframework.security.core.Authentication;
|
|
|
import org.springframework.security.core.AuthenticationException;
|
|
|
+import org.springframework.security.crypto.factory.PasswordEncoderFactories;
|
|
|
+import org.springframework.security.crypto.password.PasswordEncoder;
|
|
|
import org.springframework.security.oauth2.core.AuthorizationGrantType;
|
|
|
import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
|
|
|
import org.springframework.security.oauth2.core.OAuth2Error;
|
|
@@ -56,6 +58,7 @@ public class OAuth2ClientAuthenticationProvider implements AuthenticationProvide
|
|
|
private static final OAuth2TokenType AUTHORIZATION_CODE_TOKEN_TYPE = new OAuth2TokenType(OAuth2ParameterNames.CODE);
|
|
|
private final RegisteredClientRepository registeredClientRepository;
|
|
|
private final OAuth2AuthorizationService authorizationService;
|
|
|
+ private PasswordEncoder passwordEncoder;
|
|
|
|
|
|
/**
|
|
|
* Constructs an {@code OAuth2ClientAuthenticationProvider} using the provided parameters.
|
|
@@ -69,6 +72,12 @@ public class OAuth2ClientAuthenticationProvider implements AuthenticationProvide
|
|
|
Assert.notNull(authorizationService, "authorizationService cannot be null");
|
|
|
this.registeredClientRepository = registeredClientRepository;
|
|
|
this.authorizationService = authorizationService;
|
|
|
+ this.passwordEncoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setPasswordEncoder(PasswordEncoder passwordEncoder) {
|
|
|
+ Assert.notNull(passwordEncoder, "passwordEncoder cannot be null");
|
|
|
+ this.passwordEncoder = passwordEncoder;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -91,8 +100,7 @@ public class OAuth2ClientAuthenticationProvider implements AuthenticationProvide
|
|
|
|
|
|
if (clientAuthentication.getCredentials() != null) {
|
|
|
String clientSecret = clientAuthentication.getCredentials().toString();
|
|
|
- // TODO Use PasswordEncoder.matches()
|
|
|
- if (!registeredClient.getClientSecret().equals(clientSecret)) {
|
|
|
+ if (!passwordEncoder.matches(clientSecret, registeredClient.getClientSecret())) {
|
|
|
throwInvalidClient();
|
|
|
}
|
|
|
authenticatedCredentials = true;
|