Support configurable JwtDecoder for IdToken verification

Fixes gh-5717
This commit is contained in:
Joe Grandja
2018-12-12 10:28:22 -05:00
committed by Rob Winch
parent be23ab8114
commit 8f4f52edb9
12 changed files with 445 additions and 130 deletions

View File

@@ -32,6 +32,7 @@ public class TestOAuth2AuthorizationRequests {
return OAuth2AuthorizationRequest.authorizationCode()
.authorizationUri("https://example.com/login/oauth/authorize")
.clientId(clientId)
.scope("openid")
.redirectUri("https://example.com/authorize/oauth2/code/registration-id")
.state("state")
.additionalParameters(additionalParameters);

View File

@@ -0,0 +1,47 @@
/*
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.security.oauth2.core.oidc.user;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.oauth2.core.oidc.IdTokenClaimNames;
import org.springframework.security.oauth2.core.oidc.OidcIdToken;
import java.time.Instant;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Joe Grandja
*/
public class TestOidcUsers {
public static DefaultOidcUser create() {
List<GrantedAuthority> roles = AuthorityUtils.createAuthorityList("ROLE_USER");
return new DefaultOidcUser(roles, idToken());
}
private static OidcIdToken idToken() {
Map<String, Object> claims = new HashMap<>();
claims.put(IdTokenClaimNames.SUB, "subject");
claims.put(IdTokenClaimNames.ISS, "http://localhost/issuer");
claims.put(IdTokenClaimNames.AUD, Collections.singletonList("client"));
claims.put(IdTokenClaimNames.AZP, "client");
return new OidcIdToken("id-token", Instant.now(), Instant.now().plusSeconds(3600), claims);
}
}