1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.security.oauth2.provider.approval;
18
19 import java.util.HashMap;
20 import java.util.Map;
21
22 import org.springframework.security.core.Authentication;
23 import org.springframework.security.oauth2.common.util.OAuth2Utils;
24 import org.springframework.security.oauth2.provider.AuthorizationRequest;
25
26
27
28
29
30
31
32 public class DefaultUserApprovalHandler implements UserApprovalHandler {
33
34 private String approvalParameter = OAuth2Utils.USER_OAUTH_APPROVAL;
35
36
37
38
39 public void setApprovalParameter(String approvalParameter) {
40 this.approvalParameter = approvalParameter;
41 }
42
43
44
45
46
47
48
49
50
51
52 public boolean isApproved(AuthorizationRequest authorizationRequest, Authentication userAuthentication) {
53 if (authorizationRequest.isApproved()) {
54 return true;
55 }
56 return false;
57 }
58
59 public AuthorizationRequestringframework/security/oauth2/provider/AuthorizationRequest.html#AuthorizationRequest">AuthorizationRequest checkForPreApproval(AuthorizationRequest authorizationRequest, Authentication userAuthentication) {
60 return authorizationRequest;
61 }
62
63 @Override
64 public AuthorizationRequestringframework/security/oauth2/provider/AuthorizationRequest.html#AuthorizationRequest">AuthorizationRequest updateAfterApproval(AuthorizationRequest authorizationRequest, Authentication userAuthentication) {
65 Map<String, String> approvalParameters = authorizationRequest.getApprovalParameters();
66 String flag = approvalParameters.get(approvalParameter);
67 boolean approved = flag != null && flag.toLowerCase().equals("true");
68 authorizationRequest.setApproved(approved);
69 return authorizationRequest;
70 }
71
72 @Override
73 public Map<String, Object> getUserApprovalRequest(AuthorizationRequest authorizationRequest,
74 Authentication userAuthentication) {
75 Map<String, Object> model = new HashMap<String, Object>();
76
77 model.putAll(authorizationRequest.getRequestParameters());
78 return model;
79 }
80
81 }