use of io.gravitee.am.gateway.handler.ciba.exception.AuthenticationRequestNotFoundException in project gravitee-access-management by gravitee-io.
the class CibaTokenGranter method parseRequest.
@Override
protected Single<TokenRequest> parseRequest(TokenRequest tokenRequest, Client client) {
MultiValueMap<String, String> parameters = tokenRequest.parameters();
final String authReqId = parameters.getFirst(Parameters.AUTH_REQ_ID);
if (isEmpty(authReqId)) {
return Single.error(new InvalidRequestException("Missing parameter: auth_req_id"));
}
return super.parseRequest(tokenRequest, client).flatMap(tokenRequest1 -> authenticationRequestService.retrieve(domain, authReqId).map(cibaRequest -> {
if (!cibaRequest.getClientId().equals(client.getClientId())) {
logger.warn("client_id '{}' requests token using not owned authentication request '{}'", client.getId(), authReqId);
throw new AuthenticationRequestNotFoundException("Authentication request not found");
}
return cibaRequest;
}).map(cibaRequest -> {
// set resource owner
tokenRequest1.setSubject(cibaRequest.getSubject());
// set original scopes
tokenRequest1.setScopes(cibaRequest.getScopes());
// store only the AuthenticationFlowContext.data attributes in order to simplify EL templating
// and provide an up to date set of data if the enrichAuthFlow Policy ius used multiple time in a step
// {#context.attributes['authFlow']['entry']}
tokenRequest1.getContext().put(AUTH_FLOW_CONTEXT_ATTRIBUTES_KEY, emptyMap());
return tokenRequest1;
}));
}
use of io.gravitee.am.gateway.handler.ciba.exception.AuthenticationRequestNotFoundException in project gravitee-access-management by gravitee-io.
the class AuthenticationRequestServiceImpl method retrieve.
@Override
public Single<CibaAuthRequest> retrieve(Domain domain, String authReqId) {
LOGGER.debug("Search for authentication request with id '{}'", authReqId);
return this.authRequestRepository.findById(authReqId).switchIfEmpty(Single.error(new AuthenticationRequestNotFoundException(authReqId))).flatMap(request -> {
if ((request.getExpireAt().getTime() - (requestRetentionInSec * 1000)) < Instant.now().toEpochMilli()) {
return Single.error(new AuthenticationRequestExpiredException());
}
switch(AuthenticationRequestStatus.valueOf(request.getStatus())) {
case ONGOING:
// Check if the request interval is respected by the client
// if the client request to often the endpoint, throws a SlowDown error
// otherwise, update the last Access date before sending the pending exception
final int interval = domain.getOidc().getCibaSettings().getTokenReqInterval();
if (request.getLastAccessAt().toInstant().plusSeconds(interval).isAfter(Instant.now())) {
return Single.error(new SlowDownException());
}
request.setLastAccessAt(new Date());
return this.authRequestRepository.update(request).flatMap(__ -> Single.error(new AuthorizationPendingException()));
case REJECTED:
return this.authRequestRepository.delete(authReqId).toSingle(() -> {
throw new AccessDeniedException();
});
default:
return this.authRequestRepository.delete(authReqId).toSingle(() -> request);
}
});
}
use of io.gravitee.am.gateway.handler.ciba.exception.AuthenticationRequestNotFoundException in project gravitee-access-management by gravitee-io.
the class AuthenticationRequestServiceImpl method updateAuthDeviceInformation.
@Override
public Single<CibaAuthRequest> updateAuthDeviceInformation(CibaAuthRequest request) {
LOGGER.debug("Update authentication request '{}' with AuthenticationDeviceNotifier information", request.getId());
return this.authRequestRepository.findById(request.getId()).switchIfEmpty(Single.error(new AuthenticationRequestNotFoundException(request.getId()))).flatMap(existingReq -> {
// update only information provided by the AD notifier
existingReq.setExternalTrxId(request.getExternalTrxId());
existingReq.setExternalInformation(request.getExternalInformation());
existingReq.setDeviceNotifierId(request.getDeviceNotifierId());
return this.authRequestRepository.update(existingReq);
});
}
Aggregations