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

公開メンバ関数

String getResourceSetsForCurrentUser (Model m, Authentication auth)
 
String getResourceSet (@PathVariable(value="rsid") Long rsid, Model m, Authentication auth)
 
String deleteResourceSet (@PathVariable(value="rsid") Long rsid, Model m, Authentication auth)
 
String getPoliciesForResourceSet (@PathVariable(value="rsid") Long rsid, Model m, Authentication auth)
 
String createNewPolicyForResourceSet (@PathVariable(value="rsid") Long rsid, @RequestBody String jsonString, Model m, Authentication auth)
 
String getPolicy (@PathVariable(value="rsid") Long rsid, @PathVariable(value="pid") Long pid, Model m, Authentication auth)
 
String setClaimsForResourceSet (@PathVariable(value="rsid") Long rsid, @PathVariable(value="pid") Long pid, @RequestBody String jsonString, Model m, Authentication auth)
 
String deleteResourceSet (@PathVariable("rsid") Long rsid, @PathVariable(value="pid") Long pid, Model m, Authentication auth)
 

静的公開変数類

static final String URL = RootController.API_URL + "/resourceset"
 
static final String POLICYURL = "/policy"
 

非公開変数類

Gson gson = new Gson()
 
ResourceSetService resourceSetService
 

静的非公開変数類

static final Logger logger = LoggerFactory.getLogger(PolicyAPI.class)
 

詳解

API for managing policies on resource sets.

著者
jricher

関数詳解

◆ createNewPolicyForResourceSet()

String org.mitre.uma.web.PolicyAPI.createNewPolicyForResourceSet ( @PathVariable(value="rsid") Long  rsid,
@RequestBody String  jsonString,
Model  m,
Authentication  auth 
)
inline

Create a new policy on the given resource set

引数
rsid
m
auth
戻り値
185  {
186  ResourceSet rs = resourceSetService.getById(rsid);
187 
188  if (rs == null) {
189  m.addAttribute(HttpCodeView.CODE, HttpStatus.NOT_FOUND);
190  return HttpCodeView.VIEWNAME;
191  }
192 
193  if (!rs.getOwner().equals(auth.getName())) {
194  logger.warn("Unauthorized resource set request from bad user; expected " + rs.getOwner() + " got " + auth.getName());
195 
196  // authenticated user didn't match the owner of the resource set
197  m.addAttribute(HttpCodeView.CODE, HttpStatus.FORBIDDEN);
198  return HttpCodeView.VIEWNAME;
199  }
200 
201  Policy p = gson.fromJson(jsonString, Policy.class);
202 
203  if (p.getId() != null) {
204  logger.warn("Tried to add a policy with a non-null ID: " + p.getId());
205  m.addAttribute(HttpCodeView.CODE, HttpStatus.BAD_REQUEST);
206  return HttpCodeView.VIEWNAME;
207  }
208 
209  for (Claim claim : p.getClaimsRequired()) {
210  if (claim.getId() != null) {
211  logger.warn("Tried to add a policy with a non-null claim ID: " + claim.getId());
212  m.addAttribute(HttpCodeView.CODE, HttpStatus.BAD_REQUEST);
213  return HttpCodeView.VIEWNAME;
214  }
215  }
216 
217  rs.getPolicies().add(p);
218  ResourceSet saved = resourceSetService.update(rs, rs);
219 
220  // find the new policy object
221  Collection<Policy> newPolicies = Sets.difference(new HashSet<>(saved.getPolicies()), new HashSet<>(rs.getPolicies()));
222 
223  if (newPolicies.size() == 1) {
224  Policy newPolicy = newPolicies.iterator().next();
225  m.addAttribute(JsonEntityView.ENTITY, newPolicy);
226  return JsonEntityView.VIEWNAME;
227  } else {
228  logger.warn("Unexpected result trying to add a new policy object: " + newPolicies);
229  m.addAttribute(HttpCodeView.CODE, HttpStatus.INTERNAL_SERVER_ERROR);
230  return HttpCodeView.VIEWNAME;
231  }
232 
233  }
ResourceSet update(ResourceSet oldRs, ResourceSet newRs)
ResourceSetService resourceSetService
Definition: PolicyAPI.java:68
Gson gson
Definition: PolicyAPI.java:65
static final Logger logger
Definition: PolicyAPI.java:60

