Merge branch '7.0.x'
This commit is contained in:
+2
-3
@@ -40,11 +40,11 @@ import org.springframework.security.oauth2.server.authorization.settings.Authori
|
|||||||
import org.springframework.security.oauth2.server.authorization.web.OAuth2DeviceVerificationEndpointFilter;
|
import org.springframework.security.oauth2.server.authorization.web.OAuth2DeviceVerificationEndpointFilter;
|
||||||
import org.springframework.security.oauth2.server.authorization.web.authentication.OAuth2DeviceAuthorizationConsentAuthenticationConverter;
|
import org.springframework.security.oauth2.server.authorization.web.authentication.OAuth2DeviceAuthorizationConsentAuthenticationConverter;
|
||||||
import org.springframework.security.oauth2.server.authorization.web.authentication.OAuth2DeviceVerificationAuthenticationConverter;
|
import org.springframework.security.oauth2.server.authorization.web.authentication.OAuth2DeviceVerificationAuthenticationConverter;
|
||||||
|
import org.springframework.security.web.access.intercept.AuthorizationFilter;
|
||||||
import org.springframework.security.web.authentication.AuthenticationConverter;
|
import org.springframework.security.web.authentication.AuthenticationConverter;
|
||||||
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
|
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
|
||||||
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
|
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
|
||||||
import org.springframework.security.web.authentication.DelegatingAuthenticationConverter;
|
import org.springframework.security.web.authentication.DelegatingAuthenticationConverter;
|
||||||
import org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter;
|
|
||||||
import org.springframework.security.web.servlet.util.matcher.PathPatternRequestMatcher;
|
import org.springframework.security.web.servlet.util.matcher.PathPatternRequestMatcher;
|
||||||
import org.springframework.security.web.util.matcher.OrRequestMatcher;
|
import org.springframework.security.web.util.matcher.OrRequestMatcher;
|
||||||
import org.springframework.security.web.util.matcher.RequestMatcher;
|
import org.springframework.security.web.util.matcher.RequestMatcher;
|
||||||
@@ -279,8 +279,7 @@ public final class OAuth2DeviceVerificationEndpointConfigurer extends AbstractOA
|
|||||||
if (StringUtils.hasText(this.consentPage)) {
|
if (StringUtils.hasText(this.consentPage)) {
|
||||||
deviceVerificationEndpointFilter.setConsentPage(this.consentPage);
|
deviceVerificationEndpointFilter.setConsentPage(this.consentPage);
|
||||||
}
|
}
|
||||||
builder.addFilterBefore(postProcess(deviceVerificationEndpointFilter),
|
builder.addFilterAfter(postProcess(deviceVerificationEndpointFilter), AuthorizationFilter.class);
|
||||||
AbstractPreAuthenticatedProcessingFilter.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+2
-2
@@ -359,7 +359,7 @@ public class OAuth2DeviceCodeGrantTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestWhenDeviceAuthorizationConsentRequestUnauthenticatedThenBadRequest() throws Exception {
|
public void requestWhenDeviceAuthorizationConsentRequestUnauthenticatedThenUnauthorized() throws Exception {
|
||||||
this.spring.register(AuthorizationServerConfiguration.class).autowire();
|
this.spring.register(AuthorizationServerConfiguration.class).autowire();
|
||||||
|
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
@@ -392,7 +392,7 @@ public class OAuth2DeviceCodeGrantTests {
|
|||||||
// @formatter:off
|
// @formatter:off
|
||||||
this.mvc.perform(post(DEFAULT_DEVICE_VERIFICATION_ENDPOINT_URI)
|
this.mvc.perform(post(DEFAULT_DEVICE_VERIFICATION_ENDPOINT_URI)
|
||||||
.params(parameters))
|
.params(parameters))
|
||||||
.andExpect(status().isBadRequest());
|
.andExpect(status().isUnauthorized());
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-3
@@ -132,9 +132,7 @@ public final class OAuth2DeviceVerificationAuthenticationProvider implements Aut
|
|||||||
if (this.logger.isTraceEnabled()) {
|
if (this.logger.isTraceEnabled()) {
|
||||||
this.logger.trace("Did not authenticate device verification request since principal not authenticated");
|
this.logger.trace("Did not authenticate device verification request since principal not authenticated");
|
||||||
}
|
}
|
||||||
// Return the device verification request as-is where isAuthenticated() is
|
throw new OAuth2AuthenticationException(OAuth2ErrorCodes.INVALID_REQUEST);
|
||||||
// false
|
|
||||||
return deviceVerificationAuthentication;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RegisteredClient registeredClient = this.registeredClientRepository
|
RegisteredClient registeredClient = this.registeredClientRepository
|
||||||
|
|||||||
-9
@@ -161,15 +161,6 @@ public final class OAuth2DeviceVerificationEndpointFilter extends OncePerRequest
|
|||||||
}
|
}
|
||||||
|
|
||||||
Authentication authenticationResult = this.authenticationManager.authenticate(authentication);
|
Authentication authenticationResult = this.authenticationManager.authenticate(authentication);
|
||||||
if (!authenticationResult.isAuthenticated()) {
|
|
||||||
// If the Principal (Resource Owner) is not authenticated then pass
|
|
||||||
// through the chain
|
|
||||||
// with the expectation that the authentication process will commence via
|
|
||||||
// AuthenticationEntryPoint
|
|
||||||
filterChain.doFilter(request, response);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (authenticationResult instanceof OAuth2DeviceAuthorizationConsentAuthenticationToken) {
|
if (authenticationResult instanceof OAuth2DeviceAuthorizationConsentAuthenticationToken) {
|
||||||
if (this.logger.isTraceEnabled()) {
|
if (this.logger.isTraceEnabled()) {
|
||||||
this.logger.trace("Device authorization consent is required");
|
this.logger.trace("Device authorization consent is required");
|
||||||
|
|||||||
+13
-7
@@ -227,7 +227,7 @@ public class OAuth2DeviceVerificationAuthenticationProviderTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void authenticateWhenPrincipalNotAuthenticatedThenReturnUnauthenticated() {
|
public void authenticateWhenPrincipalNotAuthenticatedThenThrowOAuth2AuthenticationException() {
|
||||||
RegisteredClient registeredClient = TestRegisteredClients.registeredClient().build();
|
RegisteredClient registeredClient = TestRegisteredClients.registeredClient().build();
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
OAuth2Authorization authorization = TestOAuth2Authorizations
|
OAuth2Authorization authorization = TestOAuth2Authorizations
|
||||||
@@ -237,15 +237,21 @@ public class OAuth2DeviceVerificationAuthenticationProviderTests {
|
|||||||
.attribute(OAuth2ParameterNames.SCOPE, registeredClient.getScopes())
|
.attribute(OAuth2ParameterNames.SCOPE, registeredClient.getScopes())
|
||||||
.build();
|
.build();
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
TestingAuthenticationToken principal = new TestingAuthenticationToken("user", null);
|
TestingAuthenticationToken principal = new TestingAuthenticationToken("anonymous", null);
|
||||||
|
principal.setAuthenticated(false);
|
||||||
Authentication authentication = new OAuth2DeviceVerificationAuthenticationToken(principal, USER_CODE,
|
Authentication authentication = new OAuth2DeviceVerificationAuthenticationToken(principal, USER_CODE,
|
||||||
Collections.emptyMap());
|
Collections.emptyMap());
|
||||||
given(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class))).willReturn(authorization);
|
given(this.authorizationService.findByToken(eq(USER_CODE),
|
||||||
|
eq(OAuth2DeviceVerificationAuthenticationProvider.USER_CODE_TOKEN_TYPE)))
|
||||||
|
.willReturn(authorization);
|
||||||
|
|
||||||
OAuth2DeviceVerificationAuthenticationToken authenticationResult = (OAuth2DeviceVerificationAuthenticationToken) this.authenticationProvider
|
// @formatter:off
|
||||||
.authenticate(authentication);
|
assertThatExceptionOfType(OAuth2AuthenticationException.class)
|
||||||
assertThat(authenticationResult).isEqualTo(authentication);
|
.isThrownBy(() -> this.authenticationProvider.authenticate(authentication))
|
||||||
assertThat(authenticationResult.isAuthenticated()).isFalse();
|
.extracting(OAuth2AuthenticationException::getError)
|
||||||
|
.extracting(OAuth2Error::getErrorCode)
|
||||||
|
.isEqualTo(OAuth2ErrorCodes.INVALID_REQUEST);
|
||||||
|
// @formatter:on
|
||||||
|
|
||||||
verify(this.authorizationService).findByToken(USER_CODE,
|
verify(this.authorizationService).findByToken(USER_CODE,
|
||||||
OAuth2DeviceVerificationAuthenticationProvider.USER_CODE_TOKEN_TYPE);
|
OAuth2DeviceVerificationAuthenticationProvider.USER_CODE_TOKEN_TYPE);
|
||||||
|
|||||||
-15
@@ -166,21 +166,6 @@ public class OAuth2DeviceVerificationEndpointFilterTests {
|
|||||||
verifyNoInteractions(this.authenticationManager);
|
verifyNoInteractions(this.authenticationManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void doFilterWhenUnauthenticatedThenPassThrough() throws Exception {
|
|
||||||
TestingAuthenticationToken unauthenticatedResult = new TestingAuthenticationToken("user", null);
|
|
||||||
given(this.authenticationManager.authenticate(any(Authentication.class))).willReturn(unauthenticatedResult);
|
|
||||||
|
|
||||||
MockHttpServletRequest request = createRequest();
|
|
||||||
request.addParameter(OAuth2ParameterNames.USER_CODE, USER_CODE);
|
|
||||||
updateQueryString(request);
|
|
||||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
|
||||||
FilterChain filterChain = mock(FilterChain.class);
|
|
||||||
this.filter.doFilter(request, response, filterChain);
|
|
||||||
verify(this.authenticationManager).authenticate(any(Authentication.class));
|
|
||||||
verify(filterChain).doFilter(request, response);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void doFilterWhenDeviceAuthorizationConsentRequestThenSuccess() throws Exception {
|
public void doFilterWhenDeviceAuthorizationConsentRequestThenSuccess() throws Exception {
|
||||||
Authentication authenticationResult = createDeviceVerificationAuthentication();
|
Authentication authenticationResult = createDeviceVerificationAuthentication();
|
||||||
|
|||||||
Reference in New Issue
Block a user