Search in sources :

Example 1 with Exchange

use of com.nexblocks.authguard.service.exchange.Exchange in project AuthGuard by AuthGuard.

the class ExchangeServiceImpl method exchange.

@Override
public AuthResponseBO exchange(final AuthRequestBO authRequest, final String fromTokenType, final String toTokenType, final RequestContextBO requestContext) {
    final String key = exchangeKey(fromTokenType, toTokenType);
    final Exchange exchange = exchanges.get(key);
    if (exchange == null) {
        throw new ServiceException(ErrorCode.UNKNOWN_EXCHANGE, "Unknown token exchange " + fromTokenType + " to " + toTokenType);
    }
    final Either<Exception, AuthResponseBO> result = exchange.exchange(authRequest);
    if (result.isRight()) {
        final AuthResponseBO tokens = result.get();
        exchangeSuccess(authRequest, requestContext, tokens, fromTokenType, toTokenType);
        return tokens;
    } else {
        final Exception e = result.getLeft();
        exchangeFailure(authRequest, requestContext, e, fromTokenType, toTokenType);
        // TODO remove this
        if (ServiceException.class.isAssignableFrom(e.getClass())) {
            throw (ServiceException) e;
        } else {
            throw new RuntimeException(e);
        }
    }
}
Also used : TokenExchange(com.nexblocks.authguard.service.exchange.TokenExchange) Exchange(com.nexblocks.authguard.service.exchange.Exchange) ServiceException(com.nexblocks.authguard.service.exceptions.ServiceException) ServiceAuthorizationException(com.nexblocks.authguard.service.exceptions.ServiceAuthorizationException) ServiceException(com.nexblocks.authguard.service.exceptions.ServiceException)

Aggregations

ServiceAuthorizationException (com.nexblocks.authguard.service.exceptions.ServiceAuthorizationException)1 ServiceException (com.nexblocks.authguard.service.exceptions.ServiceException)1 Exchange (com.nexblocks.authguard.service.exchange.Exchange)1 TokenExchange (com.nexblocks.authguard.service.exchange.TokenExchange)1