use of oidc.model.Scope in project OpenConext-oidcng by OpenConext.
the class TokenController method convertToken.
private Map<String, Object> convertToken(AccessToken token) {
Map<String, Object> result = new HashMap<>();
result.put("id", token.getId());
Optional<OpenIDClient> optionalClient = openIDClientRepository.findOptionalByClientId(token.getClientId());
if (!optionalClient.isPresent()) {
return result;
}
OpenIDClient openIDClient = optionalClient.get();
result.put("clientId", openIDClient.getClientId());
result.put("clientName", openIDClient.getName());
List<OpenIDClient> resourceServers = openIDClient.getAllowedResourceServers().stream().map(rs -> openIDClientRepository.findOptionalByClientId(rs)).filter(Optional::isPresent).map(Optional::get).collect(toList());
result.put("audiences", resourceServers.stream().map(OpenIDClient::getName));
result.put("createdAt", token.getCreatedAt());
result.put("expiresIn", token.getExpiresIn());
result.put("type", token instanceof RefreshToken ? TokenType.REFRESH : TokenType.ACCESS);
Map<String, Scope> allScopes = resourceServers.stream().map(OpenIDClient::getScopes).flatMap(List::stream).filter(distinctByKey(Scope::getName)).collect(toMap(Scope::getName, s -> s));
List<Scope> scopes = token.getScopes().stream().filter(name -> !name.equalsIgnoreCase("openid")).map(allScopes::get).filter(Objects::nonNull).collect(toList());
result.put("scopes", scopes);
return result;
}
use of oidc.model.Scope in project OpenConext-oidcng by OpenConext.
the class AuthnRequestConverterUnitTest method testSamlForceAuthn.
@Test
public void testSamlForceAuthn() throws Exception {
OpenIDClient openIDClient = new OpenIDClient("clientId", singletonList("http://redirect"), singletonList(new Scope("openid")), singletonList("authorization_code"));
when(openIDClientRepository.findOptionalByClientId("mock_sp")).thenReturn(Optional.of(openIDClient));
MockHttpServletRequest request = new MockHttpServletRequest("GET", "http://localhost/oidc/authorize");
request.addParameter("max_age", "-1");
request.addParameter("response_type", "code");
request.addParameter("client_id", "mock_sp");
HttpServletRequest servletRequest = new MockHttpServletRequest();
CustomSaml2AuthenticationRequestContext ctx = new CustomSaml2AuthenticationRequestContext(relyingParty, servletRequest);
when(requestCache.getRequest(any(HttpServletRequest.class), any())).thenReturn(new DefaultSavedRequest(request, portResolver));
AuthnRequest authnRequest = subject.convert(ctx);
assertTrue(authnRequest.isForceAuthn());
}
use of oidc.model.Scope in project OpenConext-oidcng by OpenConext.
the class AuthnRequestConverterUnitTest method testSaml.
@Test
public void testSaml() throws Exception {
OpenIDClient openIDClient = new OpenIDClient("clientId", singletonList("http://redirect"), singletonList(new Scope("openid")), singletonList("authorization_code"));
String cert = readFile("keys/certificate.crt");
setCertificateFields(openIDClient, cert, null, null);
when(openIDClientRepository.findOptionalByClientId("mock_sp")).thenReturn(Optional.of(openIDClient));
MockHttpServletRequest request = new MockHttpServletRequest("GET", "http://localhost/oidc/authorize");
request.addParameter("client_id", "mock_sp");
request.addParameter("response_type", "code");
request.addParameter("acr_values", "http://loa1");
request.addParameter("prompt", "login");
request.addParameter("login_hint", "http://idp");
String keyID = getCertificateKeyIDFromCertificate(cert);
SignedJWT signedJWT = signedJWT(openIDClient.getClientId(), keyID, openIDClient.getRedirectUrls().get(0));
request.addParameter("request", signedJWT.serialize());
HttpServletRequest servletRequest = new MockHttpServletRequest();
CustomSaml2AuthenticationRequestContext ctx = new CustomSaml2AuthenticationRequestContext(relyingParty, servletRequest);
when(requestCache.getRequest(any(HttpServletRequest.class), any())).thenReturn(new DefaultSavedRequest(request, portResolver));
AuthnRequest authnRequest = subject.convert(ctx);
assertTrue(authnRequest.isForceAuthn());
assertEquals("loa1", authnRequest.getRequestedAuthnContext().getAuthnContextClassRefs().get(0).getAuthnContextClassRef());
assertEquals("http://idp", authnRequest.getScoping().getIDPList().getIDPEntrys().get(0).getProviderID());
}
Aggregations