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

公開メンバ関数

String createResourceSet (@RequestBody String jsonString, Model m, Authentication auth)
 
String readResourceSet (@PathVariable("id") Long id, Model m, Authentication auth)
 
String updateResourceSet (@PathVariable("id") Long id, @RequestBody String jsonString, Model m, Authentication auth)
 
String deleteResourceSet (@PathVariable("id") Long id, Model m, Authentication auth)
 
String listResourceSets (Model m, Authentication auth)
 

静的公開変数類

static final String DISCOVERY_URL = "resource_set"
 
static final String URL = DISCOVERY_URL + "/resource_set"
 

非公開メンバ関数

ResourceSet parseResourceSet (String jsonString)
 
ResourceSet validateScopes (ResourceSet rs)
 

非公開変数類

ResourceSetService resourceSetService
 
ConfigurationPropertiesBean config
 
SystemScopeService scopeService
 
JsonParser parser = new JsonParser()
 

静的非公開変数類

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

詳解

関数詳解

◆ createResourceSet()

String org.mitre.uma.web.ResourceSetRegistrationEndpoint.createResourceSet ( @RequestBody String  jsonString,
Model  m,
Authentication  auth 
)
inline
82  {
83  ensureOAuthScope(auth, SystemScopeService.UMA_PROTECTION_SCOPE);
84 
85  ResourceSet rs = parseResourceSet(jsonString);
86 
87  if (rs == null) { // there was no resource set in the body
88  logger.warn("Resource set registration missing body.");
89 
90  m.addAttribute("code", HttpStatus.BAD_REQUEST);
91  m.addAttribute("error_description", "Resource request was missing body.");
92  return JsonErrorView.VIEWNAME;
93  }
94 
95  if (auth instanceof OAuth2Authentication) {
96  // if it's an OAuth mediated call, it's on behalf of a client, so store that
97  OAuth2Authentication o2a = (OAuth2Authentication) auth;
98  rs.setClientId(o2a.getOAuth2Request().getClientId());
99  rs.setOwner(auth.getName()); // the username is going to be in the auth object
100  } else {
101  // this one shouldn't be called if it's not OAuth
102  m.addAttribute(HttpCodeView.CODE, HttpStatus.BAD_REQUEST);
103  m.addAttribute(JsonErrorView.ERROR_MESSAGE, "This call must be made with an OAuth token");
104  return JsonErrorView.VIEWNAME;
105  }
106 
107  rs = validateScopes(rs);
108 
109  if (Strings.isNullOrEmpty(rs.getName()) // there was no name (required)
110  || rs.getScopes() == null // there were no scopes (required)
111  ) {
112 
113  logger.warn("Resource set registration missing one or more required fields.");
114 
115  m.addAttribute(HttpCodeView.CODE, HttpStatus.BAD_REQUEST);
116  m.addAttribute(JsonErrorView.ERROR_MESSAGE, "Resource request was missing one or more required fields.");
117  return JsonErrorView.VIEWNAME;
118  }
119 
120  ResourceSet saved = resourceSetService.saveNew(rs);
121 
122  m.addAttribute(HttpCodeView.CODE, HttpStatus.CREATED);
123  m.addAttribute(JsonEntityView.ENTITY, saved);
124  m.addAttribute(ResourceSetEntityAbbreviatedView.LOCATION, config.getIssuer() + URL + "/" + saved.getId());
125 
126  return ResourceSetEntityAbbreviatedView.VIEWNAME;
127 
128  }
ResourceSet saveNew(ResourceSet rs)
ResourceSetService resourceSetService
Definition: ResourceSetRegistrationEndpoint.java:71
static final String URL
Definition: ResourceSetRegistrationEndpoint.java:68
static final Logger logger
Definition: ResourceSetRegistrationEndpoint.java:65
ResourceSet validateScopes(ResourceSet rs)
Definition: ResourceSetRegistrationEndpoint.java:305
ResourceSet parseResourceSet(String jsonString)
Definition: ResourceSetRegistrationEndpoint.java:270
String getIssuer()
Definition: ConfigurationPropertiesBean.java:100
ConfigurationPropertiesBean config
Definition: ResourceSetRegistrationEndpoint.java:74

◆ deleteResourceSet()

