|
37 | 37 | import org.springframework.http.HttpStatus;
|
38 | 38 | import org.springframework.http.MediaType;
|
39 | 39 | import org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal;
|
| 40 | +import org.springframework.security.oauth2.core.OAuth2TokenIntrospectionClaimNames; |
40 | 41 | import org.springframework.web.reactive.function.client.ClientResponse;
|
41 | 42 | import org.springframework.web.reactive.function.client.WebClient;
|
42 | 43 |
|
@@ -106,18 +107,19 @@ public void authenticateWhenActiveTokenThenOk() throws Exception {
|
106 | 107 | SpringReactiveOpaqueTokenIntrospector introspectionClient = new SpringReactiveOpaqueTokenIntrospector(
|
107 | 108 | introspectUri, CLIENT_ID, CLIENT_SECRET);
|
108 | 109 | OAuth2AuthenticatedPrincipal authority = introspectionClient.introspect("token").block();
|
| 110 | + assertThat(authority).isNotNull(); |
109 | 111 | // @formatter:off
|
110 | 112 | assertThat(authority.getAttributes())
|
111 | 113 | .isNotNull()
|
112 |
| - .containsEntry(OAuth2IntrospectionClaimNames.ACTIVE, true) |
113 |
| - .containsEntry(OAuth2IntrospectionClaimNames.AUDIENCE, |
| 114 | + .containsEntry(OAuth2TokenIntrospectionClaimNames.ACTIVE, true) |
| 115 | + .containsEntry(OAuth2TokenIntrospectionClaimNames.AUD, |
114 | 116 | Arrays.asList("https://protected.example.net/resource"))
|
115 |
| - .containsEntry(OAuth2IntrospectionClaimNames.CLIENT_ID, "l238j323ds-23ij4") |
116 |
| - .containsEntry(OAuth2IntrospectionClaimNames.EXPIRES_AT, Instant.ofEpochSecond(1419356238)) |
117 |
| - .containsEntry(OAuth2IntrospectionClaimNames.ISSUER, "https://server.example.com/") |
118 |
| - .containsEntry(OAuth2IntrospectionClaimNames.SCOPE, Arrays.asList("read", "write", "dolphin")) |
119 |
| - .containsEntry(OAuth2IntrospectionClaimNames.SUBJECT, "Z5O3upPC88QrAjx00dis") |
120 |
| - .containsEntry(OAuth2IntrospectionClaimNames.USERNAME, "jdoe") |
| 117 | + .containsEntry(OAuth2TokenIntrospectionClaimNames.CLIENT_ID, "l238j323ds-23ij4") |
| 118 | + .containsEntry(OAuth2TokenIntrospectionClaimNames.EXP, Instant.ofEpochSecond(1419356238)) |
| 119 | + .containsEntry(OAuth2TokenIntrospectionClaimNames.ISS, "https://server.example.com/") |
| 120 | + .containsEntry(OAuth2TokenIntrospectionClaimNames.SCOPE, Arrays.asList("read", "write", "dolphin")) |
| 121 | + .containsEntry(OAuth2TokenIntrospectionClaimNames.SUB, "Z5O3upPC88QrAjx00dis") |
| 122 | + .containsEntry(OAuth2TokenIntrospectionClaimNames.USERNAME, "jdoe") |
121 | 123 | .containsEntry("extension_field", "twenty-seven");
|
122 | 124 | // @formatter:on
|
123 | 125 | }
|
@@ -149,21 +151,22 @@ public void authenticateWhenInactiveTokenThenInvalidToken() {
|
149 | 151 | @Test
|
150 | 152 | public void authenticateWhenActiveTokenThenParsesValuesInResponse() {
|
151 | 153 | Map<String, Object> introspectedValues = new HashMap<>();
|
152 |
| - introspectedValues.put(OAuth2IntrospectionClaimNames.ACTIVE, true); |
153 |
| - introspectedValues.put(OAuth2IntrospectionClaimNames.AUDIENCE, Arrays.asList("aud")); |
154 |
| - introspectedValues.put(OAuth2IntrospectionClaimNames.NOT_BEFORE, 29348723984L); |
| 154 | + introspectedValues.put(OAuth2TokenIntrospectionClaimNames.ACTIVE, true); |
| 155 | + introspectedValues.put(OAuth2TokenIntrospectionClaimNames.AUD, Arrays.asList("aud")); |
| 156 | + introspectedValues.put(OAuth2TokenIntrospectionClaimNames.NBF, 29348723984L); |
155 | 157 | WebClient webClient = mockResponse(introspectedValues);
|
156 | 158 | SpringReactiveOpaqueTokenIntrospector introspectionClient = new SpringReactiveOpaqueTokenIntrospector(
|
157 | 159 | INTROSPECTION_URL, webClient);
|
158 | 160 | OAuth2AuthenticatedPrincipal authority = introspectionClient.introspect("token").block();
|
| 161 | + assertThat(authority).isNotNull(); |
159 | 162 | // @formatter:off
|
160 | 163 | assertThat(authority.getAttributes())
|
161 | 164 | .isNotNull()
|
162 |
| - .containsEntry(OAuth2IntrospectionClaimNames.ACTIVE, true) |
163 |
| - .containsEntry(OAuth2IntrospectionClaimNames.AUDIENCE, Arrays.asList("aud")) |
164 |
| - .containsEntry(OAuth2IntrospectionClaimNames.NOT_BEFORE, Instant.ofEpochSecond(29348723984L)) |
165 |
| - .doesNotContainKey(OAuth2IntrospectionClaimNames.CLIENT_ID) |
166 |
| - .doesNotContainKey(OAuth2IntrospectionClaimNames.SCOPE); |
| 165 | + .containsEntry(OAuth2TokenIntrospectionClaimNames.ACTIVE, true) |
| 166 | + .containsEntry(OAuth2TokenIntrospectionClaimNames.AUD, Arrays.asList("aud")) |
| 167 | + .containsEntry(OAuth2TokenIntrospectionClaimNames.NBF, Instant.ofEpochSecond(29348723984L)) |
| 168 | + .doesNotContainKey(OAuth2TokenIntrospectionClaimNames.CLIENT_ID) |
| 169 | + .doesNotContainKey(OAuth2TokenIntrospectionClaimNames.SCOPE); |
167 | 170 | // @formatter:on
|
168 | 171 | }
|
169 | 172 |
|
@@ -234,6 +237,7 @@ private WebClient mockResponse(Map<String, Object> response) {
|
234 | 237 | return webClient;
|
235 | 238 | }
|
236 | 239 |
|
| 240 | + @SuppressWarnings("unchecked") |
237 | 241 | private Map<String, Object> toMap(String string) {
|
238 | 242 | try {
|
239 | 243 | return this.mapper.readValue(string, Map.class);
|
|
0 commit comments