◆ deleteResourceSet() [1/2]

String org.mitre.uma.web.PolicyAPI.deleteResourceSet ( @PathVariable(value="rsid") Long  rsid,
Model  m,
Authentication  auth 
)
inline

Delete the indicated resource set

引数
rsid
m
auth
戻り値
124  {
125 
126  ResourceSet rs = resourceSetService.getById(rsid);
127 
128  if (rs == null) {
129  m.addAttribute(HttpCodeView.CODE, HttpStatus.NOT_FOUND);
130  return HttpCodeView.VIEWNAME;
131  }
132 
133  if (!rs.getOwner().equals(auth.getName())) {
134  logger.warn("Unauthorized resource set request from bad user; expected " + rs.getOwner() + " got " + auth.getName());
135 
136  // authenticated user didn't match the owner of the resource set
137  m.addAttribute(HttpCodeView.CODE, HttpStatus.FORBIDDEN);
138  return HttpCodeView.VIEWNAME;
139  }
140 
142  m.addAttribute(HttpCodeView.CODE, HttpStatus.NO_CONTENT);
143  return HttpCodeView.VIEWNAME;
144 
145  }
ResourceSetService resourceSetService
Definition: PolicyAPI.java:68
static final Logger logger
Definition: PolicyAPI.java:60

◆ deleteResourceSet() [2/2]

String org.mitre.uma.web.PolicyAPI.deleteResourceSet ( @PathVariable("rsid") Long  rsid,
@PathVariable(value="pid") Long  pid,
Model  m,
Authentication  auth 
)
inline

Delete a specific policy

引数
rsid
pid
m
auth
戻り値
354  {
355 
356  ResourceSet rs = resourceSetService.getById(rsid);
357 
358  if (rs == null) {
359  m.addAttribute(HttpCodeView.CODE, HttpStatus.NOT_FOUND);
360  m.addAttribute(JsonErrorView.ERROR, "not_found");
361  return JsonErrorView.VIEWNAME;
362  }
363 
364  if (!auth.getName().equals(rs.getOwner())) {
365 
366  logger.warn("Unauthorized resource set request from bad user; expected " + rs.getOwner() + " got " + auth.getName());
367 
368  // it wasn't issued to this user
369  m.addAttribute(HttpCodeView.CODE, HttpStatus.FORBIDDEN);
370  return JsonErrorView.VIEWNAME;
371  }
372 
373 
374  for (Policy policy : rs.getPolicies()) {
375  if (policy.getId().equals(pid)) {
376  // found it!
377  rs.getPolicies().remove(policy);
378  resourceSetService.update(rs, rs);
379 
380  m.addAttribute(HttpCodeView.CODE, HttpStatus.NO_CONTENT);
381  return HttpCodeView.VIEWNAME;
382  }
383  }
384 
385  // if we made it this far, we haven't found it
386  m.addAttribute(HttpCodeView.CODE, HttpStatus.NOT_FOUND);
387  return HttpCodeView.VIEWNAME;
388 
389  }
ResourceSet update(ResourceSet oldRs, ResourceSet newRs)
ResourceSetService resourceSetService
Definition: PolicyAPI.java:68
static final Logger logger
Definition: PolicyAPI.java:60

◆ getPoliciesForResourceSet()

String org.mitre.uma.web.PolicyAPI.getPoliciesForResourceSet ( @PathVariable(value="rsid") Long  rsid,
Model  m,
Authentication  auth 
)
inline

List all the policies for the given resource set

引数
rsid
m
auth
戻り値
155  {
156 
157  ResourceSet rs = resourceSetService.getById(rsid);
158 
159  if (rs == null) {
160  m.addAttribute(HttpCodeView.CODE, HttpStatus.NOT_FOUND);
161  return HttpCodeView.VIEWNAME;
162  }
163 
164  if (!rs.getOwner().equals(auth.getName())) {
165  logger.warn("Unauthorized resource set request from bad user; expected " + rs.getOwner() + " got " + auth.getName());
166 
167  // authenticated user didn't match the owner of the resource set
168  m.addAttribute(HttpCodeView.CODE, HttpStatus.FORBIDDEN);
169  return HttpCodeView.VIEWNAME;
170  }
171 
172  m.addAttribute(JsonEntityView.ENTITY, rs.getPolicies());
173 
174  return JsonEntityView.VIEWNAME;
175  }
ResourceSetService resourceSetService
Definition: PolicyAPI.java:68
static final Logger logger
Definition: PolicyAPI.java:60

◆ getPolicy()

String org.mitre.uma.web.PolicyAPI.getPolicy ( @PathVariable(value="rsid") Long  rsid,
@PathVariable(value="pid") Long  pid,
Model  m,
Authentication  auth 
)
inline

Get a specific policy

引数
rsid
pid
m
auth
戻り値
244  {
245 
246  ResourceSet rs = resourceSetService.getById(rsid);
247 
248  if (rs == null) {
249  m.addAttribute(HttpCodeView.CODE, HttpStatus.NOT_FOUND);
250  return HttpCodeView.VIEWNAME;
251  }
252 
253  if (!rs.getOwner().equals(auth.getName())) {
254  logger.warn("Unauthorized resource set request from bad user; expected " + rs.getOwner() + " got " + auth.getName());
255 
256  // authenticated user didn't match the owner of the resource set
257  m.addAttribute(HttpCodeView.CODE, HttpStatus.FORBIDDEN);
258  return HttpCodeView.VIEWNAME;
259  }
260 
261  for (Policy policy : rs.getPolicies()) {
262  if (policy.getId().equals(pid)) {
263  // found it!
264  m.addAttribute(JsonEntityView.ENTITY, policy);
265  return JsonEntityView.VIEWNAME;
266  }
267  }
268 
269  // if we made it this far, we haven't found it
270  m.addAttribute(HttpCodeView.CODE, HttpStatus.NOT_FOUND);
271  return HttpCodeView.VIEWNAME;
272  }
ResourceSetService resourceSetService
Definition: PolicyAPI.java:68
static final Logger logger
Definition: PolicyAPI.java:60

◆ getResourceSet()

String org.mitre.uma.web.PolicyAPI.getResourceSet ( @PathVariable(value="rsid") Long  rsid,
Model  m,
Authentication  auth 
)
inline

Get the indicated resource set

引数
rsid
m
auth
戻り値
94  {
95 
96  ResourceSet rs = resourceSetService.getById(rsid);
97 
98  if (rs == null) {
99  m.addAttribute(HttpCodeView.CODE, HttpStatus.NOT_FOUND);
100  return HttpCodeView.VIEWNAME;
101  }
102 
103  if (!rs.getOwner().equals(auth.getName())) {
104  logger.warn("Unauthorized resource set request from bad user; expected " + rs.getOwner() + " got " + auth.getName());
105 
106  // authenticated user didn't match the owner of the resource set
107  m.addAttribute(HttpCodeView.CODE, HttpStatus.FORBIDDEN);
108  return HttpCodeView.VIEWNAME;
109  }
110 
111  m.addAttribute(JsonEntityView.ENTITY, rs);
112 
113  return JsonEntityView.VIEWNAME;
114  }
ResourceSetService resourceSetService
Definition: PolicyAPI.java:68
static final Logger logger
Definition: PolicyAPI.java:60

◆ getResourceSetsForCurrentUser()

String org.mitre.uma.web.PolicyAPI.getResourceSetsForCurrentUser ( Model  m,
Authentication  auth 
)
inline

List all resource sets for the current user

