use of org.springframework.web.servlet.view.json.MappingJackson2JsonView in project cas by apereo.
the class OAuth20Utils method writeError.
/**
* Write to the output this error.
*
* @param response the response
* @param error error message
* @return json -backed view.
*/
public static ModelAndView writeError(final HttpServletResponse response, final String error) {
val model = CollectionUtils.wrap(OAuth20Constants.ERROR, error);
val mv = new ModelAndView(new MappingJackson2JsonView(MAPPER), (Map) model);
mv.setStatus(HttpStatus.BAD_REQUEST);
response.setStatus(HttpStatus.BAD_REQUEST.value());
return mv;
}
use of org.springframework.web.servlet.view.json.MappingJackson2JsonView in project cas by apereo.
the class Cas30JsonResponseView method createDelegatedView.
private static MappingJackson2JsonView createDelegatedView() {
val view = new MappingJackson2JsonView();
view.setPrettyPrint(true);
view.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL).findAndRegisterModules();
return view;
}
use of org.springframework.web.servlet.view.json.MappingJackson2JsonView in project cas by apereo.
the class OidcCallbackAuthorizeViewResolver method resolve.
@Override
@SneakyThrows
public ModelAndView resolve(final WebContext context, final ProfileManager manager, final String url) {
val prompt = OidcRequestSupport.getOidcPromptFromAuthorizationRequest(url);
if (prompt.contains(OidcConstants.PROMPT_NONE)) {
val result = manager.getProfile();
if (result.isPresent()) {
LOGGER.trace("Redirecting to URL [{}] without prompting for login", url);
return new ModelAndView(new RedirectView(url));
}
val originalRedirectUrl = OAuth20Utils.getRequestParameter(context, OAuth20Constants.REDIRECT_URI);
if (originalRedirectUrl.isEmpty()) {
val model = new HashMap<String, String>();
model.put(OAuth20Constants.ERROR, OidcConstants.LOGIN_REQUIRED);
return new ModelAndView(new MappingJackson2JsonView(), model);
}
val parameters = new LinkedHashMap<String, String>();
parameters.put(OAuth20Constants.ERROR, OidcConstants.LOGIN_REQUIRED);
OAuth20Utils.getRequestParameter(context, OAuth20Constants.STATE).ifPresent(state -> parameters.put(OAuth20Constants.STATE, state));
val clientId = OAuth20Utils.getRequestParameter(context, OAuth20Constants.CLIENT_ID).orElse(StringUtils.EMPTY);
val registeredService = OAuth20Utils.getRegisteredOAuthServiceByClientId(servicesManager, clientId);
val responseType = OAuth20Utils.getResponseModeType(context);
val redirect = FunctionUtils.doIf(OAuth20Utils.isResponseModeTypeFormPost(registeredService, responseType), originalRedirectUrl::get, () -> OidcRequestSupport.getRedirectUrlWithError(originalRedirectUrl.get(), OidcConstants.LOGIN_REQUIRED, context)).get();
LOGGER.warn("Unable to detect authenticated user profile for prompt-less login attempts. Redirecting to URL [{}]", redirect);
return authorizationModelAndViewBuilder.build(registeredService, responseType, redirect, parameters);
}
if (prompt.contains(OidcConstants.PROMPT_LOGIN)) {
LOGGER.trace("Removing login prompt from URL [{}]", url);
val newUrl = OidcRequestSupport.removeOidcPromptFromAuthorizationRequest(url, OidcConstants.PROMPT_LOGIN);
LOGGER.trace("Redirecting to URL [{}]", newUrl);
return new ModelAndView(new RedirectView(newUrl));
}
LOGGER.trace("Redirecting to URL [{}]", url);
return new ModelAndView(new RedirectView(url));
}
use of org.springframework.web.servlet.view.json.MappingJackson2JsonView in project cas by apereo.
the class OidcPushedAuthorizationModelAndViewBuilder method build.
@Override
public ModelAndView build(final OAuthRegisteredService registeredService, final OAuth20ResponseModeTypes responseMode, final String redirectUrl, final Map<String, String> parameters) {
val model = new LinkedHashMap<String, Object>();
model.put(OidcConstants.EXPIRES_IN, Long.valueOf(parameters.get(OidcConstants.EXPIRES_IN)));
model.put(OidcConstants.REQUEST_URI, parameters.get(OidcConstants.REQUEST_URI));
val mv = new ModelAndView(new MappingJackson2JsonView(), model);
mv.setStatus(HttpStatus.CREATED);
return mv;
}
use of org.springframework.web.servlet.view.json.MappingJackson2JsonView in project proxyee-down by monkeyWie.
the class RestExceptionHandler method resolveException.
@Override
public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
LOGGER.error("rest error:", e);
ModelAndView modelAndView = new ModelAndView();
try {
ResultInfo resultInfo = new ResultInfo().setStatus(ResultStatus.ERROR.getCode()).setMsg(ResultInfo.MSG_ERROR);
Map<String, Object> attr = JSON.parseObject(JSON.toJSONString(resultInfo), Map.class);
MappingJackson2JsonView view = new MappingJackson2JsonView();
view.setAttributesMap(attr);
modelAndView.setView(view);
} catch (Exception e1) {
e1.printStackTrace();
}
return modelAndView;
}
Aggregations