mitreid-connect
公開メンバ関数 | 非公開メンバ関数 | 非公開変数類 | 全メンバ一覧
org.mitre.openid.connect.token.TofuUserApprovalHandler クラス
org.mitre.openid.connect.token.TofuUserApprovalHandler の継承関係図
Inheritance graph
org.mitre.openid.connect.token.TofuUserApprovalHandler 連携図
Collaboration graph

公開メンバ関数

boolean isApproved (AuthorizationRequest authorizationRequest, Authentication userAuthentication)
 
AuthorizationRequest checkForPreApproval (AuthorizationRequest authorizationRequest, Authentication userAuthentication)
 
AuthorizationRequest updateAfterApproval (AuthorizationRequest authorizationRequest, Authentication userAuthentication)
 
Map< String, Object > getUserApprovalRequest (AuthorizationRequest authorizationRequest, Authentication userAuthentication)
 

非公開メンバ関数

void setAuthTime (AuthorizationRequest authorizationRequest)
 

非公開変数類

ApprovedSiteService approvedSiteService
 
WhitelistedSiteService whitelistedSiteService
 
ClientDetailsService clientDetailsService
 
SystemScopeService systemScopes
 

詳解

Custom User Approval Handler implementation which uses a concept of a whitelist, blacklist, and greylist.

Blacklisted sites will be caught and handled before this point.

Whitelisted sites will be automatically approved, and an ApprovedSite entry will be created for the site the first time a given user access it.

All other sites fall into the greylist - the user will be presented with the user approval page upon their first visit

著者
aanganes

関数詳解

◆ checkForPreApproval()

AuthorizationRequest org.mitre.openid.connect.token.TofuUserApprovalHandler.checkForPreApproval ( AuthorizationRequest  authorizationRequest,
Authentication  userAuthentication 
)
inline

Check if the user has already stored a positive approval decision for this site; or if the site is whitelisted, approve it automatically.

Otherwise the user will be directed to the approval page and can make their own decision.

引数
authorizationRequestthe incoming authorization request
userAuthenticationthe Principal representing the currently-logged-in user
戻り値
the updated AuthorizationRequest
123  {
124 
125  //First, check database to see if the user identified by the userAuthentication has stored an approval decision
126 
127  String userId = userAuthentication.getName();
128  String clientId = authorizationRequest.getClientId();
129 
130  //lookup ApprovedSites by userId and clientId
131  boolean alreadyApproved = false;
132 
133  // find out if we're supposed to force a prompt on the user or not
134  String prompt = (String) authorizationRequest.getExtensions().get(PROMPT);
135  List<String> prompts = Splitter.on(PROMPT_SEPARATOR).splitToList(Strings.nullToEmpty(prompt));
136  if (!prompts.contains(PROMPT_CONSENT)) {
137  // if the prompt parameter is set to "consent" then we can't use approved sites or whitelisted sites
138  // otherwise, we need to check them below
139 
140  Collection<ApprovedSite> aps = approvedSiteService.getByClientIdAndUserId(clientId, userId);
141  for (ApprovedSite ap : aps) {
142 
143  if (!ap.isExpired()) {
144 
145  // if we find one that fits...
146  if (systemScopes.scopesMatch(ap.getAllowedScopes(), authorizationRequest.getScope())) {
147 
148  //We have a match; update the access date on the AP entry and return true.
149  ap.setAccessDate(new Date());
151 
152  String apId = ap.getId().toString();
153  authorizationRequest.getExtensions().put(APPROVED_SITE, apId);
154  authorizationRequest.setApproved(true);
155  alreadyApproved = true;
156 
157  setAuthTime(authorizationRequest);
158  }
159  }
160  }
161 
162  if (!alreadyApproved) {
163  WhitelistedSite ws = whitelistedSiteService.getByClientId(clientId);
164  if (ws != null && systemScopes.scopesMatch(ws.getAllowedScopes(), authorizationRequest.getScope())) {
165  authorizationRequest.setApproved(true);
166 
167  setAuthTime(authorizationRequest);
168  }
169  }
170  }
171 
172  return authorizationRequest;
173 
174  }
Long getId()
Definition: ApprovedSite.java:92
Collection< ApprovedSite > getByClientIdAndUserId(String clientId, String userId)
ApprovedSite save(ApprovedSite approvedSite)
ApprovedSiteService approvedSiteService
Definition: TofuUserApprovalHandler.java:74
boolean scopesMatch(Set< String > expected, Set< String > actual)
WhitelistedSiteService whitelistedSiteService
Definition: TofuUserApprovalHandler.java:77
WhitelistedSite getByClientId(String clientId)
SystemScopeService systemScopes
Definition: TofuUserApprovalHandler.java:83
void setAuthTime(AuthorizationRequest authorizationRequest)
Definition: TofuUserApprovalHandler.java:247

◆ getUserApprovalRequest()

Map<String, Object> org.mitre.openid.connect.token.TofuUserApprovalHandler.getUserApprovalRequest ( AuthorizationRequest  authorizationRequest,
Authentication  userAuthentication 
)
inline
264  {
265  Map<String, Object> model = new HashMap<>();
266  // In case of a redirect we might want the request parameters to be included
267  model.putAll(authorizationRequest.getRequestParameters());
268  return model;
269  }

◆ isApproved()

boolean org.mitre.openid.connect.token.TofuUserApprovalHandler.isApproved ( AuthorizationRequest  authorizationRequest,
Authentication  userAuthentication 
)
inline

