@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse resp)
throws IOException {
final String method = "doGet";
DominoOAuth2Accessor accessor = null;
final OAuth2Message msg = this.oauth2MessageProvider.get();
msg.parseRequest(request);
if(!isOAuthMsgValid(msg, resp)) {
return;
}
final DominoOAuth2CallbackState state = new DominoOAuth2CallbackState(this.stateCrypter,
msg.getState());
try {
accessor = this.store.getOAuth2Accessor(state);
} catch (GadgetException e1) {
log.logp(Level.WARNING, CLASS, method, "Error getting accessor from store.", e1);
}
if(accessor == null) {
sendError(OAuth2Error.CALLBACK_PROBLEM, "OAuth2CallbackServlet accessor is null",
"OAuth2CallbackServlet accessor is null", "", null, resp,
null, this.sendTraceToClient);
return;
}
if(!isAccessorValid(accessor, resp)) {
accessor.invalidate();
try {
this.store.removeOAuth2Accessor(accessor);
} catch (GadgetException e) {
log.logp(Level.WARNING, CLASS, method, "Error removing invalid accessor.", e);
}
return;
}
try {
boolean foundHandler = false;
for (final AuthorizationEndpointResponseHandler authorizationEndpointResponseHandler : this.authorizationEndpointResponseHandlers) {
if (authorizationEndpointResponseHandler.handlesRequest(accessor, request)) {
final OAuth2HandlerError handlerError = authorizationEndpointResponseHandler
.handleRequest(accessor, request);
if (handlerError != null) {
sendError(handlerError.getError(),
handlerError.getContextMessage(), handlerError.getDescription(),
handlerError.getUri(), accessor, resp, handlerError.getCause(),
this.sendTraceToClient);
return;
}
foundHandler = true;
break;
}
}
if (!foundHandler) {
sendError(OAuth2Error.NO_RESPONSE_HANDLER,
"OAuth2Callback servlet couldn't find a AuthorizationEndpointResponseHandler", "",
"", accessor, resp, null, this.sendTraceToClient);
return;
}
HttpUtil.setNoCache(resp);
resp.setContentType("text/html; charset=UTF-8");
resp.getWriter().write(RESP_BODY);
} catch (final Exception e) {
sendError(OAuth2Error.CALLBACK_PROBLEM,
"Exception occurred processing redirect.", "", "", accessor, resp, e,
this.sendTraceToClient);
throw new IOException(e);
} finally {
try{
if (!accessor.isErrorResponse()) {
accessor.invalidate();
this.store.removeOAuth2Accessor(accessor);
} else {
this.store.storeOAuth2Accessor(accessor);
}
} catch(GadgetException e) {