mitreid-connect
公開メンバ関数 | 静的公開変数類 | 非公開変数類 | 全メンバ一覧
org.mitre.oauth2.web.DeviceEndpoint クラス
org.mitre.oauth2.web.DeviceEndpoint 連携図
Collaboration graph

公開メンバ関数

String requestDeviceCode (@RequestParam("client_id") String clientId, @RequestParam(name="scope", required=false) String scope, Map< String, String > parameters, ModelMap model)
 
String requestUserCode (ModelMap model)
 
String readUserCode (@RequestParam("user_code") String userCode, ModelMap model, HttpSession session)
 
String approveDevice (@RequestParam("user_code") String userCode, @RequestParam(value="user_oauth_approval") Boolean approve, ModelMap model, Authentication auth, HttpSession session)
 

静的公開変数類

static final String URL = "devicecode"
 
static final String USER_URL = "device"
 
static final Logger logger = LoggerFactory.getLogger(DeviceEndpoint.class)
 

非公開変数類

ClientDetailsEntityService clientService
 
SystemScopeService scopeService
 
ConfigurationPropertiesBean config
 
DeviceCodeService deviceCodeService
 
OAuth2RequestFactory oAuth2RequestFactory
 

詳解

Implements https://tools.ietf.org/html/draft-ietf-oauth-device-flow

参照
DeviceTokenGranter
著者
jricher

関数詳解

◆ approveDevice()

String org.mitre.oauth2.web.DeviceEndpoint.approveDevice ( @RequestParam("user_code") String  userCode,
@RequestParam(value="user_oauth_approval") Boolean  approve,
ModelMap  model,
Authentication  auth,
HttpSession  session 
)
inline
229  {
230 
231  AuthorizationRequest authorizationRequest = (AuthorizationRequest) session.getAttribute("authorizationRequest");
232  DeviceCode dc = (DeviceCode) session.getAttribute("deviceCode");
233 
234  // make sure the form that was submitted is the one that we were expecting
235  if (!dc.getUserCode().equals(userCode)) {
236  model.addAttribute("error", "userCodeMismatch");
237  return "requestUserCode";
238  }
239 
240  // make sure the code hasn't expired yet
241  if (dc.getExpiration() != null && dc.getExpiration().before(new Date())) {
242  model.addAttribute("error", "expiredUserCode");
243  return "requestUserCode";
244  }
245 
246  ClientDetailsEntity client = clientService.loadClientByClientId(dc.getClientId());
247 
248  model.put("client", client);
249 
250  // user did not approve
251  if (!approve) {
252  model.addAttribute("approved", false);
253  return "deviceApproved";
254  }
255 
256  // create an OAuth request for storage
257  OAuth2Request o2req = oAuth2RequestFactory.createOAuth2Request(authorizationRequest);
258  OAuth2Authentication o2Auth = new OAuth2Authentication(o2req, auth);
259 
260  DeviceCode approvedCode = deviceCodeService.approveDeviceCode(dc, o2Auth);
261 
262  // pre-process the scopes
263  Set<SystemScope> scopes = scopeService.fromStrings(dc.getScope());
264 
265  Set<SystemScope> sortedScopes = new LinkedHashSet<>(scopes.size());
266  Set<SystemScope> systemScopes = scopeService.getAll();
267 
268  // sort scopes for display based on the inherent order of system scopes
269  for (SystemScope s : systemScopes) {
270  if (scopes.contains(s)) {
271  sortedScopes.add(s);
272  }
273  }
274 
275  // add in any scopes that aren't system scopes to the end of the list
276  sortedScopes.addAll(Sets.difference(scopes, systemScopes));
277 
278  model.put("scopes", sortedScopes);
279  model.put("approved", true);
280 
281  return "deviceApproved";
282  }
SystemScopeService scopeService
Definition: DeviceEndpoint.java:83
ClientDetailsEntityService clientService
Definition: DeviceEndpoint.java:80
Set< SystemScope > fromStrings(Set< String > scope)
DeviceCode approveDeviceCode(DeviceCode dc, OAuth2Authentication o2Auth)
OAuth2RequestFactory oAuth2RequestFactory
Definition: DeviceEndpoint.java:92
ClientDetailsEntity loadClientByClientId(String clientId)
DeviceCodeService deviceCodeService
Definition: DeviceEndpoint.java:89