Check if the user has already stored a positive approval decision for this site; or if the site is whitelisted, approve it automatically.

Otherwise, return false so that the user will see the approval page and can make their own decision.

引数
authorizationRequestthe incoming authorization request
userAuthenticationthe Principal representing the currently-logged-in user
戻り値
true if the site is approved, false otherwise
97  {
98 
99  // if this request is already approved, pass that info through
100  // (this flag may be set by updateBeforeApproval, which can also do funny things with scopes, etc)
101  if (authorizationRequest.isApproved()) {
102  return true;
103  } else {
104  // if not, check to see if the user has approved it
105  // TODO: make parameter name configurable?
106  return Boolean.parseBoolean(authorizationRequest.getApprovalParameters().get("user_oauth_approval"));
107  }
108 
109  }

◆ setAuthTime()

void org.mitre.openid.connect.token.TofuUserApprovalHandler.setAuthTime ( AuthorizationRequest  authorizationRequest)
inlineprivate

Get the auth time out of the current session and add it to the auth request in the extensions map.

引数
authorizationRequest
247  {
248  // Get the session auth time, if we have it, and store it in the request
249  ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
250  if (attr != null) {
251  HttpSession session = attr.getRequest().getSession();
252  if (session != null) {
253  Date authTime = (Date) session.getAttribute(AuthenticationTimeStamper.AUTH_TIMESTAMP);
254  if (authTime != null) {
255  String authTimeString = Long.toString(authTime.getTime());
256  authorizationRequest.getExtensions().put(AuthenticationTimeStamper.AUTH_TIMESTAMP, authTimeString);
257  }
258  }
259  }
260  }

◆ updateAfterApproval()

AuthorizationRequest org.mitre.openid.connect.token.TofuUserApprovalHandler.updateAfterApproval ( AuthorizationRequest  authorizationRequest,
Authentication  userAuthentication 
)
inline
178  {
179 
180  String userId = userAuthentication.getName();
181  String clientId = authorizationRequest.getClientId();
182  ClientDetails client = clientDetailsService.loadClientByClientId(clientId);
183 
184  // This must be re-parsed here because SECOAUTH forces us to call things in a strange order
185  if (Boolean.parseBoolean(authorizationRequest.getApprovalParameters().get("user_oauth_approval"))) {
186 
187  authorizationRequest.setApproved(true);
188 
189  // process scopes from user input
190  Set<String> allowedScopes = Sets.newHashSet();
191  Map<String,String> approvalParams = authorizationRequest.getApprovalParameters();
192 
193  Set<String> keys = approvalParams.keySet();
194 
195  for (String key : keys) {
196  if (key.startsWith("scope_")) {
197  //This is a scope parameter from the approval page. The value sent back should
198  //be the scope string. Check to make sure it is contained in the client's
199  //registered allowed scopes.
200 
201  String scope = approvalParams.get(key);
202  Set<String> approveSet = Sets.newHashSet(scope);
203 
204  //Make sure this scope is allowed for the given client
205  if (systemScopes.scopesMatch(client.getScope(), approveSet)) {
206 
207  allowedScopes.add(scope);
208  }
209 
210  }
211  }
212 
213  // inject the user-allowed scopes into the auth request
214  authorizationRequest.setScope(allowedScopes);
215 
216  //Only store an ApprovedSite if the user has checked "remember this decision":
217  String remember = authorizationRequest.getApprovalParameters().get("remember");
218  if (!Strings.isNullOrEmpty(remember) && !remember.equals("none")) {
219 
220  Date timeout = null;
221  if (remember.equals("one-hour")) {
222  // set the timeout to one hour from now
223  Calendar cal = Calendar.getInstance();
224  cal.add(Calendar.HOUR, 1);
225  timeout = cal.getTime();
226  }
227 
228  ApprovedSite newSite = approvedSiteService.createApprovedSite(clientId, userId, timeout, allowedScopes);
229  String newSiteId = newSite.getId().toString();
230  authorizationRequest.getExtensions().put(APPROVED_SITE, newSiteId);
231  }
232 
233  setAuthTime(authorizationRequest);
234 
235 
236  }
237 
238  return authorizationRequest;
239  }
Long getId()
Definition: ApprovedSite.java:92
ApprovedSite createApprovedSite(String clientId, String userId, Date timeoutDate, Set< String > allowedScopes)
ApprovedSiteService approvedSiteService
Definition: TofuUserApprovalHandler.java:74
ClientDetailsService clientDetailsService
Definition: TofuUserApprovalHandler.java:80
boolean scopesMatch(Set< String > expected, Set< String > actual)
SystemScopeService systemScopes
Definition: TofuUserApprovalHandler.java:83
void setAuthTime(AuthorizationRequest authorizationRequest)
Definition: TofuUserApprovalHandler.java:247

メンバ詳解

◆ approvedSiteService

ApprovedSiteService org.mitre.openid.connect.token.TofuUserApprovalHandler.approvedSiteService
private

◆ clientDetailsService

ClientDetailsService org.mitre.openid.connect.token.TofuUserApprovalHandler.clientDetailsService
private

◆ systemScopes

SystemScopeService org.mitre.openid.connect.token.TofuUserApprovalHandler.systemScopes
private

◆ whitelistedSiteService

WhitelistedSiteService org.mitre.openid.connect.token.TofuUserApprovalHandler.whitelistedSiteService
private

このクラス詳解は次のファイルから抽出されました: