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

SECAUTH-1483 #640

Merged
merged 4 commits into from
Sep 1, 2021
Merged

SECAUTH-1483 #640

merged 4 commits into from
Sep 1, 2021

Conversation

nenaraab
Copy link
Contributor

@nenaraab nenaraab commented Aug 24, 2021

In spring-xsuaa

Before

Converter<Jwt, AbstractAuthenticationToken> getJwtAuthenticationConverter() {
		TokenAuthenticationConverter converter = new TokenAuthenticationConverter(xsuaaServiceConfiguration);
		converter.setLocalScopeAsAuthorities(true);
		return converter;
}

New

Converter<Jwt, AbstractAuthenticationToken> getJwtAuthenticationConverter() {
          return new TokenAuthenticationConverter(new MyCustomAuthoritiesExtractor());
}

private static class MyCustomAuthoritiesExtractor implements AuthoritiesExtractor {

		@Override
		public Collection<GrantedAuthority> getAuthorities(XsuaaToken token) {
			String appId = "";
			if(token.getClientId().startsWith("sb-")) {
				appId = token.getClientId().replaceFirst("sb-", "");
			}
			AuthoritiesExtractor authoritiesExtractor = new LocalAuthoritiesExtractor(appId);
			return authoritiesExtractor.getAuthorities(token);
		}

	}

In spring-security

You can subclass XsuaaTokenAuthorizationConverter and overwrite localScopeAuthorities(Jwt jwt, Collection<String> scopes). An example is not yet available.

@nenaraab nenaraab requested a review from liga-oz August 24, 2021 11:12
Copy link
Contributor

@liga-oz liga-oz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looking good just couple of points to review 😉

return localScopeAuthorities(jwt, scopes);
}

protected Collection<GrantedAuthority> localScopeAuthorities(Jwt jwt, Collection<String> scopes) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the jwt seems to be not used in the method, is it required to have it in the argument list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good finding!
But in this case this protected method is foreseen as "enhancement spot" and app developers may need access to other token claims.

@nenaraab nenaraab requested a review from liga-oz August 31, 2021 16:47
Copy link
Contributor

@liga-oz liga-oz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

@nenaraab nenaraab merged commit 083d988 into main Sep 1, 2021
@nenaraab nenaraab deleted the SECAUTH-1483-2 branch September 1, 2021 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants