@Override public String apply(SystemScope input) { if (input == null) { return null; } else { return input.getValue(); } } };
/** * @param writer */ private void writeSystemScopes(JsonWriter writer) { for (SystemScope sysScope : sysScopeRepository.getAll()) { try { writer.beginObject(); writer.name(ID).value(sysScope.getId()); writer.name(DESCRIPTION).value(sysScope.getDescription()); writer.name(ICON).value(sysScope.getIcon()); writer.name(VALUE).value(sysScope.getValue()); writer.name(RESTRICTED).value(sysScope.isRestricted()); writer.name(DEFAULT_SCOPE).value(sysScope.isDefaultScope()); writer.endObject(); logger.debug("Wrote system scope {}", sysScope.getId()); } catch (IOException ex) { logger.error("Unable to write system scope {}", sysScope.getId(), ex); } } logger.info("Done writing system scopes"); }
@PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public String createScope(@RequestBody String json, ModelMap m) { SystemScope scope = gson.fromJson(json, SystemScope.class); SystemScope alreadyExists = scopeService.getByValue(scope.getValue()); if (alreadyExists != null) { //Error, cannot save a scope with the same value as an existing one logger.error("Error: attempting to save a scope with a value that already exists: " + scope.getValue()); m.put(HttpCodeView.CODE, HttpStatus.CONFLICT); m.put(JsonErrorView.ERROR_MESSAGE, "A scope with value " + scope.getValue() + " already exists, please choose a different value."); return JsonErrorView.VIEWNAME; } scope = scopeService.save(scope); if (scope != null && scope.getId() != null) { m.put(JsonEntityView.ENTITY, scope); return JsonEntityView.VIEWNAME; } else { logger.error("createScope failed; JSON was invalid: " + json); m.put(HttpCodeView.CODE, HttpStatus.BAD_REQUEST); m.put(JsonErrorView.ERROR_MESSAGE, "Could not save new scope " + scope + ". The scope service failed to return a saved entity."); return JsonErrorView.VIEWNAME; } }
@Override public String apply(SystemScope input) { if (input == null) { return null; } else { return input.getValue(); } } };
@Override public SystemScope getByValue(final String s) { for (final SystemScope scope : scopes) { if (scope.getValue().equals(s)) { return scope; } } return null; }
final Map<String, String> claimValues = new HashMap<>(); final Set<String> claims = scopeClaimTranslationService.getClaimsForScope(systemScope.getValue()); log.debug("Processing system scope {} for the following claims: {}", systemScope.getValue(), claims); for (final String claim : claims) { final JsonElement element = userJson.get(claim); log.debug("Final claims for system scope {} are {}", systemScope.getValue(), claimValues); claimsForScopes.put(systemScope.getValue(), claimValues);
/** * @param writer */ private void writeSystemScopes(JsonWriter writer) { for (SystemScope sysScope : sysScopeRepository.getAll()) { try { writer.beginObject(); writer.name(ID).value(sysScope.getId()); writer.name(DESCRIPTION).value(sysScope.getDescription()); writer.name(ICON).value(sysScope.getIcon()); writer.name(VALUE).value(sysScope.getValue()); writer.name(RESTRICTED).value(sysScope.isRestricted()); writer.name(DEFAULT_SCOPE).value(sysScope.isDefaultScope()); writer.endObject(); logger.debug("Wrote system scope {}", sysScope.getId()); } catch (IOException ex) { logger.error("Unable to write system scope {}", sysScope.getId(), ex); } } logger.info("Done writing system scopes"); }
@PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public String createScope(@RequestBody String json, ModelMap m) { SystemScope scope = gson.fromJson(json, SystemScope.class); SystemScope alreadyExists = scopeService.getByValue(scope.getValue()); if (alreadyExists != null) { //Error, cannot save a scope with the same value as an existing one logger.error("Error: attempting to save a scope with a value that already exists: " + scope.getValue()); m.put(HttpCodeView.CODE, HttpStatus.CONFLICT); m.put(JsonErrorView.ERROR_MESSAGE, "A scope with value " + scope.getValue() + " already exists, please choose a different value."); return JsonErrorView.VIEWNAME; } scope = scopeService.save(scope); if (scope != null && scope.getId() != null) { m.put(JsonEntityView.ENTITY, scope); return JsonEntityView.VIEWNAME; } else { logger.error("createScope failed; JSON was invalid: " + json); m.put(HttpCodeView.CODE, HttpStatus.BAD_REQUEST); m.put(JsonErrorView.ERROR_MESSAGE, "Could not save new scope " + scope + ". The scope service failed to return a saved entity."); return JsonErrorView.VIEWNAME; } }