getLogger().info("After Redirecting to : " + redirRef.toUri());
// return true;
// return null;
} else {
getLogger().info("Came back after SNS code = " + code);
ClientResource tokenResource = new CookieCopyClientResource(
params.getBaseRef() + params.getAccessTokenPath());
Form form = new Form();
form.add(OAuthServerResource.GRANT_TYPE,
OAuthServerResource.GrantType.authorization_code.name());
String redir = request.getResourceRef().getHostIdentifier()
+ request.getResourceRef().getPath();
form.add(OAuthServerResource.REDIR_URI, redir);
if (basicSecret) {
ChallengeResponse authentication = new ChallengeResponse(
ChallengeScheme.HTTP_BASIC);
authentication.setDigestAlgorithm("NONE");
String basic = params.getClientId() + ':'
+ params.getClientSecret();
authentication.setRawValue(Base64.encode(basic.getBytes(),
false));
tokenResource.setChallengeResponse(authentication);
} else {
form.add(OAuthServerResource.CLIENT_ID, params.getClientId());
form.add(OAuthServerResource.CLIENT_SECRET,
params.getClientSecret());
}
form.add(OAuthServerResource.CODE, code);
getLogger().info(
"Sending access form : " + form.getQueryString() + " to : "
+ tokenResource.getReference());
try {
Representation input = form.getWebRepresentation();
Representation body = tokenResource.post(input);
if (tokenResource.getStatus().isSuccess()) {
// Store away the user
OAuthUser authUser = OAuthUser.createJson(body);
if (authUser != null) {
request.getClientInfo().setUser(authUser);
request.getClientInfo().setAuthenticated(true);
getLogger().info(
"storing to context = : " + getContext());
// continue in the filter chain
auth = true;
}
}
getLogger().info("Before sns release");
body.release();
} catch (ResourceException re) {
getLogger().warning("Could not find token resource.");
}
tokenResource.release();
}
return auth;
}