Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Opaque Token Validation Support for Servlet Web Application Type #185

Merged
merged 105 commits into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
5d86f86
fix: pom.xml to reduce vulnerabilities
snyk-bot Sep 9, 2020
9020e89
add new property to OktaOAuth2Properties
arvindkrishnakumar-okta Sep 10, 2020
e1f1695
updates
arvindkrishnakumar-okta Sep 10, 2020
84c3bf8
added application properties with logging config
arvindkrishnakumar-okta Sep 10, 2020
275dc24
removed unused variable - pmd violation
arvindkrishnakumar-okta Sep 10, 2020
d384df4
added custom opaque token introspector based off on nimbus oaque toke…
arvindkrishnakumar-okta Sep 10, 2020
c5f78ef
updated per review comments
arvindkrishnakumar-okta Sep 10, 2020
3d9ca2b
minor refactor
arvindkrishnakumar-okta Sep 10, 2020
65879e7
minor refactor
arvindkrishnakumar-okta Sep 10, 2020
22121b1
fixed pmd violations
arvindkrishnakumar-okta Sep 10, 2020
bf4a5d6
fixed pmd violations
arvindkrishnakumar-okta Sep 10, 2020
5792bc0
fixed pmd violations
arvindkrishnakumar-okta Sep 10, 2020
65abd6b
updates per comments
arvindkrishnakumar-okta Sep 10, 2020
9707f2a
removed application.properties
arvindkrishnakumar-okta Sep 10, 2020
5d51036
updated javadoc comment for opaque
arvindkrishnakumar-okta Sep 10, 2020
3ee0d7d
updated javadoc comment for opaque
arvindkrishnakumar-okta Sep 10, 2020
44c3597
updates per review comments
arvindkrishnakumar-okta Sep 10, 2020
d2363bf
removed okta opaque token introspection class and refactored around it
arvindkrishnakumar-okta Sep 10, 2020
d936e5f
minor refactoring
arvindkrishnakumar-okta Sep 10, 2020
2ba8a26
updates
arvindkrishnakumar-okta Sep 11, 2020
a05d2a4
updates
arvindkrishnakumar-okta Sep 11, 2020
a5c2fd4
fix tests
arvindkrishnakumar-okta Sep 11, 2020
873c527
fix tests
arvindkrishnakumar-okta Sep 11, 2020
ba13ab6
fix tests
arvindkrishnakumar-okta Sep 11, 2020
95e9781
refactored
arvindkrishnakumar-okta Sep 11, 2020
489f956
fix tests
arvindkrishnakumar-okta Sep 11, 2020
e60bc56
fix tests
arvindkrishnakumar-okta Sep 11, 2020
4b85138
refactor
arvindkrishnakumar-okta Sep 11, 2020
f3fd8e7
refactoring/cleanup
arvindkrishnakumar-okta Sep 11, 2020
daafbef
reverted changes to AutoConfigConditionalTest
arvindkrishnakumar-okta Sep 11, 2020
ccc4b92
Merge https://github.com/okta/okta-spring-boot into add_opaque_token_…
arvindkrishnakumar-okta Sep 11, 2020
a393db4
fix tests
arvindkrishnakumar-okta Sep 11, 2020
c22d216
add custom opaque token conditional
arvindkrishnakumar-okta Sep 11, 2020
5c92761
add licence header to new class
arvindkrishnakumar-okta Sep 12, 2020
15306de
refactoring done
arvindkrishnakumar-okta Sep 12, 2020
b803f01
minor refactor
arvindkrishnakumar-okta Sep 14, 2020
177e4f4
impl isRootOrgIssuer method
arvindkrishnakumar-okta Sep 14, 2020
f0a0d8f
minor refactoring
arvindkrishnakumar-okta Sep 16, 2020
d6546ba
added customizer that can configure jwt or opaque flows conditionally…
arvindkrishnakumar-okta Sep 16, 2020
062f8bf
added code snippet to readme on how to add custom claims to jwt acces…
arvindkrishnakumar-okta Sep 2, 2020
f731d37
update to code snippet
arvindkrishnakumar-okta Sep 2, 2020
8941160
update README
arvindkrishnakumar-okta Sep 2, 2020
ec23e62
update README
arvindkrishnakumar-okta Sep 2, 2020
6151511
update README
arvindkrishnakumar-okta Sep 2, 2020
41d876b
Update README.md
arvindkrishnakumar-okta Sep 18, 2020
548bbd2
Update README.md
arvindkrishnakumar-okta Sep 18, 2020
9a946e2
Update README.md
arvindkrishnakumar-okta Sep 18, 2020
f542d64
Update README.md
arvindkrishnakumar-okta Sep 21, 2020
55675d4
Update README.md
arvindkrishnakumar-okta Sep 21, 2020
45fdede
updates to work with both jwt and opaque cases plus root org detection
arvindkrishnakumar-okta Sep 25, 2020
335e5ec
fix findbug error
arvindkrishnakumar-okta Sep 25, 2020
0fb2a71
minor refactor
arvindkrishnakumar-okta Sep 25, 2020
a699262
bumped spring boot to v2.3.4.RELEASE
arvindkrishnakumar-okta Sep 25, 2020
5664fd3
added opaque token custom group claim converter
arvindkrishnakumar-okta Sep 28, 2020
75f7636
Update README.md
arvindkrishnakumar-okta Sep 23, 2020
a9f3ec2
Update README.md
arvindkrishnakumar-okta Sep 23, 2020
9cc9c32
Update README.md
arvindkrishnakumar-okta Sep 28, 2020
19cbb59
Update README.md
arvindkrishnakumar-okta Sep 28, 2020
0f6217e
Update README.md
arvindkrishnakumar-okta Sep 28, 2020
ba1994a
Update README.md
arvindkrishnakumar-okta Sep 28, 2020
fca8b6e
Update README.md
arvindkrishnakumar-okta Sep 28, 2020
5ad5ac4
Update README.md
arvindkrishnakumar-okta Sep 28, 2020
f0c392d
Update README.md
arvindkrishnakumar-okta Sep 28, 2020
0b19761
Update README.md
arvindkrishnakumar-okta Sep 28, 2020
eac495b
Update README.md
arvindkrishnakumar-okta Sep 23, 2020
4b5c98e
Update README.md
arvindkrishnakumar-okta Sep 23, 2020
4a9dc26
Update README.md
arvindkrishnakumar-okta Sep 23, 2020
7561915
Update README.md
arvindkrishnakumar-okta Sep 23, 2020
15e013e
Update README.md
arvindkrishnakumar-okta Sep 23, 2020
188adfa
Update README.md
arvindkrishnakumar-okta Sep 28, 2020
65cf376
Update README.md
arvindkrishnakumar-okta Sep 28, 2020
2f3c97b
Update README.md
arvindkrishnakumar-okta Sep 28, 2020
74f229e
Update README.md
arvindkrishnakumar-okta Sep 28, 2020
a56578d
Update README.md
arvindkrishnakumar-okta Sep 28, 2020
796ec4a
Update README.md
arvindkrishnakumar-okta Sep 28, 2020
63f64d0
Improve Quickstart steps to be numbers
Sep 28, 2020
7143c71
Add link to Spring Security issue
Sep 28, 2020
7429fbc
fix: readme typo
robertjd Oct 1, 2020
d90629b
Add note in readme about the orgUrl property
bdemers Oct 5, 2020
79c66f9
Fixing formatting issues
bdemers Oct 5, 2020
50654be
fix: pom.xml to reduce vulnerabilities
snyk-bot Sep 19, 2020
08c81a0
Merge https://github.com/okta/okta-spring-boot into add_opaque_token_…
arvindkrishnakumar-okta Oct 5, 2020
a8979e4
fix some review comments
arvindkrishnakumar-okta Oct 5, 2020
f215abf
fixed review comments
arvindkrishnakumar-okta Oct 6, 2020
13f637a
fixed review comments
arvindkrishnakumar-okta Oct 7, 2020
b1b2b5c
added logging
arvindkrishnakumar-okta Oct 7, 2020
de58e94
review comments addressed
arvindkrishnakumar-okta Oct 7, 2020
50cc50b
added test for missing client secret in OktaOAuth2PropertiesMappingEn…
arvindkrishnakumar-okta Oct 7, 2020
07671b8
added UserAgent header to resttemplate used in OpaqueTokenIntrospecti…
arvindkrishnakumar-okta Oct 8, 2020
fed0000
used an alternate constructor for NimbusOpaqueTokenIntrospector
arvindkrishnakumar-okta Oct 8, 2020
83a986b
cleanup
arvindkrishnakumar-okta Oct 8, 2020
0f472c3
cleanup
arvindkrishnakumar-okta Oct 8, 2020
8476284
review comments addressed
arvindkrishnakumar-okta Oct 8, 2020
99ad9d6
added opaque token support for Reactive/Webflux case as well
arvindkrishnakumar-okta Oct 8, 2020
0b7bdbf
minor refactor
arvindkrishnakumar-okta Oct 9, 2020
249e562
reverted unintentional import removal
arvindkrishnakumar-okta Oct 9, 2020
64a14ae
minor refactoring
arvindkrishnakumar-okta Oct 9, 2020
d757e38
reverted changes done for opaque token support to Reactive/webflux ap…
arvindkrishnakumar-okta Oct 12, 2020
5e1481a
Ensuring the Okta Env Post Processor only sets valid properties
bdemers Oct 12, 2020
dc6cd54
addressed review comments
arvindkrishnakumar-okta Oct 12, 2020
8a4293b
Revert change that increases scope of var
bdemers Oct 13, 2020
6f33aa9
Updated tests to reflect previous condition (custom as support only)
bdemers Oct 13, 2020
a3b454c
added more unit tests to cover all possible resource server config co…
arvindkrishnakumar-okta Oct 14, 2020
606e027
Update test method names
bdemers Oct 14, 2020
e77aec3
minor linting fixes
bdemers Oct 14, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@
package com.okta.spring.boot.oauth;

import com.okta.spring.boot.oauth.config.OktaOAuth2Properties;
import com.okta.spring.boot.oauth.http.UserAgentRequestInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.security.oauth2.resource.OAuth2ResourceServerProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.http.converter.FormHttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.oauth2.client.http.OAuth2ErrorResponseErrorHandler;
import org.springframework.security.oauth2.client.oidc.userinfo.OidcUserRequest;
import org.springframework.security.oauth2.client.oidc.web.logout.OidcClientInitiatedLogoutSuccessHandler;
import org.springframework.security.oauth2.client.registration.ClientRegistration;
Expand All @@ -33,8 +38,11 @@
import org.springframework.security.oauth2.client.userinfo.OAuth2UserService;
import org.springframework.security.oauth2.core.oidc.user.OidcUser;
import org.springframework.security.oauth2.core.user.OAuth2User;
import org.springframework.security.oauth2.server.resource.introspection.OpaqueTokenIntrospector;
import org.springframework.web.client.RestTemplate;

import java.net.URI;
import java.util.Arrays;
import java.util.Collection;

@Configuration
Expand Down Expand Up @@ -65,4 +73,21 @@ OAuth2UserService<OAuth2UserRequest, OAuth2User> oAuth2UserService(Collection<Au
OAuth2UserService<OidcUserRequest, OidcUser> oidcUserService(Collection<AuthoritiesProvider> authoritiesProviders) {
return new OktaOidcUserService(oAuth2UserService(authoritiesProviders), authoritiesProviders);
}

@Bean
@ConditionalOnProperty(name="okta.oauth2.opaque", havingValue="true")
OpaqueTokenIntrospector oktaOpaqueTokenIntrospector(OktaOAuth2Properties oktaOAuth2Properties,
OAuth2ResourceServerProperties oAuth2ResourceServerProperties) {
RestTemplate restTemplate = new RestTemplate(Arrays.asList(
new FormHttpMessageConverter(),
new StringHttpMessageConverter()));
restTemplate.setErrorHandler(new OAuth2ErrorResponseErrorHandler());
restTemplate.getInterceptors().add(new UserAgentRequestInterceptor());
arvindkrishnakumar-okta marked this conversation as resolved.
Show resolved Hide resolved

return new OktaOpaqueTokenIntrospector(
oAuth2ResourceServerProperties.getOpaquetoken().getIntrospectionUri(),
oktaOAuth2Properties.getClientId(),
oktaOAuth2Properties.getClientSecret(),
restTemplate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
*/
package com.okta.spring.boot.oauth;

import com.okta.commons.configcheck.ConfigurationValidator;
import com.okta.spring.boot.oauth.config.OktaOAuth2Properties;
import com.okta.spring.boot.oauth.http.UserAgentRequestInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties;
import org.springframework.boot.autoconfigure.security.oauth2.resource.OAuth2ResourceServerProperties;
import org.springframework.context.ApplicationContext;
Expand Down Expand Up @@ -69,11 +71,19 @@ public void init(HttpSecurity http) throws Exception {
// resource server configuration
if (!context.getBeansOfType(OAuth2ResourceServerProperties.class).isEmpty()) {
OAuth2ResourceServerProperties resourceServerProperties = context.getBean(OAuth2ResourceServerProperties.class);
if (!isEmpty(resourceServerProperties.getJwt().getIssuerUri())) {
// configure Okta specific auth converter (extracts authorities from `groupsClaim`
configureResourceServer(http, oktaOAuth2Properties);
} else {
log.debug("OAuth resource server not configured due to missing issuer property");

log.debug("isRootOrgIssuer(resourceServerProperties.getJwt().getIssuerUri())?: {}", isRootOrgIssuer(resourceServerProperties.getJwt().getIssuerUri()));

try {
context.getBean(OktaOpaqueTokenIntrospector.class);

log.debug("Configuring resource server for Opaque Token validation");
configureResourceServerWithOpaqueTokenValidation(http, context);
} catch (NoSuchBeanDefinitionException e) {
if (!isEmpty(resourceServerProperties.getJwt().getIssuerUri())) {
log.debug("Configuring resource server for JWT validation");
configureResourceServerWithJwtValidation(http, oktaOAuth2Properties);
}
}
} else {
log.debug("OAuth resource server not configured due to missing OAuth2ResourceServerProperties bean");
Expand All @@ -92,10 +102,16 @@ private void configureLogin(HttpSecurity http, OktaOAuth2Properties oktaOAuth2Pr
}
}

private void configureResourceServer(HttpSecurity http, OktaOAuth2Properties oktaOAuth2Properties) throws Exception {
private void configureResourceServerWithJwtValidation(HttpSecurity http, OktaOAuth2Properties oktaOAuth2Properties) throws Exception {

http.oauth2ResourceServer()
.jwt().jwtAuthenticationConverter(new OktaJwtAuthenticationConverter(oktaOAuth2Properties.getGroupsClaim()));
}

private void configureResourceServerWithOpaqueTokenValidation(HttpSecurity http, ApplicationContext context) throws Exception {

http.oauth2ResourceServer()
.jwt().jwtAuthenticationConverter(new OktaJwtAuthenticationConverter(oktaOAuth2Properties.getGroupsClaim()));
.opaqueToken().introspector(context.getBean(OktaOpaqueTokenIntrospector.class));
}

private OAuth2AccessTokenResponseClient<OAuth2AuthorizationCodeGrantRequest> accessTokenResponseClient() {
Expand All @@ -110,4 +126,13 @@ private OAuth2AccessTokenResponseClient<OAuth2AuthorizationCodeGrantRequest> acc

return accessTokenResponseClient;
}

private boolean isRootOrgIssuer(String issuerUri) {
try {
ConfigurationValidator.assertOrgUrl(issuerUri);
arvindkrishnakumar-okta marked this conversation as resolved.
Show resolved Hide resolved
} catch (IllegalArgumentException e) {
return false;
}
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
/*
* Copyright 2020-Present Okta, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.okta.spring.boot.oauth;

import com.nimbusds.oauth2.sdk.TokenIntrospectionResponse;
import com.nimbusds.oauth2.sdk.TokenIntrospectionSuccessResponse;
import com.nimbusds.oauth2.sdk.http.HTTPResponse;
import com.nimbusds.oauth2.sdk.id.Audience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.convert.converter.Converter;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrincipal;
import org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal;
import org.springframework.security.oauth2.server.resource.introspection.BadOpaqueTokenException;
import org.springframework.security.oauth2.server.resource.introspection.OAuth2IntrospectionException;
import org.springframework.security.oauth2.server.resource.introspection.OpaqueTokenIntrospector;
import org.springframework.util.Assert;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestOperations;

import java.net.URI;
import java.net.URL;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
* Okta's implementation of Spring security's interface {@link OpaqueTokenIntrospector} based on
* {@link org.springframework.security.oauth2.server.resource.introspection.NimbusOpaqueTokenIntrospector}.
*/
public class OktaOpaqueTokenIntrospector implements OpaqueTokenIntrospector {
arvindkrishnakumar-okta marked this conversation as resolved.
Show resolved Hide resolved

private static final Logger log = LoggerFactory.getLogger(OktaOpaqueTokenIntrospector.class);

private static final String ACCESS_TOKEN_TYPE_HINT = "access_token";

private Converter<String, RequestEntity<?>> requestEntityConverter;
private RestOperations restOperations;

public OktaOpaqueTokenIntrospector(String introspectionUri, String clientId, String clientSecret, RestOperations restOperations) {
Assert.notNull(introspectionUri, "introspectionUri cannot be null");
Assert.notNull(clientId, "clientId cannot be null");
Assert.notNull(clientSecret, "clientSecret cannot be null");
Assert.notNull(restOperations, "restOperations cannot be null");
this.requestEntityConverter = this.defaultRequestEntityConverter(URI.create(introspectionUri), clientId, clientSecret);
this.restOperations = restOperations;
}

private Converter<String, RequestEntity<?>> defaultRequestEntityConverter(URI introspectionUri, String clientId, String clientSecret) {
return (token) -> {
HttpHeaders headers = this.requestHeaders();
MultiValueMap<String, String> body = this.requestBody(token, clientId, clientSecret);
return new RequestEntity(body, headers, HttpMethod.POST, introspectionUri);
};
}

private HttpHeaders requestHeaders() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
return headers;
}

/**
* Okta Introspection endpoint requires caller to send client_id, client_secret & token_type_hint
* parameters in request body addition to token.
*/
private MultiValueMap<String, String> requestBody(String token, String clientId, String clientSecret) {
MultiValueMap<String, String> body = new LinkedMultiValueMap();
body.add("client_id", clientId);
body.add("client_secret", clientSecret);
body.add("token_type_hint", ACCESS_TOKEN_TYPE_HINT);
body.add("token", token);
return body;
}

public OAuth2AuthenticatedPrincipal introspect(String token) {

RequestEntity<?> requestEntity = (RequestEntity)this.requestEntityConverter.convert(token);
if (requestEntity == null) {
throw new OAuth2IntrospectionException("requestEntityConverter returned a null entity");
} else {
ResponseEntity<String> responseEntity = this.makeRequest(requestEntity);
log.debug("Response from introspection endpoint: {}", responseEntity.getBody());
HTTPResponse httpResponse = this.adaptToNimbusResponse(responseEntity);
TokenIntrospectionResponse introspectionResponse = this.parseNimbusResponse(httpResponse);
TokenIntrospectionSuccessResponse introspectionSuccessResponse = this.castToNimbusSuccess(introspectionResponse);
if (!introspectionSuccessResponse.isActive()) {
throw new BadOpaqueTokenException("Provided token isn't active");
} else {
return this.convertClaimsSet(introspectionSuccessResponse);
}
}
}

public void setRequestEntityConverter(Converter<String, RequestEntity<?>> requestEntityConverter) {
Assert.notNull(requestEntityConverter, "requestEntityConverter cannot be null");
this.requestEntityConverter = requestEntityConverter;
}

private ResponseEntity<String> makeRequest(RequestEntity<?> requestEntity) {
log.debug("Making request to introspection endpoint");
try {
return this.restOperations.exchange(requestEntity, String.class);
} catch (Exception var3) {
throw new OAuth2IntrospectionException(var3.getMessage(), var3);
}
}

private HTTPResponse adaptToNimbusResponse(ResponseEntity<String> responseEntity) {
HTTPResponse response = new HTTPResponse(responseEntity.getStatusCodeValue());
response.setHeader("Content-Type", new String[]{responseEntity.getHeaders().getContentType().toString()});
response.setContent((String)responseEntity.getBody());
if (response.getStatusCode() != 200) {
throw new OAuth2IntrospectionException("Introspection endpoint responded with " + response.getStatusCode());
} else {
return response;
}
}

private TokenIntrospectionResponse parseNimbusResponse(HTTPResponse response) {
try {
return TokenIntrospectionResponse.parse(response);
} catch (Exception var3) {
throw new OAuth2IntrospectionException(var3.getMessage(), var3);
}
}

private TokenIntrospectionSuccessResponse castToNimbusSuccess(TokenIntrospectionResponse introspectionResponse) {
if (!introspectionResponse.indicatesSuccess()) {
throw new OAuth2IntrospectionException("Token introspection failed");
} else {
return (TokenIntrospectionSuccessResponse)introspectionResponse;
}
}

private OAuth2AuthenticatedPrincipal convertClaimsSet(TokenIntrospectionSuccessResponse response) {
Collection<GrantedAuthority> authorities = new ArrayList();
Map<String, Object> claims = response.toJSONObject();
Iterator var5;
if (response.getAudience() != null) {
List<String> audiences = new ArrayList();
var5 = response.getAudience().iterator();

while(var5.hasNext()) {
Audience audience = (Audience)var5.next();
audiences.add(audience.getValue());
}

claims.put("aud", Collections.unmodifiableList(audiences));
}

if (response.getClientID() != null) {
claims.put("client_id", response.getClientID().getValue());
}

Instant iat;
if (response.getExpirationTime() != null) {
iat = response.getExpirationTime().toInstant();
claims.put("exp", iat);
}

if (response.getIssueTime() != null) {
iat = response.getIssueTime().toInstant();
claims.put("iat", iat);
}

if (response.getIssuer() != null) {
claims.put("iss", this.issuer(response.getIssuer().getValue()));
}

if (response.getNotBeforeTime() != null) {
claims.put("nbf", response.getNotBeforeTime().toInstant());
}

if (response.getScope() != null) {
List<String> scopes = Collections.unmodifiableList(response.getScope().toStringList());
claims.put("scope", scopes);
var5 = scopes.iterator();

while(var5.hasNext()) {
String scope = (String)var5.next();
StringBuilder var10003 = new StringBuilder();
this.getClass();
authorities.add(new SimpleGrantedAuthority(var10003.append("SCOPE_").append(scope).toString()));
}
}

return new DefaultOAuth2AuthenticatedPrincipal(claims, authorities);
}

private URL issuer(String uri) {
try {
return new URL(uri);
} catch (Exception var3) {
throw new OAuth2IntrospectionException("Invalid iss value: " + uri);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public final class OktaOAuth2Properties implements Validator {
*/
private String postLogoutRedirectUri;

/**
* Identifies Opaque token
arvindkrishnakumar-okta marked this conversation as resolved.
Show resolved Hide resolved
*/
private boolean opaque = false;

// work around for https://github.com/spring-projects/spring-boot/issues/17035
private OktaOAuth2Properties() {
this(null);
Expand Down Expand Up @@ -154,6 +159,18 @@ public void setPostLogoutRedirectUri(String postLogoutRedirectUri) {
this.postLogoutRedirectUri = postLogoutRedirectUri;
}

public boolean getOpaque() {
arvindkrishnakumar-okta marked this conversation as resolved.
Show resolved Hide resolved
return opaque;
}

public boolean isOpaque() {
return getOpaque();
}

public void setOpaque(boolean opaque) {
this.opaque = opaque;
}

@Override
public boolean supports(Class<?> clazz) {
return OktaOAuth2Properties.class.isAssignableFrom(clazz);
Expand Down
Loading