use of org.springframework.web.bind.annotation.GetMapping in project cas by apereo.
the class RegisteredServiceSimpleFormController method getServiceById.
/**
* Gets service by id.
*
* @param id the id
* @param request the request
* @param response the response
*/
@GetMapping(value = "getService")
public void getServiceById(@RequestParam(value = "id", required = false) final Long id, final HttpServletRequest request, final HttpServletResponse response) {
try {
final RegisteredServiceEditBean bean = new RegisteredServiceEditBean();
if (id == -1) {
bean.setServiceData(null);
} else {
final RegisteredService service = this.servicesManager.findServiceBy(id);
if (service == null) {
LOGGER.warn("Invalid service id specified [{}]. Cannot find service in the registry", id);
throw new IllegalArgumentException("Service id " + id + " cannot be found");
}
bean.setServiceData(this.registeredServiceFactory.createServiceData(service));
}
bean.setFormData(this.registeredServiceFactory.createFormData());
bean.setStatus(HttpServletResponse.SC_OK);
JsonUtils.render(bean, response);
} catch (final Exception e) {
throw Throwables.propagate(e);
}
}
use of org.springframework.web.bind.annotation.GetMapping in project cas by apereo.
the class OAuth20AuthorizeEndpointController method handleRequestInternal.
/**
* Handle request internal model and view.
*
* @param request the request
* @param response the response
* @return the model and view
* @throws Exception the exception
*/
@GetMapping(path = OAuthConstants.BASE_OAUTH20_URL + '/' + OAuthConstants.AUTHORIZE_URL)
public ModelAndView handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final J2EContext context = WebUtils.getPac4jJ2EContext(request, response);
final ProfileManager manager = WebUtils.getPac4jProfileManager(request, response);
if (!verifyAuthorizeRequest(request) || !isRequestAuthenticated(manager, context)) {
LOGGER.error("Authorize request verification failed");
return OAuthUtils.produceUnauthorizedErrorView();
}
final String clientId = context.getRequestParameter(OAuthConstants.CLIENT_ID);
final OAuthRegisteredService registeredService = getRegisteredServiceByClientId(clientId);
try {
RegisteredServiceAccessStrategyUtils.ensureServiceAccessIsAllowed(clientId, registeredService);
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
return OAuthUtils.produceUnauthorizedErrorView();
}
final ModelAndView mv = this.consentApprovalViewResolver.resolve(context, registeredService);
if (!mv.isEmpty() && mv.hasView()) {
return mv;
}
return redirectToCallbackRedirectUrl(manager, registeredService, context, clientId);
}
use of org.springframework.web.bind.annotation.GetMapping in project cas by apereo.
the class OAuth20UserProfileControllerController method handleRequestInternal.
/**
* Handle request internal response entity.
*
* @param request the request
* @param response the response
* @return the response entity
* @throws Exception the exception
*/
@GetMapping(path = OAuthConstants.BASE_OAUTH20_URL + '/' + OAuthConstants.PROFILE_URL, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
String accessToken = request.getParameter(OAuthConstants.ACCESS_TOKEN);
if (StringUtils.isBlank(accessToken)) {
final String authHeader = request.getHeader(HttpConstants.AUTHORIZATION_HEADER);
if (StringUtils.isNotBlank(authHeader) && authHeader.toLowerCase().startsWith(OAuthConstants.BEARER_TOKEN.toLowerCase() + ' ')) {
accessToken = authHeader.substring(OAuthConstants.BEARER_TOKEN.length() + 1);
}
}
LOGGER.debug("[{}]: [{}]", OAuthConstants.ACCESS_TOKEN, accessToken);
if (StringUtils.isBlank(accessToken)) {
LOGGER.error("Missing [{}]", OAuthConstants.ACCESS_TOKEN);
final LinkedMultiValueMap<String, String> map = new LinkedMultiValueMap<>(1);
map.add(OAuthConstants.ERROR, OAuthConstants.MISSING_ACCESS_TOKEN);
final String value = OAuthUtils.jsonify(map);
return new ResponseEntity<>(value, HttpStatus.UNAUTHORIZED);
}
final AccessToken accessTokenTicket = getTicketRegistry().getTicket(accessToken, AccessToken.class);
if (accessTokenTicket == null || accessTokenTicket.isExpired()) {
LOGGER.error("Expired access token: [{}]", OAuthConstants.ACCESS_TOKEN);
final LinkedMultiValueMap<String, String> map = new LinkedMultiValueMap<>(1);
map.add(OAuthConstants.ERROR, OAuthConstants.EXPIRED_ACCESS_TOKEN);
final String value = OAuthUtils.jsonify(map);
return new ResponseEntity<>(value, HttpStatus.UNAUTHORIZED);
}
final Map<String, Object> map = writeOutProfileResponse(accessTokenTicket.getAuthentication(), accessTokenTicket.getAuthentication().getPrincipal());
final String value = OAuthUtils.jsonify(map);
LOGGER.debug("Final user profile is [{}]", value);
return new ResponseEntity<>(value, HttpStatus.OK);
}
use of org.springframework.web.bind.annotation.GetMapping in project spring-boot by spring-projects.
the class WelcomeController method welcome.
@GetMapping("/")
public String welcome(Map<String, Object> model) {
model.put("time", new Date());
model.put("message", this.message);
return "welcome";
}
use of org.springframework.web.bind.annotation.GetMapping in project spring-boot by spring-projects.
the class SampleWebSecureCustomApplication method home.
@GetMapping("/")
public String home(Map<String, Object> model) {
model.put("message", "Hello World");
model.put("title", "Hello Home");
model.put("date", new Date());
return "home";
}
Aggregations