String org.mitre.uma.web.ResourceSetRegistrationEndpoint.deleteResourceSet ( @PathVariable("id") Long  id,
Model  m,
Authentication  auth 
)
inline
206  {
207  ensureOAuthScope(auth, SystemScopeService.UMA_PROTECTION_SCOPE);
208 
209  ResourceSet rs = resourceSetService.getById(id);
210 
211  if (rs == null) {
212  m.addAttribute(HttpCodeView.CODE, HttpStatus.NOT_FOUND);
213  m.addAttribute(JsonErrorView.ERROR, "not_found");
214  return JsonErrorView.VIEWNAME;
215  } else {
216  if (!auth.getName().equals(rs.getOwner())) {
217 
218  logger.warn("Unauthorized resource set request from bad user; expected " + rs.getOwner() + " got " + auth.getName());
219 
220  // it wasn't issued to this user
221  m.addAttribute(HttpCodeView.CODE, HttpStatus.FORBIDDEN);
222  return JsonErrorView.VIEWNAME;
223  } else if (auth instanceof OAuth2Authentication &&
224  !((OAuth2Authentication)auth).getOAuth2Request().getClientId().equals(rs.getClientId())){
225 
226  logger.warn("Unauthorized resource set request from bad client; expected " + rs.getClientId() + " got " + ((OAuth2Authentication)auth).getOAuth2Request().getClientId());
227 
228  // it wasn't issued to this client
229  m.addAttribute(HttpCodeView.CODE, HttpStatus.FORBIDDEN);
230  return JsonErrorView.VIEWNAME;
231  } else {
232 
233  // user and client matched
235 
236  m.addAttribute(HttpCodeView.CODE, HttpStatus.NO_CONTENT);
237  return HttpCodeView.VIEWNAME;
238  }
239 
240  }
241  }
ResourceSetService resourceSetService
Definition: ResourceSetRegistrationEndpoint.java:71
static final Logger logger
Definition: ResourceSetRegistrationEndpoint.java:65

◆ listResourceSets()

String org.mitre.uma.web.ResourceSetRegistrationEndpoint.listResourceSets ( Model  m,
Authentication  auth 
)
inline
244  {
245  ensureOAuthScope(auth, SystemScopeService.UMA_PROTECTION_SCOPE);
246 
247  String owner = auth.getName();
248 
249  Collection<ResourceSet> resourceSets = Collections.emptySet();
250  if (auth instanceof OAuth2Authentication) {
251  // if it's an OAuth mediated call, it's on behalf of a client, so look that up too
252  OAuth2Authentication o2a = (OAuth2Authentication) auth;
253  resourceSets = resourceSetService.getAllForOwnerAndClient(owner, o2a.getOAuth2Request().getClientId());
254  } else {
255  // otherwise get everything for the current user
256  resourceSets = resourceSetService.getAllForOwner(owner);
257  }
258 
259  // build the entity here and send to the display
260 
261  Set<String> ids = new HashSet<>();
262  for (ResourceSet resourceSet : resourceSets) {
263  ids.add(resourceSet.getId().toString()); // add them all as strings so that gson renders them properly
264  }
265 
266  m.addAttribute(JsonEntityView.ENTITY, ids);
267  return JsonEntityView.VIEWNAME;
268  }
Collection< ResourceSet > getAllForOwner(String owner)
ResourceSetService resourceSetService
Definition: ResourceSetRegistrationEndpoint.java:71
Collection< ResourceSet > getAllForOwnerAndClient(String owner, String authClientId)

◆ parseResourceSet()

ResourceSet org.mitre.uma.web.ResourceSetRegistrationEndpoint.parseResourceSet ( String  jsonString)
inlineprivate
270  {
271 
272  try {
273  JsonElement el = parser.parse(jsonString);
274 
275  if (el.isJsonObject()) {
276  JsonObject o = el.getAsJsonObject();
277 
278  ResourceSet rs = new ResourceSet();
279  rs.setId(getAsLong(o, "_id"));
280  rs.setName(getAsString(o, "name"));
281  rs.setIconUri(getAsString(o, "icon_uri"));
282  rs.setType(getAsString(o, "type"));
283  rs.setScopes(getAsStringSet(o, "scopes"));
284  rs.setUri(getAsString(o, "uri"));
285 
286  return rs;
287 
288  }
289 
290  return null;
291 
292  } catch (JsonParseException e) {
293  return null;
294  }
295 
296  }
JsonParser parser
Definition: ResourceSetRegistrationEndpoint.java:79

◆ readResourceSet()

String org.mitre.uma.web.ResourceSetRegistrationEndpoint.readResourceSet ( @PathVariable("id") Long  id,
Model  m,
Authentication  auth 
)
inline
131  {
132  ensureOAuthScope(auth, SystemScopeService.UMA_PROTECTION_SCOPE);
133 
134  ResourceSet rs = resourceSetService.getById(id);
135 
136  if (rs == null) {
137  m.addAttribute("code", HttpStatus.NOT_FOUND);
138  m.addAttribute("error", "not_found");
139  return JsonErrorView.VIEWNAME;
140  } else {
141 
142  rs = validateScopes(rs);
143 
144  if (!auth.getName().equals(rs.getOwner())) {
145 
146  logger.warn("Unauthorized resource set request from wrong user; expected " + rs.getOwner() + " got " + auth.getName());
147 
148  // it wasn't issued to this user
149  m.addAttribute(HttpCodeView.CODE, HttpStatus.FORBIDDEN);
150  return JsonErrorView.VIEWNAME;
151  } else {
152  m.addAttribute(JsonEntityView.ENTITY, rs);
153  return ResourceSetEntityView.VIEWNAME;
154  }
155 
156  }
157 
158  }
ResourceSetService resourceSetService
Definition: ResourceSetRegistrationEndpoint.java:71
static final Logger logger
Definition: ResourceSetRegistrationEndpoint.java:65
ResourceSet validateScopes(ResourceSet rs)
Definition: ResourceSetRegistrationEndpoint.java:305

◆ updateResourceSet()

String org.mitre.uma.web.ResourceSetRegistrationEndpoint.updateResourceSet ( @PathVariable("id") Long  id,
@RequestBody String  jsonString,
Model  m,
Authentication  auth 
)
inline
161  {
162  ensureOAuthScope(auth, SystemScopeService.UMA_PROTECTION_SCOPE);
163 
164  ResourceSet newRs = parseResourceSet(jsonString);
165 
166  if (newRs == null // there was no resource set in the body
167  || Strings.isNullOrEmpty(newRs.getName()) // there was no name (required)
168  || newRs.getScopes() == null // there were no scopes (required)
169  || newRs.getId() == null || !newRs.getId().equals(id) // the IDs didn't match
170  ) {
171 
172  logger.warn("Resource set registration missing one or more required fields.");
173 
174  m.addAttribute(HttpCodeView.CODE, HttpStatus.BAD_REQUEST);
175  m.addAttribute(JsonErrorView.ERROR_MESSAGE, "Resource request was missing one or more required fields.");
176  return JsonErrorView.VIEWNAME;
177  }
178 
179  ResourceSet rs = resourceSetService.getById(id);
180 
181  if (rs == null) {
182  m.addAttribute(HttpCodeView.CODE, HttpStatus.NOT_FOUND);
183  m.addAttribute(JsonErrorView.ERROR, "not_found");
184  return JsonErrorView.VIEWNAME;
185  } else {
186  if (!auth.getName().equals(rs.getOwner())) {
187 
188  logger.warn("Unauthorized resource set request from bad user; expected " + rs.getOwner() + " got " + auth.getName());
189 
190  // it wasn't issued to this user
191  m.addAttribute(HttpCodeView.CODE, HttpStatus.FORBIDDEN);
192  return JsonErrorView.VIEWNAME;
193  } else {
194 
195  ResourceSet saved = resourceSetService.update(rs, newRs);
196 
197  m.addAttribute(JsonEntityView.ENTITY, saved);
198  m.addAttribute(ResourceSetEntityAbbreviatedView.LOCATION, config.getIssuer() + URL + "/" + rs.getId());
199  return ResourceSetEntityAbbreviatedView.VIEWNAME;
200  }
201 
202  }
203  }
ResourceSet update(ResourceSet oldRs, ResourceSet newRs)
ResourceSetService resourceSetService
Definition: ResourceSetRegistrationEndpoint.java:71
static final String URL
Definition: ResourceSetRegistrationEndpoint.java:68
static final Logger logger
Definition: ResourceSetRegistrationEndpoint.java:65
ResourceSet parseResourceSet(String jsonString)
Definition: ResourceSetRegistrationEndpoint.java:270
String getIssuer()
Definition: ConfigurationPropertiesBean.java:100
ConfigurationPropertiesBean config
Definition: ResourceSetRegistrationEndpoint.java:74

◆ validateScopes()

ResourceSet org.mitre.uma.web.ResourceSetRegistrationEndpoint.validateScopes ( ResourceSet  rs)
inlineprivate

Make sure the resource set doesn't have any restricted or reserved scopes.

引数
rs
305  {
306  // scopes that the client is asking for
307  Set<SystemScope> requestedScopes = scopeService.fromStrings(rs.getScopes());
308 
309  // the scopes that the resource set can have must be a subset of the dynamically allowed scopes
310  Set<SystemScope> allowedScopes = scopeService.removeRestrictedAndReservedScopes(requestedScopes);
311 
312  rs.setScopes(scopeService.toStrings(allowedScopes));
313 
314  return rs;
315  }
SystemScopeService scopeService
Definition: ResourceSetRegistrationEndpoint.java:77
Set< SystemScope > removeRestrictedAndReservedScopes(Set< SystemScope > scopes)
Set< SystemScope > fromStrings(Set< String > scope)
Set< String > toStrings(Set< SystemScope > scope)

メンバ詳解

◆ config

ConfigurationPropertiesBean org.mitre.uma.web.ResourceSetRegistrationEndpoint.config
private

◆ DISCOVERY_URL

final String org.mitre.uma.web.ResourceSetRegistrationEndpoint.DISCOVERY_URL = "resource_set"
static

◆ logger

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

◆ parser

JsonParser org.mitre.uma.web.ResourceSetRegistrationEndpoint.parser = new JsonParser()
private

◆ resourceSetService

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

◆ scopeService

SystemScopeService org.mitre.uma.web.ResourceSetRegistrationEndpoint.scopeService
private

◆ URL

final String org.mitre.uma.web.ResourceSetRegistrationEndpoint.URL = DISCOVERY_URL + "/resource_set"
static

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