use of org.restlet.data.ChallengeResponse in project OpenAM by OpenRock.
the class AccessTokenProtectionFilter method beforeHandle.
@Override
protected int beforeHandle(Request request, Response response) {
ChallengeResponse challengeResponse = request.getChallengeResponse();
Status failure = null;
if (challengeResponse == null) {
failure = new Status(401, new InvalidTokenException());
} else {
String tokenId = challengeResponse.getRawValue();
try {
OAuth2Request oAuth2Request = requestFactory.create(request);
AccessToken accessToken = tokenStore.readAccessToken(oAuth2Request, tokenId);
if (accessToken == null || accessToken.isExpired()) {
failure = new Status(401, new InvalidTokenException());
} else if (requiredScope != null && !accessToken.getScope().contains(requiredScope)) {
failure = new Status(403, new InsufficientScopeException(requiredScope));
} else {
oAuth2Request.setToken(AccessToken.class, accessToken);
}
} catch (ServerException e) {
failure = new Status(500, e);
} catch (NotFoundException e) {
debug.message("Error loading token with id: " + tokenId, e);
failure = new Status(404, e);
} catch (InvalidGrantException e) {
debug.message("Error loading token with id: " + tokenId, e);
failure = new Status(401, new InvalidTokenException());
}
}
if (failure != null) {
response.setStatus(failure);
return STOP;
}
return super.beforeHandle(request, response);
}
use of org.restlet.data.ChallengeResponse in project OpenAM by OpenRock.
the class OAuth2AuditRefreshTokenContextProvider method retrieveRefreshTokenFromChallengeResponse.
private RefreshToken retrieveRefreshTokenFromChallengeResponse(Request request) {
RefreshToken refreshToken;
ChallengeResponse challengeResponse = request.getChallengeResponse();
if (challengeResponse == null) {
return null;
}
String bearerToken = challengeResponse.getRawValue();
if ("undefined".equals(bearerToken)) {
return null;
}
OAuth2Request oAuth2Request = requestFactory.create(request);
try {
refreshToken = tokenStore.readRefreshToken(oAuth2Request, bearerToken);
} catch (ServerException | InvalidGrantException | NotFoundException e) {
return null;
}
return refreshToken;
}
use of org.restlet.data.ChallengeResponse in project OpenAM by OpenRock.
the class OAuth2AuditAccessTokenContextProvider method retrieveAccessTokenFromChallengeResponse.
private AccessToken retrieveAccessTokenFromChallengeResponse(Request request) {
AccessToken token;
ChallengeResponse challengeResponse = request.getChallengeResponse();
if (challengeResponse == null) {
return null;
}
String bearerToken = challengeResponse.getRawValue();
if ("undefined".equals(bearerToken)) {
return null;
}
OAuth2Request oAuth2Request = requestFactory.create(request);
try {
token = tokenStore.readAccessToken(oAuth2Request, bearerToken);
} catch (ServerException | InvalidGrantException | NotFoundException e) {
return null;
}
return token;
}
use of org.restlet.data.ChallengeResponse in project vcell by virtualcell.
the class UserVerifier method verify.
@Override
public int verify(Request request, Response response) {
ChallengeResponse challengeResponse = request.getChallengeResponse();
AuthenticationStatus result = verify(challengeResponse);
Context.getCurrent().getLogger().log(Level.FINE, "UserVerifier.verify(request,response) - returning " + result + ", request='" + request + "'");
switch(result) {
case invalid:
{
request.getCookies().removeAll("org.vcell.auth");
response.getCookieSettings().removeAll("org.vcell.auth");
return RESULT_INVALID;
}
case stale:
{
request.getCookies().removeAll("org.vcell.auth");
response.getCookieSettings().removeAll("org.vcell.auth");
return RESULT_STALE;
}
case missing:
{
return RESULT_MISSING;
}
case valid:
{
return RESULT_VALID;
}
default:
{
return RESULT_UNKNOWN;
}
}
}
use of org.restlet.data.ChallengeResponse in project vcell by virtualcell.
the class VCellCookieAuthenticator method logout.
@Override
protected int logout(Request request, Response response) {
try {
Cookie credentialsCookie = request.getCookies().getFirst(getCookieName());
if (credentialsCookie != null) {
ChallengeResponse challengeResponse = parseCredentials(credentialsCookie.getValue());
ApiAccessToken apiAccessToken = vcellApiApplication.getApiAccessToken(challengeResponse);
if (apiAccessToken != null) {
vcellApiApplication.getUserVerifier().invalidateApiAccessToken(apiAccessToken.getToken());
getLogger().log(Level.INFO, "MyCookieAuthenticator.login(request,response) - invalidated accessToken '" + apiAccessToken.getToken() + "'");
}
}
} catch (Exception e) {
e.printStackTrace(System.out);
getLogger().log(Level.SEVERE, "MyCookieAuthenticator.logout(request,response) - exception while invalidating '" + CustomAuthHelper.ACCESS_TOKEN + "'", e);
}
return super.logout(request, response);
}
Aggregations