|
@@ -16,7 +16,11 @@
|
|
|
package org.springframework.security.oauth2.server.authorization.authentication;
|
|
|
|
|
|
import org.springframework.security.authentication.AuthenticationProvider;
|
|
|
+import org.springframework.security.core.Authentication;
|
|
|
import org.springframework.security.oauth2.core.AbstractOAuth2Token;
|
|
|
+import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
|
|
|
+import org.springframework.security.oauth2.core.OAuth2Error;
|
|
|
+import org.springframework.security.oauth2.core.OAuth2ErrorCodes;
|
|
|
import org.springframework.security.oauth2.core.OAuth2RefreshToken;
|
|
|
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
|
|
|
import org.springframework.security.oauth2.server.authorization.token.OAuth2AuthorizationCode;
|
|
@@ -34,6 +38,17 @@ final class OAuth2AuthenticationProviderUtils {
|
|
|
private OAuth2AuthenticationProviderUtils() {
|
|
|
}
|
|
|
|
|
|
+ static OAuth2ClientAuthenticationToken getAuthenticatedClientElseThrowInvalidClient(Authentication authentication) {
|
|
|
+ OAuth2ClientAuthenticationToken clientPrincipal = null;
|
|
|
+ if (OAuth2ClientAuthenticationToken.class.isAssignableFrom(authentication.getPrincipal().getClass())) {
|
|
|
+ clientPrincipal = (OAuth2ClientAuthenticationToken) authentication.getPrincipal();
|
|
|
+ }
|
|
|
+ if (clientPrincipal != null && clientPrincipal.isAuthenticated()) {
|
|
|
+ return clientPrincipal;
|
|
|
+ }
|
|
|
+ throw new OAuth2AuthenticationException(new OAuth2Error(OAuth2ErrorCodes.INVALID_CLIENT));
|
|
|
+ }
|
|
|
+
|
|
|
static <T extends AbstractOAuth2Token> OAuth2Authorization invalidate(
|
|
|
OAuth2Authorization authorization, T token) {
|
|
|
|