Hi All,
I'm using Spring Security OAuth2 (M6 version)and I have a requirement that user should get to approve page only once after first his login. The approved flag should be stored in DB and it is not difficult to implement custom UserApprovalHandler that verifies this flag. My question is where to inject code to save the approval flag value. I looked at the AuthorizationEndpoint source code and some other classes but i can't find a place where this code can be injected. So I'll be grateful for any advice.
My opinion that it might be better to put this logic into UserApprovalHandler. For example create new method.
And then change AuthorizationEndpoint from/**
* Basic interface for determining whether a given client authentication request has been approved by the current user.
*
* @author Ryan Heaton
* @author Dave Syer
*/
public interface UserApprovalHandler {
/**
* Whether the specified authorization request has been approved by the current user (if there is one).
*
* @param authorizationRequest the authorization request.
* @param userAuthentication the user authentication for the current user.
* @return Whether the specified client authentication has been approved by the current user.
*/
boolean isApproved(AuthorizationRequest authorizationRequest, Authentication userAuthentication);
/**
* Put approve logic here
* @param authorizationRequest
* @param approved
*/
void doApprove(AuthorizationRequest authorizationRequest, boolean approved);
}
topublic View approveOrDeny(@RequestParam(USER_OAUTH_APPROVAL) boolean approved,
@ModelAttribute AuthorizationRequest authorizationRequest, SessionStatus sessionStatus, Principal principal) {
................
try {
Set<String> responseTypes = authorizationRequest.getResponseTypes();
authorizationRequest = resolveRedirectUri(authorizationRequest);
if (responseTypes.contains("token")) {
return getImplicitGrantResponse(authorizationRequest.appr oved(true)).getView();
}
return getAuthorizationCodeResponse(authorizationRequest.approved(approved), (Authentication) principal);
}
finally {
sessionStatus.setComplete();
}
}
public View approveOrDeny(@RequestParam(USER_OAUTH_APPROVAL) boolean approved,
@ModelAttribute AuthorizationRequest authorizationRequest, SessionStatus sessionStatus, Principal principal) {
................
try {
Set<String> responseTypes = authorizationRequest.getResponseTypes();
authorizationRequest = resolveRedirectUri(authorizationRequest);
if (responseTypes.contains("token")) {
return getImplicitGrantResponse(authorizationRequest.appr oved(true)).getView();
}
return getAuthorizationCodeResponse(userApprovalHandler.doApprove(authorizationRequest ,approved), (Authentication) principal);
}
finally {
sessionStatus.setComplete();
}
}


Reply With Quote