引数
m
auth
戻り値
77  {
78 
79  Collection<ResourceSet> resourceSets = resourceSetService.getAllForOwner(auth.getName());
80 
81  m.addAttribute(JsonEntityView.ENTITY, resourceSets);
82 
83  return JsonEntityView.VIEWNAME;
84  }
Collection< ResourceSet > getAllForOwner(String owner)
ResourceSetService resourceSetService
Definition: PolicyAPI.java:68

◆ setClaimsForResourceSet()

String org.mitre.uma.web.PolicyAPI.setClaimsForResourceSet ( @PathVariable(value="rsid") Long  rsid,
@PathVariable(value="pid") Long  pid,
@RequestBody String  jsonString,
Model  m,
Authentication  auth 
)
inline

Update a specific policy

引数
rsid
pid
jsonString
m
auth
戻り値
284  {
285 
286  ResourceSet rs = resourceSetService.getById(rsid);
287 
288  if (rs == null) {
289  m.addAttribute(HttpCodeView.CODE, HttpStatus.NOT_FOUND);
290  return HttpCodeView.VIEWNAME;
291  }
292 
293  if (!rs.getOwner().equals(auth.getName())) {
294  logger.warn("Unauthorized resource set request from bad user; expected " + rs.getOwner() + " got " + auth.getName());
295 
296  // authenticated user didn't match the owner of the resource set
297  m.addAttribute(HttpCodeView.CODE, HttpStatus.FORBIDDEN);
298  return HttpCodeView.VIEWNAME;
299  }
300 
301  Policy p = gson.fromJson(jsonString, Policy.class);
302 
303  if (!pid.equals(p.getId())) {
304  logger.warn("Policy ID mismatch, expected " + pid + " got " + p.getId());
305 
306  m.addAttribute(HttpCodeView.CODE, HttpStatus.BAD_REQUEST);
307  return HttpCodeView.VIEWNAME;
308  }
309 
310  for (Policy policy : rs.getPolicies()) {
311  if (policy.getId().equals(pid)) {
312  // found it!
313 
314  // find the existing claim IDs, make sure we're not overwriting anything from another policy
315  Set<Long> claimIds = new HashSet<>();
316  for (Claim claim : policy.getClaimsRequired()) {
317  claimIds.add(claim.getId());
318  }
319 
320  for (Claim claim : p.getClaimsRequired()) {
321  if (claim.getId() != null && !claimIds.contains(claim.getId())) {
322  logger.warn("Tried to add a policy with a an unmatched claim ID: got " + claim.getId() + " expected " + claimIds);
323  m.addAttribute(HttpCodeView.CODE, HttpStatus.BAD_REQUEST);
324  return HttpCodeView.VIEWNAME;
325  }
326  }
327 
328  // update the existing object with the new values
329  policy.setClaimsRequired(p.getClaimsRequired());
330  policy.setName(p.getName());
331  policy.setScopes(p.getScopes());
332 
333  resourceSetService.update(rs, rs);
334 
335  m.addAttribute(JsonEntityView.ENTITY, policy);
336  return JsonEntityView.VIEWNAME;
337  }
338  }
339 
340  // if we made it this far, we haven't found it
341  m.addAttribute(HttpCodeView.CODE, HttpStatus.NOT_FOUND);
342  return HttpCodeView.VIEWNAME;
343  }
ResourceSet update(ResourceSet oldRs, ResourceSet newRs)
ResourceSetService resourceSetService
Definition: PolicyAPI.java:68
Gson gson
Definition: PolicyAPI.java:65
static final Logger logger
Definition: PolicyAPI.java:60

メンバ詳解

◆ gson

Gson org.mitre.uma.web.PolicyAPI.gson = new Gson()
private

◆ logger

final Logger org.mitre.uma.web.PolicyAPI.logger = LoggerFactory.getLogger(PolicyAPI.class)
staticprivate

◆ POLICYURL

final String org.mitre.uma.web.PolicyAPI.POLICYURL = "/policy"
static

◆ resourceSetService

ResourceSetService org.mitre.uma.web.PolicyAPI.resourceSetService
private

◆ URL

final String org.mitre.uma.web.PolicyAPI.URL = RootController.API_URL + "/resourceset"
static

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