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);
}
}
}
Aggregations