use of oidc.model.User in project OpenConext-oidcng by OpenConext.
the class AuthorizationEndpointTest method hybridFlowFragment.
@Test
public void hybridFlowFragment() throws IOException, BadJOSEException, ParseException, JOSEException {
Response response = doAuthorize("mock-sp", "code id_token token", null, "nonce", null);
String url = response.getHeader("Location");
String fragment = url.substring(url.indexOf("#") + 1);
Map<String, String> fragmentParameters = fragmentToMap(fragment);
String code = fragmentParameters.get("code");
AuthorizationCode authorizationCode = mongoTemplate.findOne(Query.query(Criteria.where("code").is(code)), AuthorizationCode.class);
User user = mongoTemplate.findOne(Query.query(Criteria.where("sub").is(authorizationCode.getSub())), User.class);
assertNotNull(user);
String accessToken = fragmentParameters.get("access_token");
JWTClaimsSet claimsSet = assertImplicitFlowResponse(fragmentParameters);
Map<String, Object> tokenResponse = doToken(code);
List<User> users = mongoTemplate.find(Query.query(Criteria.where("sub").is(authorizationCode.getSub())), User.class);
assertEquals(0, users.size());
String newAccessToken = (String) tokenResponse.get("access_token");
/*
* If an Access Token is returned from both the Authorization Endpoint and from the Token Endpoint, which is
* the case for the response_type values code token and code id_token token, their values MAY be the same or
* they MAY be different. Note that different Access Tokens might be returned be due to the different
* security characteristics of the two endpoints and the lifetimes and the access to resources granted
* by them might also be different.
*/
assertNotEquals(accessToken, newAccessToken);
String idToken = (String) tokenResponse.get("id_token");
JWTClaimsSet newClaimsSet = processToken(idToken, port);
assertEquals(claimsSet.getAudience(), newClaimsSet.getAudience());
assertEquals(claimsSet.getSubject(), newClaimsSet.getSubject());
assertEquals(claimsSet.getIssuer(), newClaimsSet.getIssuer());
}
use of oidc.model.User in project OpenConext-oidcng by OpenConext.
the class ResponseAuthenticationConverter method convert.
@Override
public OidcSamlAuthentication convert(OpenSaml4AuthenticationProvider.ResponseToken responseToken) {
Saml2Authentication authentication = defaultResponseAuthenticationConverter.convert(responseToken);
Assertion assertion = responseToken.getResponse().getAssertions().get(0);
Matcher matcher = inResponseToPattern.matcher(authentication.getSaml2Response());
boolean match = matcher.find();
if (!match) {
throw new SessionAuthenticationException("Invalid Authn Statement. Missing InResponseTo");
}
String authenticationRequestID = matcher.group(1);
User user = buildUser(assertion, authenticationRequestID);
Optional<User> existingUserOptional = userRepository.findOptionalUserBySub(user.getSub());
if (existingUserOptional.isPresent()) {
User existingUser = existingUserOptional.get();
LOG.debug("Authenticate with existing user: " + existingUser);
user.setId(existingUser.getId());
if (!user.equals(existingUser)) {
LOG.debug("Saving existing user with changed attributes: " + existingUser);
userRepository.save(existingUser);
}
} else {
LOG.debug("Provisioning new user : " + user);
userRepository.insert(user);
}
OidcSamlAuthentication oidcSamlAuthentication = new OidcSamlAuthentication(assertion, user, authenticationRequestID);
return oidcSamlAuthentication;
}
Aggregations