use of org.springframework.web.bind.annotation.PostMapping in project cas by apereo.
the class UserAuthenticationResource method createTicketGrantingTicket.
/**
* Create new ticket granting ticket.
*
* @param requestBody username and password application/x-www-form-urlencoded values
* @param request raw HttpServletRequest used to call this method
* @return ResponseEntity representing RESTful response
*/
@PostMapping(value = "/v1/users", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public ResponseEntity<String> createTicketGrantingTicket(@RequestBody final MultiValueMap<String, String> requestBody, final HttpServletRequest request) {
try {
final Collection<Credential> credential = this.credentialFactory.fromRequestBody(requestBody);
if (credential == null || credential.isEmpty()) {
throw new BadRestRequestException("No credentials are provided or extracted to authenticate the REST request");
}
final Service service = this.serviceFactory.createService(request);
final AuthenticationResult authenticationResult = authenticationSystemSupport.handleAndFinalizeSingleAuthenticationTransaction(service, credential);
return this.userAuthenticationResourceEntityResponseFactory.build(authenticationResult, request);
} catch (final AuthenticationException e) {
return RestResourceUtils.createResponseEntityForAuthnFailure(e);
} catch (final BadRestRequestException e) {
LOGGER.error(e.getMessage(), e);
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
use of org.springframework.web.bind.annotation.PostMapping in project 2017-01-HUDI-MAC-CHAR by NHNNEXT.
the class ApiUserController method login.
@PostMapping("/login")
public LoginResult login(@RequestBody User loginUser, HttpSession session) {
logger.debug("loginUser email : {}", loginUser.getEmail());
User user = userRepository.findUserByEmail(loginUser.getEmail());
if (user == null) {
return LoginResult.emailNotFound("가입되지 않은 이메일입니다.");
}
if (!user.matchPassword(loginUser)) {
return LoginResult.invalidPassword("잘못된 비밀번호입니다.");
}
user.setStatus(Status.LOBBY);
session.setAttribute(HttpSessionUtils.USER_SESSION_KEY, user);
return LoginResult.ok(user);
}
use of org.springframework.web.bind.annotation.PostMapping in project cas by apereo.
the class ManageRegisteredServicesMultiActionController method updateRegisteredServiceEvaluationOrder.
/**
* Updates the {@link RegisteredService#getEvaluationOrder()}.
*
* @param response the response
* @param id the service ids, whose order also determines the service evaluation order
*/
@PostMapping(value = "/updateRegisteredServiceEvaluationOrder")
public void updateRegisteredServiceEvaluationOrder(final HttpServletResponse response, @RequestParam("id") final long... id) {
if (id == null || id.length == 0) {
throw new IllegalArgumentException("No service id was received. Re-examine the request");
}
for (int i = 0; i < id.length; i++) {
final long svcId = id[i];
final RegisteredService svc = this.servicesManager.findServiceBy(svcId);
if (svc == null) {
throw new IllegalArgumentException("Service id " + svcId + " cannot be found.");
}
svc.setEvaluationOrder(i);
this.servicesManager.save(svc);
}
final Map<String, Object> model = new HashMap<>();
model.put(STATUS, HttpServletResponse.SC_OK);
JsonUtils.render(model, response);
}
use of org.springframework.web.bind.annotation.PostMapping in project cas by apereo.
the class ManageRegisteredServicesMultiActionController method deleteRegisteredService.
/**
* Method to delete the RegisteredService by its ID. Will make sure
* the default service that is the management app itself cannot be deleted
* or the user will be locked out.
*
* @param idAsLong the id
* @param response the response
*/
@PostMapping(value = "/deleteRegisteredService")
public void deleteRegisteredService(@RequestParam("id") final long idAsLong, final HttpServletResponse response) {
final RegisteredService svc = this.servicesManager.findServiceBy(this.defaultService);
if (svc == null || svc.getId() == idAsLong) {
throw new IllegalArgumentException("The default service " + this.defaultService.getId() + " cannot be deleted. " + "The definition is required for accessing the application.");
}
final RegisteredService r = this.servicesManager.delete(idAsLong);
if (r == null) {
throw new IllegalArgumentException("Service id " + idAsLong + " cannot be found.");
}
final Map<String, Object> model = new HashMap<>();
model.put("serviceName", r.getName());
model.put(STATUS, HttpServletResponse.SC_OK);
JsonUtils.render(model, response);
}
use of org.springframework.web.bind.annotation.PostMapping in project cas by apereo.
the class ECPProfileHandlerController method handleEcpRequest.
/**
* Handle ecp request.
*
* @param response the response
* @param request the request
* @throws Exception the exception
*/
@PostMapping(path = SamlIdPConstants.ENDPOINT_SAML2_IDP_ECP_PROFILE_SSO, consumes = { MediaType.TEXT_XML_VALUE, "application/vnd.paos.xml" })
public void handleEcpRequest(final HttpServletResponse response, final HttpServletRequest request) throws Exception {
final MessageContext soapContext = decodeSoapRequest(request);
final Credential credential = extractBasicAuthenticationCredential(request, response);
if (credential == null) {
LOGGER.error("Credentials could not be extracted from the SAML ECP request");
return;
}
if (soapContext == null) {
LOGGER.error("SAML ECP request could not be determined from the authentication request");
return;
}
handleEcpRequest(response, request, soapContext, credential);
}
Aggregations