Compare commits

..

No commits in common. "master" and "a90d98aa1e685ca5af67189f1f4f0cb2317a0473" have entirely different histories.

11 changed files with 27 additions and 17 deletions

View File

@ -3,3 +3,6 @@ contact_links:
- name: Community Support
url: https://stackoverflow.com/questions/tagged/spring-security
about: Please ask and answer questions on StackOverflow with the tag `spring-security`.
- name: Security Issues
url: https://pivotal.io/security#reporting
about: Please report security vulnerabilities here.

View File

@ -45,7 +45,7 @@ This project adheres to the Contributor Covenant link:CODE_OF_CONDUCT.adoc[code
By participating, you are expected to uphold this code. Please report unacceptable behavior to spring-code-of-conduct@pivotal.io.
== Downloading Artifacts
See https://github.com/spring-projects/spring-framework/wiki/Spring-Framework-Artifacts[downloading Spring artifacts] for Maven repository information.
See https://github.com/spring-projects/spring-framework/wiki/Downloading-Spring-artifacts[downloading Spring artifacts] for Maven repository information.
== Building from Source
Spring Authorization Server uses a https://gradle.org[Gradle]-based build system.

View File

@ -1,5 +1,5 @@
version=0.1.1-SNAPSHOT
springBootVersion=2.4.3
springBootVersion=2.4.2
org.gradle.jvmargs=-Xmx3g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError
org.gradle.parallel=true
org.gradle.caching=true

View File

@ -3,7 +3,7 @@ if (!project.hasProperty("springVersion")) {
}
if (!project.hasProperty("springSecurityVersion")) {
ext.springSecurityVersion = "5.4.5"
ext.springSecurityVersion = "5.4.2"
}
if (!project.hasProperty("reactorVersion")) {
@ -25,6 +25,8 @@ dependencyManagement {
}
dependencies {
dependency "com.nimbusds:oauth2-oidc-sdk:8.23.1"
dependency "com.nimbusds:nimbus-jose-jwt:9.1.3"
dependency "javax.servlet:javax.servlet-api:4.0.1"
dependency 'junit:junit:4.13.1'
dependency 'org.assertj:assertj-core:3.18.1'

View File

@ -20,5 +20,5 @@ dependencies {
}
jacoco {
toolVersion = '0.8.6'
toolVersion = '0.8.5'
}

View File

@ -43,7 +43,6 @@ import com.nimbusds.jose.util.Base64URL;
import com.nimbusds.jwt.JWTClaimsSet;
import com.nimbusds.jwt.SignedJWT;
import net.minidev.json.JSONObject;
import org.springframework.core.convert.converter.Converter;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
@ -198,7 +197,7 @@ public final class NimbusJwsEncoder implements JwtEncoder {
Map<String, Object> jwk = headers.getJwk();
if (!CollectionUtils.isEmpty(jwk)) {
try {
builder.jwk(JWK.parse(new JSONObject(jwk)));
builder.jwk(JWK.parse(jwk));
}
catch (Exception ex) {
throw new JwtEncodingException(String.format(ENCODING_ERROR_MESSAGE_TEMPLATE,

View File

@ -18,6 +18,7 @@ package org.springframework.security.oauth2.server.authorization.authentication;
import java.security.Principal;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@ -146,7 +147,7 @@ public class OAuth2AuthorizationCodeAuthenticationProvider implements Authentica
JoseHeader.Builder headersBuilder = JwtUtils.headers();
JwtClaimsSet.Builder claimsBuilder = JwtUtils.accessTokenClaims(
registeredClient, issuer, authorization.getPrincipalName(),
authorizedScopes);
excludeOpenidIfNecessary(authorizedScopes));
// @formatter:off
JwtEncodingContext context = JwtEncodingContext.with(headersBuilder, claimsBuilder)
@ -168,7 +169,7 @@ public class OAuth2AuthorizationCodeAuthenticationProvider implements Authentica
OAuth2AccessToken accessToken = new OAuth2AccessToken(OAuth2AccessToken.TokenType.BEARER,
jwtAccessToken.getTokenValue(), jwtAccessToken.getIssuedAt(),
jwtAccessToken.getExpiresAt(), authorizedScopes);
jwtAccessToken.getExpiresAt(), excludeOpenidIfNecessary(authorizedScopes));
OAuth2RefreshToken refreshToken = null;
if (registeredClient.getAuthorizationGrantTypes().contains(AuthorizationGrantType.REFRESH_TOKEN)) {
@ -244,6 +245,15 @@ public class OAuth2AuthorizationCodeAuthenticationProvider implements Authentica
registeredClient, clientPrincipal, accessToken, refreshToken, additionalParameters);
}
private static Set<String> excludeOpenidIfNecessary(Set<String> scopes) {
if (!scopes.contains(OidcScopes.OPENID)) {
return scopes;
}
scopes = new HashSet<>(scopes);
scopes.remove(OidcScopes.OPENID);
return scopes;
}
@Override
public boolean supports(Class<?> authentication) {
return OAuth2AuthorizationCodeAuthenticationToken.class.isAssignableFrom(authentication);

View File

@ -311,8 +311,7 @@ public class OAuth2AuthorizationCodeAuthenticationProviderTests {
assertThat(accessTokenContext.getClaims()).isNotNull();
Map<String, Object> claims = new HashMap<>();
accessTokenContext.getClaims().claims(claims::putAll);
assertThat(claims).flatExtracting(OAuth2ParameterNames.SCOPE)
.containsExactlyInAnyOrder(OidcScopes.OPENID, "scope1");
assertThat(claims.containsKey(OidcScopes.OPENID)).isFalse();
// ID Token context
JwtEncodingContext idTokenContext = jwtEncodingContextCaptor.getAllValues().get(1);
assertThat(idTokenContext.getRegisteredClient()).isEqualTo(registeredClient);
@ -336,6 +335,7 @@ public class OAuth2AuthorizationCodeAuthenticationProviderTests {
assertThat(accessTokenAuthentication.getPrincipal()).isEqualTo(clientPrincipal);
assertThat(accessTokenAuthentication.getAccessToken()).isEqualTo(updatedAuthorization.getAccessToken().getToken());
Set<String> accessTokenScopes = new HashSet<>(updatedAuthorization.getAttribute(OAuth2Authorization.AUTHORIZED_SCOPE_ATTRIBUTE_NAME));
accessTokenScopes.remove(OidcScopes.OPENID);
assertThat(accessTokenAuthentication.getAccessToken().getScopes()).isEqualTo(accessTokenScopes);
assertThat(accessTokenAuthentication.getRefreshToken()).isNotNull();
assertThat(accessTokenAuthentication.getRefreshToken()).isEqualTo(updatedAuthorization.getRefreshToken().getToken());

View File

@ -43,10 +43,6 @@ import org.springframework.security.oauth2.server.authorization.config.ProviderS
@Import(OAuth2AuthorizationServerConfiguration.class)
public class AuthorizationServerConfig {
private String getIssuer() {
return "http://localhost:9000";
}
// @formatter:off
@Bean
public RegisteredClientRepository registeredClientRepository() {
@ -77,6 +73,6 @@ public class AuthorizationServerConfig {
@Bean
public ProviderSettings providerSettings() {
return new ProviderSettings().issuer(getIssuer());
return new ProviderSettings().issuer("http://auth-server:9000");
}
}

View File

@ -41,7 +41,7 @@ spring:
client-name: messaging-client-client-credentials
provider:
spring:
issuer-uri: http://localhost:9000
issuer-uri: http://auth-server:9000
messages:
base-uri: http://localhost:8090/messages

View File

@ -14,4 +14,4 @@ spring:
oauth2:
resourceserver:
jwt:
issuer-uri: http://localhost:9000
issuer-uri: http://auth-server:9000