use of org.apache.oltu.oauth2.common.exception.OAuthSystemException in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuth2AuthzEndpoint method handleDeniedConsent.
private Response handleDeniedConsent(OAuthMessage oAuthMessage) throws OAuthSystemException, URISyntaxException {
OAuth2Parameters oauth2Params = getOauth2Params(oAuthMessage);
OpenIDConnectUserRPStore.getInstance().putUserRPToStore(getLoggedInUser(oAuthMessage), getOauth2Params(oAuthMessage).getApplicationName(), false, oauth2Params.getClientId());
OAuthErrorDTO oAuthErrorDTO = EndpointUtil.getOAuth2Service().handleUserConsentDenial(oauth2Params);
OAuthProblemException consentDenialException = buildConsentDenialException(oAuthErrorDTO);
String denyResponse = EndpointUtil.getErrorRedirectURL(oAuthMessage.getRequest(), consentDenialException, oauth2Params);
if (StringUtils.equals(oauth2Params.getResponseMode(), RESPONSE_MODE_FORM_POST)) {
return handleFailedState(oAuthMessage, oauth2Params, consentDenialException);
}
return Response.status(HttpServletResponse.SC_FOUND).location(new URI(denyResponse)).build();
}
use of org.apache.oltu.oauth2.common.exception.OAuthSystemException in project identity-inbound-auth-oauth by wso2-extensions.
the class CookieBasedTokenBinder method retrieveTokenBindingValueFromRequest.
private String retrieveTokenBindingValueFromRequest(HttpServletRequest request) throws OAuthSystemException {
Cookie[] cookies = request.getCookies();
if (ArrayUtils.isEmpty(cookies)) {
return null;
}
Optional<Cookie> tokenBindingCookieOptional = Arrays.stream(cookies).filter(t -> COOKIE_NAME.equals(t.getName())).findAny();
if (!tokenBindingCookieOptional.isPresent() || StringUtils.isBlank(tokenBindingCookieOptional.get().getValue())) {
return null;
}
String tokenBindingValue = tokenBindingCookieOptional.get().getValue();
boolean isTokenBindingValueValid;
try {
// Do we need additional validation here? like validate local user.
isTokenBindingValueValid = OAuthTokenPersistenceFactory.getInstance().getTokenBindingMgtDAO().isTokenBindingExistsForBindingReference(OAuth2Util.getTokenBindingReference(tokenBindingValue));
} catch (IdentityOAuth2Exception e) {
throw new OAuthSystemException("Failed to check token binding reference existence", e);
}
return isTokenBindingValueValid ? tokenBindingValue : null;
}
use of org.apache.oltu.oauth2.common.exception.OAuthSystemException in project identity-inbound-auth-oauth by wso2-extensions.
the class SSOSessionBasedTokenBinder method isValidTokenBinding.
@Override
public boolean isValidTokenBinding(Object request, String bindingReference) {
try {
String sessionIdentifier = getTokenBindingValue((HttpServletRequest) request);
if (StringUtils.isBlank(sessionIdentifier)) {
if (log.isDebugEnabled()) {
log.debug("CommonAuthId cookie is not found in the request.");
}
return false;
}
/* Retrieve session context information using sessionIdentifier in order to check the validity of
commonAuthId cookie.*/
SessionContext sessionContext = FrameworkUtils.getSessionContextFromCache(sessionIdentifier);
if (sessionContext == null) {
if (log.isDebugEnabled()) {
log.debug("Session context is not found corresponding to the session identifier: " + sessionIdentifier);
}
return false;
}
} catch (OAuthSystemException e) {
log.error("Error while getting the token binding value", e);
return false;
}
return isValidTokenBinding(request, bindingReference, COMMONAUTH_COOKIE);
}
use of org.apache.oltu.oauth2.common.exception.OAuthSystemException in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuth2Util method addTokenDOtoCache.
/**
* There are cases where we store an 'alias' of the token returned to the client as the token inside IS.
* For example, in the case of JWT access tokens we store the 'jti' claim in the database instead of the
* actual JWT. Therefore we need to cache an AccessTokenDO with the stored token identifier.
*
* @param newTokenBean token DO to be added to the cache.
*/
public static void addTokenDOtoCache(AccessTokenDO newTokenBean) throws IdentityOAuth2Exception {
OauthTokenIssuer tokenIssuer = null;
try {
tokenIssuer = OAuth2Util.getOAuthTokenIssuerForOAuthApp(newTokenBean.getConsumerKey());
String tokenAlias = tokenIssuer.getAccessTokenHash(newTokenBean.getAccessToken());
OAuthCacheKey accessTokenCacheKey = new OAuthCacheKey(tokenAlias);
AccessTokenDO tokenDO = AccessTokenDO.clone(newTokenBean);
tokenDO.setAccessToken(tokenAlias);
OAuthCache.getInstance().addToCache(accessTokenCacheKey, tokenDO);
if (log.isDebugEnabled()) {
if (IdentityUtil.isTokenLoggable(IdentityConstants.IdentityTokens.ACCESS_TOKEN)) {
log.debug("Access token DO was added to OAuthCache with cache key: " + accessTokenCacheKey.getCacheKeyString());
} else {
log.debug("Access token DO was added to OAuthCache");
}
}
} catch (OAuthSystemException e) {
if (IdentityUtil.isTokenLoggable(IdentityConstants.IdentityTokens.ACCESS_TOKEN)) {
throw new IdentityOAuth2Exception("Error while getting the token alias from token issuer: " + tokenIssuer.toString() + " for the token: " + newTokenBean.getAccessToken(), e);
} else {
throw new IdentityOAuth2Exception("Error while getting the token alias from token issuer: " + tokenIssuer.toString(), e);
}
} catch (InvalidOAuthClientException e) {
if (IdentityUtil.isTokenLoggable(IdentityConstants.IdentityTokens.ACCESS_TOKEN)) {
throw new IdentityOAuth2Exception("Error while getting the token issuer for the token: " + newTokenBean.getAccessToken(), e);
} else {
throw new IdentityOAuth2Exception("Error while getting the token issuer", e);
}
}
}
use of org.apache.oltu.oauth2.common.exception.OAuthSystemException in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuth2Util method getAccessTokenDOFromMatchingTokenIssuer.
/**
* Loop through provided token issuer list and tries to get the access token DO.
*
* @param tokenIdentifier Provided token identifier.
* @param tokenIssuerMap List of token issuers.
* @return Obtained matching access token DO if possible.
* @throws IdentityOAuth2Exception
*/
private static AccessTokenDO getAccessTokenDOFromMatchingTokenIssuer(String tokenIdentifier, Map<String, OauthTokenIssuer> tokenIssuerMap, boolean includeExpired) throws IdentityOAuth2Exception {
AccessTokenDO accessTokenDO;
if (tokenIssuerMap != null) {
for (Map.Entry<String, OauthTokenIssuer> oauthTokenIssuerEntry : tokenIssuerMap.entrySet()) {
try {
OauthTokenIssuer oauthTokenIssuer = oauthTokenIssuerEntry.getValue();
String tokenAlias = oauthTokenIssuer.getAccessTokenHash(tokenIdentifier);
if (oauthTokenIssuer.usePersistedAccessTokenAlias()) {
accessTokenDO = OAuth2Util.getAccessTokenDOFromTokenIdentifier(tokenAlias, includeExpired);
} else {
accessTokenDO = OAuth2Util.getAccessTokenDOFromTokenIdentifier(tokenIdentifier, includeExpired);
}
if (accessTokenDO != null) {
return accessTokenDO;
}
} catch (OAuthSystemException e) {
if (log.isDebugEnabled()) {
if (IdentityUtil.isTokenLoggable(IdentityConstants.IdentityTokens.ACCESS_TOKEN)) {
log.debug("Token issuer: " + oauthTokenIssuerEntry.getKey() + " was tried and" + " failed to parse the received token: " + tokenIdentifier);
} else {
log.debug("Token issuer: " + oauthTokenIssuerEntry.getKey() + " was tried and" + " failed to parse the received token.");
}
}
} catch (IllegalArgumentException e) {
if (log.isDebugEnabled()) {
if (IdentityUtil.isTokenLoggable(IdentityConstants.IdentityTokens.ACCESS_TOKEN)) {
log.debug("Token issuer: " + oauthTokenIssuerEntry.getKey() + " was tried and" + " failed to get the token from database: " + tokenIdentifier);
} else {
log.debug("Token issuer: " + oauthTokenIssuerEntry.getKey() + " was tried and" + " failed to get the token from database.");
}
}
}
}
}
return null;
}
Aggregations