public ServerAccessToken createAccessToken(Client client, MultivaluedMap<String, String> params)
throws OAuthServiceException {
String assertion = params.getFirst(Constants.CLIENT_GRANT_ASSERTION_PARAM);
if (assertion == null) {
throw new OAuthServiceException(OAuthConstants.INVALID_GRANT);
}
try {
InputStream tokenStream = decodeAssertion(assertion);
Element token = readToken(tokenStream);
AssertionWrapper assertionWrapper = new AssertionWrapper(token);
Message message = PhaseInterceptorChain.getCurrentMessage();
validateToken(message, assertionWrapper);
UserSubject grantSubject = getGrantSubject(message, assertionWrapper);
return doCreateAccessToken(client,
grantSubject,
Constants.SAML2_BEARER_GRANT,
OAuthUtils.parseScope(params.getFirst(OAuthConstants.SCOPE)));
} catch (OAuthServiceException ex) {
throw ex;
} catch (Exception ex) {
throw new OAuthServiceException(OAuthConstants.INVALID_GRANT, ex);
}
}