Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ch4mpy committed Nov 6, 2023
1 parent 30cda59 commit e3ea25b
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.c4_soft.springaddons.security.oidc.starter.synchronised;

import java.sql.Date;
import java.time.Instant;
import java.util.Collection;
import java.util.HashSet;
Expand Down Expand Up @@ -98,6 +99,8 @@ OpaqueTokenAuthenticationConverter introspectionAuthenticationConverter(
SpringAddonsOidcProperties addonsProperties,
OAuth2ResourceServerProperties resourceServerProperties) {
return (String introspectedToken, OAuth2AuthenticatedPrincipal authenticatedPrincipal) -> {
final var iatClaim = authenticatedPrincipal.getAttribute(OAuth2TokenIntrospectionClaimNames.IAT);
final var expClaim = authenticatedPrincipal.getAttribute(OAuth2TokenIntrospectionClaimNames.EXP);
return new BearerTokenAuthentication(
new OAuth2IntrospectionAuthenticatedPrincipal(
new OpenidClaimSet(
Expand All @@ -112,11 +115,28 @@ OpaqueTokenAuthenticationConverter introspectionAuthenticationConverter(
new OAuth2AccessToken(
OAuth2AccessToken.TokenType.BEARER,
introspectedToken,
Instant.ofEpochSecond(((Integer) authenticatedPrincipal.getAttribute(OAuth2TokenIntrospectionClaimNames.IAT)).longValue()),
Instant.ofEpochSecond(((Integer) authenticatedPrincipal.getAttribute(OAuth2TokenIntrospectionClaimNames.EXP)).longValue())),
toInstant(iatClaim),
toInstant(expClaim)),
authoritiesConverter.convert(authenticatedPrincipal.getAttributes()));
};
}

private final Instant toInstant(Object claim) {
if(claim == null) {
return null;
}
if(claim instanceof Instant i) {
return i;
} else if(claim instanceof Date d) {
return d.toInstant();
} else if(claim instanceof Integer i) {
return Instant.ofEpochSecond((i).longValue());
} else if(claim instanceof Long l) {
return Instant.ofEpochSecond(l);
} else {
return null;
}
}

/**
* @param authoritiesConverter the authorities converter to use (by default {@link ConfigurableClaimSetAuthoritiesConverter})
Expand Down

0 comments on commit e3ea25b

Please sign in to comment.