◆ readUserCode()

String org.mitre.oauth2.web.DeviceEndpoint.readUserCode ( @RequestParam("user_code") String  userCode,
ModelMap  model,
HttpSession  session 
)
inline
173  {
174 
175  // look up the request based on the user code
176  DeviceCode dc = deviceCodeService.lookUpByUserCode(userCode);
177 
178  // we couldn't find the device code
179  if (dc == null) {
180  model.addAttribute("error", "noUserCode");
181  return "requestUserCode";
182  }
183 
184  // make sure the code hasn't expired yet
185  if (dc.getExpiration() != null && dc.getExpiration().before(new Date())) {
186  model.addAttribute("error", "expiredUserCode");
187  return "requestUserCode";
188  }
189 
190  // make sure the device code hasn't already been approved
191  if (dc.isApproved()) {
192  model.addAttribute("error", "userCodeAlreadyApproved");
193  return "requestUserCode";
194  }
195 
196  ClientDetailsEntity client = clientService.loadClientByClientId(dc.getClientId());
197 
198  model.put("client", client);
199  model.put("dc", dc);
200 
201  // pre-process the scopes
202  Set<SystemScope> scopes = scopeService.fromStrings(dc.getScope());
203 
204  Set<SystemScope> sortedScopes = new LinkedHashSet<>(scopes.size());
205  Set<SystemScope> systemScopes = scopeService.getAll();
206 
207  // sort scopes for display based on the inherent order of system scopes
208  for (SystemScope s : systemScopes) {
209  if (scopes.contains(s)) {
210  sortedScopes.add(s);
211  }
212  }
213 
214  // add in any scopes that aren't system scopes to the end of the list
215  sortedScopes.addAll(Sets.difference(scopes, systemScopes));
216 
217  model.put("scopes", sortedScopes);
218 
219  AuthorizationRequest authorizationRequest = oAuth2RequestFactory.createAuthorizationRequest(dc.getRequestParameters());
220 
221  session.setAttribute("authorizationRequest", authorizationRequest);
222  session.setAttribute("deviceCode", dc);
223 
224  return "approveDevice";
225  }
SystemScopeService scopeService
Definition: DeviceEndpoint.java:83
DeviceCode lookUpByUserCode(String userCode)
ClientDetailsEntityService clientService
Definition: DeviceEndpoint.java:80
Set< SystemScope > fromStrings(Set< String > scope)
OAuth2RequestFactory oAuth2RequestFactory
Definition: DeviceEndpoint.java:92
ClientDetailsEntity loadClientByClientId(String clientId)
DeviceCodeService deviceCodeService
Definition: DeviceEndpoint.java:89

◆ requestDeviceCode()

