implemented prompt=consent

pull/324/merge
Justin Richer 2013-04-24 14:08:14 -04:00
parent ce2c90fb30
commit 7292766b51
2 changed files with 41 additions and 33 deletions

View File

@ -125,39 +125,47 @@ public class TofuUserApprovalHandler implements UserApprovalHandler {
String clientId = authorizationRequest.getClientId(); String clientId = authorizationRequest.getClientId();
ClientDetails client = clientDetailsService.loadClientByClientId(clientId); ClientDetails client = clientDetailsService.loadClientByClientId(clientId);
//lookup ApprovedSites by userId and clientId // find out if we're supposed to prompt the user or not
Collection<ApprovedSite> aps = approvedSiteService.getByClientIdAndUserId(clientId, userId); String prompt = authorizationRequest.getAuthorizationParameters().get("prompt");
for (ApprovedSite ap : aps) { if (!"consent".equals(prompt)) {
// if the prompt parameter is set to "consent" then we can't use approved sites or whitelisted sites
// otherwise, we need to check them below
if (!ap.isExpired()) {
// if we find one that fits... //lookup ApprovedSites by userId and clientId
if (scopesMatch(authorizationRequest.getScope(), ap.getAllowedScopes())) { Collection<ApprovedSite> aps = approvedSiteService.getByClientIdAndUserId(clientId, userId);
for (ApprovedSite ap : aps) {
//We have a match; update the access date on the AP entry and return true. if (!ap.isExpired()) {
ap.setAccessDate(new Date());
approvedSiteService.save(ap);
// TODO: WHY DAVE WHY // if we find one that fits...
DefaultAuthorizationRequest ar = new DefaultAuthorizationRequest(authorizationRequest); if (scopesMatch(authorizationRequest.getScope(), ap.getAllowedScopes())) {
ar.setApproved(true);
return ar; //We have a match; update the access date on the AP entry and return true.
ap.setAccessDate(new Date());
approvedSiteService.save(ap);
// TODO: WHY DAVE WHY
DefaultAuthorizationRequest ar = new DefaultAuthorizationRequest(authorizationRequest);
ar.setApproved(true);
return ar;
}
} }
}
WhitelistedSite ws = whitelistedSiteService.getByClientId(clientId);
if (ws != null && scopesMatch(authorizationRequest.getScope(), ws.getAllowedScopes())) {
//Create an approved site
approvedSiteService.createApprovedSite(clientId, userId, null, ws.getAllowedScopes(), ws);
// TODO: WHY DAVE WHY
DefaultAuthorizationRequest ar = new DefaultAuthorizationRequest(authorizationRequest);
ar.setApproved(true);
return ar;
} }
}
WhitelistedSite ws = whitelistedSiteService.getByClientId(clientId);
if (ws != null && scopesMatch(authorizationRequest.getScope(), ws.getAllowedScopes())) {
//Create an approved site
approvedSiteService.createApprovedSite(clientId, userId, null, ws.getAllowedScopes(), ws);
// TODO: WHY DAVE WHY
DefaultAuthorizationRequest ar = new DefaultAuthorizationRequest(authorizationRequest);
ar.setApproved(true);
return ar;
} }
// This must be re-parsed here because SECOAUTH forces us to call things in a strange order // This must be re-parsed here because SECOAUTH forces us to call things in a strange order