|
@@ -38,10 +38,6 @@ import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.http.RequestEntity;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
-import org.springframework.security.oauth2.server.resource.introspection.NimbusOAuth2TokenIntrospectionClient;
|
|
|
-import org.springframework.security.oauth2.server.resource.introspection.OAuth2IntrospectionClaimNames;
|
|
|
-import org.springframework.security.oauth2.server.resource.introspection.OAuth2IntrospectionException;
|
|
|
-import org.springframework.security.oauth2.server.resource.introspection.OAuth2TokenIntrospectionClient;
|
|
|
import org.springframework.web.client.RestOperations;
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
@@ -61,9 +57,9 @@ import static org.springframework.security.oauth2.server.resource.introspection.
|
|
|
import static org.springframework.security.oauth2.server.resource.introspection.OAuth2IntrospectionClaimNames.USERNAME;
|
|
|
|
|
|
/**
|
|
|
- * Tests for {@link NimbusOAuth2TokenIntrospectionClient}
|
|
|
+ * Tests for {@link NimbusOpaqueTokenIntrospector}
|
|
|
*/
|
|
|
-public class NimbusOAuth2TokenIntrospectionClientTests {
|
|
|
+public class NimbusOpaqueTokenIntrospectorTests {
|
|
|
|
|
|
private static final String INTROSPECTION_URL = "https://server.example.com";
|
|
|
private static final String CLIENT_ID = "client";
|
|
@@ -114,8 +110,8 @@ public class NimbusOAuth2TokenIntrospectionClientTests {
|
|
|
server.setDispatcher(requiresAuth(CLIENT_ID, CLIENT_SECRET, ACTIVE_RESPONSE));
|
|
|
|
|
|
String introspectUri = server.url("/introspect").toString();
|
|
|
- OAuth2TokenIntrospectionClient introspectionClient =
|
|
|
- new NimbusOAuth2TokenIntrospectionClient(introspectUri, CLIENT_ID, CLIENT_SECRET);
|
|
|
+ OpaqueTokenIntrospector introspectionClient =
|
|
|
+ new NimbusOpaqueTokenIntrospector(introspectUri, CLIENT_ID, CLIENT_SECRET);
|
|
|
|
|
|
Map<String, Object> attributes = introspectionClient.introspect("token");
|
|
|
assertThat(attributes)
|
|
@@ -138,8 +134,8 @@ public class NimbusOAuth2TokenIntrospectionClientTests {
|
|
|
server.setDispatcher(requiresAuth(CLIENT_ID, CLIENT_SECRET, ACTIVE_RESPONSE));
|
|
|
|
|
|
String introspectUri = server.url("/introspect").toString();
|
|
|
- OAuth2TokenIntrospectionClient introspectionClient =
|
|
|
- new NimbusOAuth2TokenIntrospectionClient(introspectUri, CLIENT_ID, "wrong");
|
|
|
+ OpaqueTokenIntrospector introspectionClient =
|
|
|
+ new NimbusOpaqueTokenIntrospector(introspectUri, CLIENT_ID, "wrong");
|
|
|
|
|
|
assertThatCode(() -> introspectionClient.introspect("token"))
|
|
|
.isInstanceOf(OAuth2IntrospectionException.class);
|
|
@@ -149,7 +145,7 @@ public class NimbusOAuth2TokenIntrospectionClientTests {
|
|
|
@Test
|
|
|
public void introspectWhenInactiveTokenThenInvalidToken() {
|
|
|
RestOperations restOperations = mock(RestOperations.class);
|
|
|
- OAuth2TokenIntrospectionClient introspectionClient = new NimbusOAuth2TokenIntrospectionClient(INTROSPECTION_URL, restOperations);
|
|
|
+ OpaqueTokenIntrospector introspectionClient = new NimbusOpaqueTokenIntrospector(INTROSPECTION_URL, restOperations);
|
|
|
when(restOperations.exchange(any(RequestEntity.class), eq(String.class)))
|
|
|
.thenReturn(INACTIVE);
|
|
|
|
|
@@ -167,8 +163,8 @@ public class NimbusOAuth2TokenIntrospectionClientTests {
|
|
|
introspectedValues.put(NOT_BEFORE, 29348723984L);
|
|
|
|
|
|
RestOperations restOperations = mock(RestOperations.class);
|
|
|
- OAuth2TokenIntrospectionClient introspectionClient =
|
|
|
- new NimbusOAuth2TokenIntrospectionClient(INTROSPECTION_URL, restOperations);
|
|
|
+ OpaqueTokenIntrospector introspectionClient =
|
|
|
+ new NimbusOpaqueTokenIntrospector(INTROSPECTION_URL, restOperations);
|
|
|
when(restOperations.exchange(any(RequestEntity.class), eq(String.class)))
|
|
|
.thenReturn(response(new JSONObject(introspectedValues).toJSONString()));
|
|
|
|
|
@@ -185,8 +181,8 @@ public class NimbusOAuth2TokenIntrospectionClientTests {
|
|
|
@Test
|
|
|
public void introspectWhenIntrospectionEndpointThrowsExceptionThenInvalidToken() {
|
|
|
RestOperations restOperations = mock(RestOperations.class);
|
|
|
- OAuth2TokenIntrospectionClient introspectionClient =
|
|
|
- new NimbusOAuth2TokenIntrospectionClient(INTROSPECTION_URL, restOperations);
|
|
|
+ OpaqueTokenIntrospector introspectionClient =
|
|
|
+ new NimbusOpaqueTokenIntrospector(INTROSPECTION_URL, restOperations);
|
|
|
when(restOperations.exchange(any(RequestEntity.class), eq(String.class)))
|
|
|
.thenThrow(new IllegalStateException("server was unresponsive"));
|
|
|
|
|
@@ -200,8 +196,8 @@ public class NimbusOAuth2TokenIntrospectionClientTests {
|
|
|
@Test
|
|
|
public void introspectWhenIntrospectionEndpointReturnsMalformedResponseThenInvalidToken() {
|
|
|
RestOperations restOperations = mock(RestOperations.class);
|
|
|
- OAuth2TokenIntrospectionClient introspectionClient =
|
|
|
- new NimbusOAuth2TokenIntrospectionClient(INTROSPECTION_URL, restOperations);
|
|
|
+ OpaqueTokenIntrospector introspectionClient =
|
|
|
+ new NimbusOpaqueTokenIntrospector(INTROSPECTION_URL, restOperations);
|
|
|
when(restOperations.exchange(any(RequestEntity.class), eq(String.class)))
|
|
|
.thenReturn(response("malformed"));
|
|
|
|
|
@@ -212,8 +208,8 @@ public class NimbusOAuth2TokenIntrospectionClientTests {
|
|
|
@Test
|
|
|
public void introspectWhenIntrospectionTokenReturnsInvalidResponseThenInvalidToken() {
|
|
|
RestOperations restOperations = mock(RestOperations.class);
|
|
|
- OAuth2TokenIntrospectionClient introspectionClient =
|
|
|
- new NimbusOAuth2TokenIntrospectionClient(INTROSPECTION_URL, restOperations);
|
|
|
+ OpaqueTokenIntrospector introspectionClient =
|
|
|
+ new NimbusOpaqueTokenIntrospector(INTROSPECTION_URL, restOperations);
|
|
|
when(restOperations.exchange(any(RequestEntity.class), eq(String.class)))
|
|
|
.thenReturn(INVALID);
|
|
|
|
|
@@ -224,8 +220,8 @@ public class NimbusOAuth2TokenIntrospectionClientTests {
|
|
|
@Test
|
|
|
public void introspectWhenIntrospectionTokenReturnsMalformedIssuerResponseThenInvalidToken() {
|
|
|
RestOperations restOperations = mock(RestOperations.class);
|
|
|
- OAuth2TokenIntrospectionClient introspectionClient =
|
|
|
- new NimbusOAuth2TokenIntrospectionClient(INTROSPECTION_URL, restOperations);
|
|
|
+ OpaqueTokenIntrospector introspectionClient =
|
|
|
+ new NimbusOpaqueTokenIntrospector(INTROSPECTION_URL, restOperations);
|
|
|
when(restOperations.exchange(any(RequestEntity.class), eq(String.class)))
|
|
|
.thenReturn(MALFORMED_ISSUER);
|
|
|
|
|
@@ -235,25 +231,25 @@ public class NimbusOAuth2TokenIntrospectionClientTests {
|
|
|
|
|
|
@Test
|
|
|
public void constructorWhenIntrospectionUriIsNullThenIllegalArgumentException() {
|
|
|
- assertThatCode(() -> new NimbusOAuth2TokenIntrospectionClient(null, CLIENT_ID, CLIENT_SECRET))
|
|
|
+ assertThatCode(() -> new NimbusOpaqueTokenIntrospector(null, CLIENT_ID, CLIENT_SECRET))
|
|
|
.isInstanceOf(IllegalArgumentException.class);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void constructorWhenClientIdIsNullThenIllegalArgumentException() {
|
|
|
- assertThatCode(() -> new NimbusOAuth2TokenIntrospectionClient(INTROSPECTION_URL, null, CLIENT_SECRET))
|
|
|
+ assertThatCode(() -> new NimbusOpaqueTokenIntrospector(INTROSPECTION_URL, null, CLIENT_SECRET))
|
|
|
.isInstanceOf(IllegalArgumentException.class);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void constructorWhenClientSecretIsNullThenIllegalArgumentException() {
|
|
|
- assertThatCode(() -> new NimbusOAuth2TokenIntrospectionClient(INTROSPECTION_URL, CLIENT_ID, null))
|
|
|
+ assertThatCode(() -> new NimbusOpaqueTokenIntrospector(INTROSPECTION_URL, CLIENT_ID, null))
|
|
|
.isInstanceOf(IllegalArgumentException.class);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void constructorWhenRestOperationsIsNullThenIllegalArgumentException() {
|
|
|
- assertThatCode(() -> new NimbusOAuth2TokenIntrospectionClient(INTROSPECTION_URL, null))
|
|
|
+ assertThatCode(() -> new NimbusOpaqueTokenIntrospector(INTROSPECTION_URL, null))
|
|
|
.isInstanceOf(IllegalArgumentException.class);
|
|
|
}
|
|
|
|
|
@@ -261,7 +257,7 @@ public class NimbusOAuth2TokenIntrospectionClientTests {
|
|
|
public void setRequestEntityConverterWhenConverterIsNullThenExceptionIsThrown() {
|
|
|
RestOperations restOperations = mock(RestOperations.class);
|
|
|
|
|
|
- NimbusOAuth2TokenIntrospectionClient introspectionClient = new NimbusOAuth2TokenIntrospectionClient(
|
|
|
+ NimbusOpaqueTokenIntrospector introspectionClient = new NimbusOpaqueTokenIntrospector(
|
|
|
INTROSPECTION_URL, restOperations
|
|
|
);
|
|
|
|
|
@@ -278,7 +274,7 @@ public class NimbusOAuth2TokenIntrospectionClientTests {
|
|
|
String tokenToIntrospect = "some token";
|
|
|
when(requestEntityConverter.convert(tokenToIntrospect)).thenReturn(requestEntity);
|
|
|
when(restOperations.exchange(requestEntity, String.class)).thenReturn(ACTIVE);
|
|
|
- NimbusOAuth2TokenIntrospectionClient introspectionClient = new NimbusOAuth2TokenIntrospectionClient(
|
|
|
+ NimbusOpaqueTokenIntrospector introspectionClient = new NimbusOpaqueTokenIntrospector(
|
|
|
INTROSPECTION_URL, restOperations
|
|
|
);
|
|
|
introspectionClient.setRequestEntityConverter(requestEntityConverter);
|