String org.mitre.oauth2.web.DeviceEndpoint.requestDeviceCode ( @RequestParam("client_id") String  clientId,
@RequestParam(name="scope", required=false) String  scope,
Map< String, String >  parameters,
ModelMap  model 
)
inline
95  {
96 
97  ClientDetailsEntity client;
98  try {
99  client = clientService.loadClientByClientId(clientId);
100 
101  // make sure this client can do the device flow
102 
103  Collection<String> authorizedGrantTypes = client.getAuthorizedGrantTypes();
104  if (authorizedGrantTypes != null && !authorizedGrantTypes.isEmpty()
105  && !authorizedGrantTypes.contains(DeviceTokenGranter.GRANT_TYPE)) {
106  throw new InvalidClientException("Unauthorized grant type: " + DeviceTokenGranter.GRANT_TYPE);
107  }
108 
109  } catch (IllegalArgumentException e) {
110  logger.error("IllegalArgumentException was thrown when attempting to load client", e);
111  model.put(HttpCodeView.CODE, HttpStatus.BAD_REQUEST);
112  return HttpCodeView.VIEWNAME;
113  }
114 
115  if (client == null) {
116  logger.error("could not find client " + clientId);
117  model.put(HttpCodeView.CODE, HttpStatus.NOT_FOUND);
118  return HttpCodeView.VIEWNAME;
119  }
120 
121  // make sure the client is allowed to ask for those scopes
122  Set<String> requestedScopes = OAuth2Utils.parseParameterList(scope);
123  Set<String> allowedScopes = client.getScope();
124 
125  if (!scopeService.scopesMatch(allowedScopes, requestedScopes)) {
126  // client asked for scopes it can't have
127  logger.error("Client asked for " + requestedScopes + " but is allowed " + allowedScopes);
128  model.put(HttpCodeView.CODE, HttpStatus.BAD_REQUEST);
129  model.put(JsonErrorView.ERROR, "invalid_scope");
130  return JsonErrorView.VIEWNAME;
131  }
132 
133  // if we got here the request is legit
134 
135  try {
136  DeviceCode dc = deviceCodeService.createNewDeviceCode(requestedScopes, client, parameters);
137 
138  Map<String, Object> response = new HashMap<>();
139  response.put("device_code", dc.getDeviceCode());
140  response.put("user_code", dc.getUserCode());
141  response.put("verification_uri", config.getIssuer() + USER_URL);
142  if (client.getDeviceCodeValiditySeconds() != null) {
143  response.put("expires_in", client.getDeviceCodeValiditySeconds());
144  }
145 
146  model.put(JsonEntityView.ENTITY, response);
147 
148 
149  return JsonEntityView.VIEWNAME;
150  } catch (DeviceCodeCreationException dcce) {
151 
152  model.put(HttpCodeView.CODE, HttpStatus.BAD_REQUEST);
153  model.put(JsonErrorView.ERROR, dcce.getError());
154  model.put(JsonErrorView.ERROR_MESSAGE, dcce.getMessage());
155 
156  return JsonErrorView.VIEWNAME;
157  }
158 
159  }
SystemScopeService scopeService
Definition: DeviceEndpoint.java:83
ClientDetailsEntityService clientService
Definition: DeviceEndpoint.java:80
static final Logger logger
Definition: DeviceEndpoint.java:77
ConfigurationPropertiesBean config
Definition: DeviceEndpoint.java:86
static final String USER_URL
Definition: DeviceEndpoint.java:75
Set< String > getAuthorizedGrantTypes()
Definition: ClientDetailsEntity.java:475
boolean scopesMatch(Set< String > expected, Set< String > actual)
DeviceCode createNewDeviceCode(Set< String > requestedScopes, ClientDetailsEntity client, Map< String, String > parameters)
ClientDetailsEntity loadClientByClientId(String clientId)
DeviceCodeService deviceCodeService
Definition: DeviceEndpoint.java:89
String getIssuer()
Definition: ConfigurationPropertiesBean.java:100

◆ requestUserCode()

String org.mitre.oauth2.web.DeviceEndpoint.requestUserCode ( ModelMap  model)
inline
163  {
164 
165  // print out a page that asks the user to enter their user code
166  // user must be logged in
167 
168  return "requestUserCode";
169  }

メンバ詳解

◆ clientService

ClientDetailsEntityService org.mitre.oauth2.web.DeviceEndpoint.clientService
private

◆ config

ConfigurationPropertiesBean org.mitre.oauth2.web.DeviceEndpoint.config
private

◆ deviceCodeService

DeviceCodeService org.mitre.oauth2.web.DeviceEndpoint.deviceCodeService
private

◆ logger

final Logger org.mitre.oauth2.web.DeviceEndpoint.logger = LoggerFactory.getLogger(DeviceEndpoint.class)
static

◆ oAuth2RequestFactory

OAuth2RequestFactory org.mitre.oauth2.web.DeviceEndpoint.oAuth2RequestFactory
private

◆ scopeService

SystemScopeService org.mitre.oauth2.web.DeviceEndpoint.scopeService
private

◆ URL

final String org.mitre.oauth2.web.DeviceEndpoint.URL = "devicecode"
static

◆ USER_URL

final String org.mitre.oauth2.web.DeviceEndpoint.USER_URL = "device"
static

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