Hm possibly I don't understand the process but as I understand the process is as the following:
OAuthConsumerContextFilter.doFilter
Code:
....
try {
request.setAttribute(getAccessTokensRequestAttribute(), new ArrayList<OAuthConsumerToken>(accessTokens.values()));
chain.doFilter(request, response);
}
catch (Exception e) {
........
// here we get token from tokenService
if (token == null) {
token = getTokenServices().getToken(neededResourceId);
}
String verifier = request.getParameter(OAuthProviderParameter.oauth_verifier.toString());
if (token == null || (!token.isAccessToken() && verifier == null)) {
.........
// try to get UnauthorizedRequestToken
token = getConsumerSupport().getUnauthorizedRequestToken(neededResourceId, callbackURL);
......
else if (!token.isAccessToken()) {
//we have a presumably authorized request token, let's try to get an access token with it.
//authorize the request token and store it.
try {
token = getConsumerSupport().getAccessToken(token, verifier);
}
finally {
// Remove token only here
getTokenServices().removeToken(neededResourceId);
}
.....
try {
//try again
if (!response.isCommitted()) {
request.setAttribute(getAccessTokensRequestAttribute(), new ArrayList<OAuthConsumerToken>(accessTokens.values()));
chain.doFilter(request, response);
}
else {
//dang. what do we do now?
throw new IllegalStateException("Unable to reprocess filter chain with needed OAuth2 resources because the response is already committed.");
}
}
catch (Exception e1) {
// HERE SPRING DOES NOTHING
resourceThatNeedsAuthorization = checkForResourceThatNeedsAuthorization(e1);
neededResourceId = resourceThatNeedsAuthorization.getId();
}
..........
}
So if here
// here we get token from tokenService
if (token == null) {
token = getTokenServices().getToken(neededResourceId);
}
we get the access token we will not step neither here if (token == null || (!token.isAccessToken() && verifier == null)) { nor here else if (!token.isAccessToken()) {
That's the case.