Search in sources :

Example 41 with PostMapping

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);
    }
}
Also used : Credential(org.apereo.cas.authentication.Credential) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) Service(org.apereo.cas.authentication.principal.Service) BadRestRequestException(org.apereo.cas.rest.BadRestRequestException) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) BadRestRequestException(org.apereo.cas.rest.BadRestRequestException) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 42 with PostMapping

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);
}
Also used : User(com.mapia.domain.User) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 43 with PostMapping

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);
}
Also used : RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) RegisteredService(org.apereo.cas.services.RegisteredService) HashMap(java.util.HashMap) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 44 with PostMapping

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);
}
Also used : RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) RegisteredService(org.apereo.cas.services.RegisteredService) HashMap(java.util.HashMap) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 45 with PostMapping

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);
}
Also used : UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Credential(org.apereo.cas.authentication.Credential) MessageContext(org.opensaml.messaging.context.MessageContext) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

PostMapping (org.springframework.web.bind.annotation.PostMapping)83 ApiOperation (io.swagger.annotations.ApiOperation)21 Profile (com.erudika.scoold.core.Profile)20 Post (com.erudika.scoold.core.Post)9 Example (tk.mybatis.mapper.entity.Example)8 HashMap (java.util.HashMap)7 Service (org.apereo.cas.authentication.principal.Service)6 ResponseEntity (org.springframework.http.ResponseEntity)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 LoginAuthDto (com.paascloud.base.dto.LoginAuthDto)5 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)5 RegisteredService (org.apereo.cas.services.RegisteredService)5 User (amu.zhcet.data.user.User)4 Report (com.erudika.scoold.core.Report)4 IOException (java.io.IOException)4 Map (java.util.Map)4 Credential (org.apereo.cas.authentication.Credential)4 Reply (com.erudika.scoold.core.Reply)3 Log (io.github.tesla.ops.common.Log)3 LinkedHashMap (java.util.LinkedHashMap)3