Skip to content

OAuth2 method security expression not working with client credentials tokens #5193

@marcioaug

Description

@marcioaug

In UserInfoTokenService (org.springframework.boot.autoconfigure.security.oauth2.resource)

private OAuth2Authentication extractAuthentication(Map<String, Object> map) {
...
        UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
                principal, "N/A", authorities);
        token.setDetails(map);
        return new OAuth2Authentication(request, token);

org.springframework.security.oauth2.provide.OAuth2Authentication:

    public OAuth2Authentication(OAuth2Request storedRequest, Authentication userAuthentication) {
        super(userAuthentication == null ? storedRequest.getAuthorities() : userAuthentication.getAuthorities());
        this.storedRequest = storedRequest;
        this.userAuthentication = userAuthentication;
    }

Always sends the userAuthentication , even when the token is obtained by client_crendetials grant type. This causes a fail in OAuth2Authentication

    public boolean isClientOnly() {
        return userAuthentication == null;
    }

Since the userAuthentication will never be null.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions