use of org.springframework.web.bind.annotation.RequestParam in project cas by apereo.
the class OidcLogoutEndpointController method handleRequestInternal.
/**
* Handle request.
*
* @param postLogoutRedirectUrl the post logout redirect url
* @param state the state
* @param idToken the id token
* @param request the request
* @param response the response
* @return the response entity
* @throws Exception the exception
*/
@GetMapping(value = { '/' + OidcConstants.BASE_OIDC_URL + '/' + OidcConstants.LOGOUT_URL, '/' + OidcConstants.BASE_OIDC_URL + "/logout", "/**/" + OidcConstants.LOGOUT_URL })
public ResponseEntity<HttpStatus> handleRequestInternal(@RequestParam(value = "post_logout_redirect_uri", required = false) final String postLogoutRedirectUrl, @RequestParam(value = "state", required = false) final String state, @RequestParam(value = "id_token_hint", required = false) final String idToken, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
val webContext = new JEEContext(request, response);
if (!getConfigurationContext().getOidcRequestSupport().isValidIssuerForEndpoint(webContext, OidcConstants.LOGOUT_URL)) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
String clientId = null;
if (StringUtils.isNotBlank(idToken)) {
LOGGER.trace("Decoding logout id token [{}]", idToken);
val configContext = getConfigurationContext();
val claims = configContext.getIdTokenSigningAndEncryptionService().decode(idToken, Optional.empty());
clientId = claims.getStringClaimValue(OAuth20Constants.CLIENT_ID);
LOGGER.debug("Client id retrieved from id token is [{}]", clientId);
val registeredService = OAuth20Utils.getRegisteredOAuthServiceByClientId(configContext.getServicesManager(), clientId);
LOGGER.debug("Located registered service [{}]", registeredService);
val service = configContext.getWebApplicationServiceServiceFactory().createService(clientId);
val audit = AuditableContext.builder().service(service).registeredService(registeredService).build();
val accessResult = configContext.getRegisteredServiceAccessStrategyEnforcer().execute(audit);
accessResult.throwExceptionIfNeeded();
WebUtils.putRegisteredService(request, Objects.requireNonNull(registeredService));
val urls = configContext.getSingleLogoutServiceLogoutUrlBuilder().determineLogoutUrl(registeredService, service, Optional.of(request)).stream().map(SingleLogoutUrl::getUrl).collect(Collectors.toList());
LOGGER.debug("Logout urls assigned to registered service are [{}]", urls);
if (StringUtils.isNotBlank(postLogoutRedirectUrl) && registeredService.getMatchingStrategy() != null) {
val matchResult = registeredService.matches(postLogoutRedirectUrl) || urls.stream().anyMatch(url -> postLogoutRedirectUrlMatcher.matches(postLogoutRedirectUrl, url));
if (matchResult) {
LOGGER.debug("Requested logout URL [{}] is authorized for redirects", postLogoutRedirectUrl);
return new ResponseEntity<>(executeLogoutRedirect(Optional.ofNullable(StringUtils.trimToNull(state)), Optional.of(postLogoutRedirectUrl), Optional.of(clientId), request, response));
}
}
val validURL = urls.stream().filter(urlValidator::isValid).findFirst();
if (validURL.isPresent()) {
return new ResponseEntity<>(executeLogoutRedirect(Optional.ofNullable(StringUtils.trimToNull(state)), validURL, Optional.of(clientId), request, response));
}
LOGGER.debug("No logout urls could be determined for registered service [{}]", registeredService.getName());
}
return new ResponseEntity<>(executeLogoutRedirect(Optional.ofNullable(StringUtils.trimToNull(state)), Optional.empty(), Optional.ofNullable(clientId), request, response));
}
use of org.springframework.web.bind.annotation.RequestParam in project disconf by knightliao.
the class MyExceptionHandler method getParamErrors.
/**
* TypeMismatchException中获取到参数错误类型
*
* @param e
*/
private ModelAndView getParamErrors(TypeMismatchException e) {
Throwable t = e.getCause();
if (t instanceof ConversionFailedException) {
ConversionFailedException x = (ConversionFailedException) t;
TypeDescriptor type = x.getTargetType();
Annotation[] annotations = type != null ? type.getAnnotations() : new Annotation[0];
Map<String, String> errors = new HashMap<String, String>();
for (Annotation a : annotations) {
if (a instanceof RequestParam) {
errors.put(((RequestParam) a).value(), "parameter type error!");
}
}
if (errors.size() > 0) {
return paramError(errors, ErrorCode.TYPE_MIS_MATCH);
}
}
JsonObjectBase jsonObject = JsonObjectUtils.buildGlobalError("parameter type error!", ErrorCode.TYPE_MIS_MATCH);
return JsonObjectUtils.JsonObjectError2ModelView((JsonObjectError) jsonObject);
}
use of org.springframework.web.bind.annotation.RequestParam in project scoold by Erudika.
the class AdminController method restore.
@PostMapping("/import")
public String restore(@RequestParam("file") MultipartFile file, @RequestParam(required = false, defaultValue = "false") Boolean isso, HttpServletRequest req, HttpServletResponse res) {
Profile authUser = utils.getAuthUser(req);
if (!utils.isAdmin(authUser)) {
res.setStatus(403);
return null;
}
ObjectReader reader = ParaObjectUtils.getJsonMapper().readerFor(new TypeReference<List<Map<String, Object>>>() {
});
Map<String, String> comments2authors = new LinkedHashMap<>();
int count = 0;
int importBatchSize = Config.getConfigInt("import_batch_size", 100);
String filename = file.getOriginalFilename();
Sysprop s = new Sysprop();
s.setType("scooldimport");
try (InputStream inputStream = file.getInputStream()) {
if (StringUtils.endsWithIgnoreCase(filename, ".zip")) {
try (ZipInputStream zipIn = new ZipInputStream(inputStream)) {
ZipEntry zipEntry;
List<ParaObject> toCreate = new LinkedList<ParaObject>();
while ((zipEntry = zipIn.getNextEntry()) != null) {
if (isso) {
count += importFromSOArchive(zipIn, zipEntry, reader, comments2authors).size();
} else if (zipEntry.getName().endsWith(".json")) {
List<Map<String, Object>> objects = reader.readValue(new FilterInputStream(zipIn) {
public void close() throws IOException {
zipIn.closeEntry();
}
});
objects.forEach(o -> toCreate.add(ParaObjectUtils.setAnnotatedFields(o)));
if (toCreate.size() >= importBatchSize) {
pc.createAll(toCreate);
toCreate.clear();
}
count += objects.size();
} else {
logger.error("Expected JSON but found unknown file type to import: {}", zipEntry.getName());
}
}
if (!toCreate.isEmpty()) {
pc.createAll(toCreate);
}
if (isso) {
updateSOCommentAuthors(comments2authors);
}
}
} else if (StringUtils.endsWithIgnoreCase(filename, ".json")) {
List<Map<String, Object>> objects = reader.readValue(inputStream);
List<ParaObject> toCreate = new LinkedList<ParaObject>();
objects.forEach(o -> toCreate.add(ParaObjectUtils.setAnnotatedFields(o)));
count = objects.size();
pc.createAll(toCreate);
}
s.setCreatorid(authUser.getCreatorid());
s.setName(authUser.getName());
s.addProperty("count", count);
s.addProperty("file", filename);
logger.info("Imported {} objects to {}. Executed by {}", count, Config.getConfigParam("access_key", "scoold"), authUser.getCreatorid() + " " + authUser.getName());
if (count > 0) {
pc.create(s);
}
} catch (Exception e) {
logger.error("Failed to import " + filename, e);
return "redirect:" + ADMINLINK + "?error=true&imported=" + count;
}
return "redirect:" + ADMINLINK + "?success=true&imported=" + count;
}
use of org.springframework.web.bind.annotation.RequestParam in project zhcet-web by zhcet-amu.
the class CoursesController method getCourses.
@GetMapping
public String getCourses(Model model, @PathVariable Department department, @RequestParam(value = "all", required = false) Boolean all) {
ErrorUtils.requireNonNullDepartment(department);
// Determine if only active courses have to be should
boolean active = !(all != null && all);
model.addAttribute("page_description", "View and manage courses for the Department");
model.addAttribute("department", department);
model.addAttribute("page_title", "Courses : " + department.getName() + " Department");
model.addAttribute("page_subtitle", "Course Management");
model.addAttribute("page_path", getPath(department));
model.addAttribute("all", !active);
List<FloatedCourse> floatedCourses = floatedCourseService.getCurrentFloatedCourses(department);
List<Course> courses = courseService.getAllActiveCourse(department, active);
// Add meta tag and no of registrations to each course
for (FloatedCourse floatedCourse : floatedCourses) {
Stream.of(floatedCourse).map(FloatedCourse::getCourse).map(courses::indexOf).filter(index -> index != -1).map(courses::get).findFirst().ifPresent(course -> {
course.setMeta("Floated");
course.setRegistrations(floatedCourse.getCourseRegistrations().size());
});
}
SortUtils.sortCourses(courses);
model.addAttribute("courses", courses);
return "department/courses";
}
use of org.springframework.web.bind.annotation.RequestParam in project mica2 by obiba.
the class SignController method signup.
@GetMapping("/signup")
public ModelAndView signup(HttpServletRequest request, @RequestParam(value = "redirect", required = false) String redirect, @CookieValue(value = "NG_TRANSLATE_LANG_KEY", required = false, defaultValue = "en") String locale, @RequestParam(value = "language", required = false) String language) {
if (!micaConfigService.getConfig().isSignupEnabled())
return new ModelAndView("redirect:" + micaConfigService.getContextPath() + "/");
ModelAndView mv = new ModelAndView("signup");
String lang = getLang(locale, language);
List<OidcProvider> providers = getOidcProviders(lang, true).stream().map(o -> new OidcProvider(o, getOidcSignupUrl(o.getName(), request, redirect))).collect(Collectors.toList());
mv.getModel().put("oidcProviders", providers);
mv.getModel().put("authConfig", getAuthConfiguration());
return mv;
}
Aggregations