Skip to content

Commit

Permalink
Polish OAuth2IntrospectionAuthenticatedPrincipal
Browse files Browse the repository at this point in the history
Removed some duplication by delegating to
DefaultOAuth2AuthenticatedPrincipal

Changed order of listed interfaces to satisfy compiler issue. When
listed with OAuth2AuthenticatedPrincipal first, then
OAuth2ResourceServerBeanDefinitionParserTests would fail to import
OpaqueTokenBeanDefinitionParser. Switching
OAuth2AuthenticatedPrincipal with OAuth2IntrospectionClaimAccessor
resolved the compilation issue.

Issue gh-6489
  • Loading branch information
jzheaux committed Jul 10, 2020
1 parent af1c96b commit 221c33f
Showing 1 changed file with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@

package org.springframework.security.oauth2.server.resource.introspection;

import static org.springframework.security.core.authority.AuthorityUtils.NO_AUTHORITIES;

import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrincipal;
import org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal;
import org.springframework.util.Assert;

/**
* A domain object that wraps the attributes of OAuth 2.0 Token Introspection.
Expand All @@ -34,11 +31,9 @@
* @since 5.4
* @see <a target="_blank" href="https://tools.ietf.org/html/rfc7662#section-2.2">Introspection Response</a>
*/
public final class OAuth2IntrospectionAuthenticatedPrincipal implements OAuth2AuthenticatedPrincipal,
OAuth2IntrospectionClaimAccessor, Serializable {
private final Map<String, Object> attributes;
private final Collection<GrantedAuthority> authorities;
private final String name;
public final class OAuth2IntrospectionAuthenticatedPrincipal implements OAuth2IntrospectionClaimAccessor,
OAuth2AuthenticatedPrincipal, Serializable {
private final OAuth2AuthenticatedPrincipal delegate;

/**
* Constructs an {@code OAuth2IntrospectionAuthenticatedPrincipal} using the provided parameters.
Expand All @@ -49,7 +44,7 @@ public final class OAuth2IntrospectionAuthenticatedPrincipal implements OAuth2Au
public OAuth2IntrospectionAuthenticatedPrincipal(Map<String, Object> attributes,
Collection<GrantedAuthority> authorities) {

this(null, attributes, authorities);
this.delegate = new DefaultOAuth2AuthenticatedPrincipal(attributes, authorities);
}

/**
Expand All @@ -62,11 +57,7 @@ public OAuth2IntrospectionAuthenticatedPrincipal(Map<String, Object> attributes,
public OAuth2IntrospectionAuthenticatedPrincipal(String name, Map<String, Object> attributes,
Collection<GrantedAuthority> authorities) {

Assert.notEmpty(attributes, "attributes cannot be empty");
this.attributes = Collections.unmodifiableMap(attributes);
this.authorities = authorities == null ?
NO_AUTHORITIES : Collections.unmodifiableCollection(authorities);
this.name = name == null ? getSubject() : name;
this.delegate = new DefaultOAuth2AuthenticatedPrincipal(name, attributes, authorities);
}

/**
Expand All @@ -76,7 +67,7 @@ public OAuth2IntrospectionAuthenticatedPrincipal(String name, Map<String, Object
*/
@Override
public Map<String, Object> getAttributes() {
return this.attributes;
return this.delegate.getAttributes();
}

/**
Expand All @@ -87,15 +78,15 @@ public Map<String, Object> getAttributes() {
*/
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return this.authorities;
return this.delegate.getAuthorities();
}

/**
* {@inheritDoc}
*/
@Override
public String getName() {
return this.name;
return this.delegate.getName();
}

/**
Expand Down

0 comments on commit 221c33f

Please sign in to comment.