Search in sources :

Example 86 with ResponseBody

use of org.springframework.web.bind.annotation.ResponseBody in project leopard by tanhaichao.

the class JsonViewTrynbResolver method resolveView.

@Override
public ModelAndView resolveView(HttpServletRequest request, HttpServletResponse response, HandlerMethod handler, Exception exception, TrynbInfo trynbInfo) {
    // Class<?> returnType = handler.getMethod().getReturnType();
    // if (!JsonView.class.isAssignableFrom(returnType)) {
    ResponseBody body = handler.getMethodAnnotation(ResponseBody.class);
    if (body == null) {
        return null;
    }
    if (corsConfig.isEnable()) {
        // response.addHeader("Access-Control-Allow-Headers", "X-Requested-With,X_Requested_With,Content-Type");
        // response.addHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
        String allowOrigin = corsConfig.getAccessControlAllowOrigin(request);
        if (StringUtils.isNotEmpty(allowOrigin)) {
            response.addHeader("Access-Control-Allow-Origin", allowOrigin);
            response.addHeader("Access-Control-Allow-Credentials", "true");
        // response.addHeader("Access-Control-Allow-Methods", "POST");
        // response.addHeader("Access-Control-Allow-Headers", "x_requested_with,content-type");
        }
    }
    ErrorJsonView jsonView = new ErrorJsonView();
    jsonView.setException(exception);
    jsonView.setHandler(handler);
    if (exception instanceof StatusCodeException) {
        StatusCodeException e = (StatusCodeException) exception;
        jsonView.setStatus(e.getStatus());
    } else {
        jsonView.setStatus(trynbInfo.getStatusCode());
    }
    jsonView.setMessage(trynbInfo.getMessage());
    if (trynbInfo.isTrynbMessage() || trynbInfo.isApiMessage() || trynbInfo.isTranslate()) {
        jsonView.setOriginalMessage(ErrorUtil.parseMessage(exception));
    }
    if (SystemUtils.IS_OS_WINDOWS) {
        // TODO 测试代码
        jsonView.setDetailMessage(exception.getMessage());
    }
    jsonView.setException(exception.getClass().getName());
    return jsonView;
}
Also used : StatusCodeException(io.leopard.web.view.StatusCodeException) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 87 with ResponseBody

use of org.springframework.web.bind.annotation.ResponseBody in project weixin-java-pay-demo by binarywang.

the class WxErrorController method error.

/**
 * Supports other formats like JSON, XML
 *
 * @param request
 */
@RequestMapping(value = ERROR_PATH)
@ResponseBody
public ResponseEntity<Map<String, Object>> error(HttpServletRequest request) {
    Map<String, Object> body = this.getErrorAttributes(request, this.getTraceParameter(request));
    HttpStatus status = this.getStatus(request);
    return new ResponseEntity<>(body, status);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) HttpStatus(org.springframework.http.HttpStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 88 with ResponseBody

use of org.springframework.web.bind.annotation.ResponseBody in project weixin-java-mp-demo-springboot by binarywang.

the class WxErrorController method error.

/**
 * Supports other formats like JSON, XML
 *
 * @param request
 */
@RequestMapping(value = ERROR_PATH)
@ResponseBody
public ResponseEntity<Map<String, Object>> error(HttpServletRequest request) {
    Map<String, Object> body = this.getErrorAttributes(request, this.getTraceParameter(request));
    HttpStatus status = this.getStatus(request);
    return new ResponseEntity<>(body, status);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) HttpStatus(org.springframework.http.HttpStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 89 with ResponseBody

use of org.springframework.web.bind.annotation.ResponseBody in project powerauth-restful-integration by lime-company.

the class TokenController method removeToken.

@RequestMapping(value = "remove", method = RequestMethod.POST)
@PowerAuth(resourceId = "/pa/token/remove", signatureType = { PowerAuthSignatureTypes.POSSESSION, PowerAuthSignatureTypes.POSSESSION_KNOWLEDGE, PowerAuthSignatureTypes.POSSESSION_BIOMETRY, PowerAuthSignatureTypes.POSSESSION_KNOWLEDGE_BIOMETRY })
@ResponseBody
public ObjectResponse<TokenRemoveResponse> removeToken(@RequestBody ObjectRequest<TokenRemoveRequest> request, PowerAuthApiAuthentication authentication) throws PowerAuthAuthenticationException {
    try {
        if (authentication != null && authentication.getActivationId() != null) {
            // Fetch activation ID
            final String activationId = authentication.getActivationId();
            // Fetch token ID from the request
            final TokenRemoveRequest requestObject = request.getRequestObject();
            final String tokenId = requestObject.getTokenId();
            // Remove a token, ignore response, since the endpoint should quietly return
            powerAuthClient.removeToken(tokenId, activationId);
            // Prepare a response
            final TokenRemoveResponse responseObject = new TokenRemoveResponse();
            responseObject.setTokenId(requestObject.getTokenId());
            return new ObjectResponse<>(responseObject);
        } else {
            throw new PowerAuthAuthenticationException();
        }
    } catch (PowerAuthAuthenticationException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new PowerAuthAuthenticationException(ex.getMessage());
    }
}
Also used : TokenRemoveRequest(io.getlime.security.powerauth.rest.api.model.request.TokenRemoveRequest) PowerAuthAuthenticationException(io.getlime.security.powerauth.rest.api.base.exception.PowerAuthAuthenticationException) ObjectResponse(io.getlime.core.rest.model.base.response.ObjectResponse) PowerAuthAuthenticationException(io.getlime.security.powerauth.rest.api.base.exception.PowerAuthAuthenticationException) TokenRemoveResponse(io.getlime.security.powerauth.rest.api.model.response.TokenRemoveResponse) PowerAuth(io.getlime.security.powerauth.rest.api.spring.annotation.PowerAuth) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 90 with ResponseBody

use of org.springframework.web.bind.annotation.ResponseBody in project powerauth-restful-integration by lime-company.

the class CustomActivationController method createNewActivation.

@RequestMapping(value = "create", method = RequestMethod.POST)
@ResponseBody
public ObjectResponse<NonPersonalizedEncryptedPayloadModel> createNewActivation(@RequestBody ObjectRequest<NonPersonalizedEncryptedPayloadModel> object) throws PowerAuthAuthenticationException, PowerAuthActivationException {
    try {
        // Check if there is any user provider to be autowired
        if (userProvider == null) {
            throw new PowerAuthActivationException();
        }
        // Prepare an encryptor
        final PowerAuthNonPersonalizedEncryptor encryptor = encryptorFactory.buildNonPersonalizedEncryptor(object);
        if (encryptor == null) {
            throw new PowerAuthActivationException();
        }
        // Decrypt the request object
        ActivationCreateCustomRequest request = encryptor.decrypt(object, ActivationCreateCustomRequest.class);
        if (request == null) {
            throw new PowerAuthActivationException();
        }
        // Lookup user ID using a provided identity
        final Map<String, String> identity = request.getIdentity();
        String userId = userProvider.lookupUserIdForAttributes(identity);
        // If no user was found, return error
        if (userId == null) {
            throw new PowerAuthActivationException();
        }
        // Create activation for a looked up user and application related to the given application key
        ActivationCreateRequest acr = request.getPowerauth();
        CreateActivationResponse response = powerAuthClient.createActivation(acr.getApplicationKey(), userId, acr.getActivationIdShort(), acr.getActivationName(), acr.getActivationNonce(), acr.getEphemeralPublicKey(), acr.getEncryptedDevicePublicKey(), acr.getExtras(), acr.getApplicationSignature());
        // Process custom attributes using a custom logic
        final Map<String, Object> customAttributes = request.getCustomAttributes();
        userProvider.processCustomActivationAttributes(customAttributes);
        // Prepare the created activation response data
        ActivationCreateResponse createResponse = new ActivationCreateResponse();
        createResponse.setActivationId(response.getActivationId());
        createResponse.setEphemeralPublicKey(response.getEphemeralPublicKey());
        createResponse.setActivationNonce(response.getActivationNonce());
        createResponse.setEncryptedServerPublicKey(response.getEncryptedServerPublicKey());
        createResponse.setEncryptedServerPublicKeySignature(response.getEncryptedServerPublicKeySignature());
        // Encrypt response object
        final ObjectResponse<NonPersonalizedEncryptedPayloadModel> powerAuthApiResponse = encryptor.encrypt(createResponse);
        // Check if activation should be committed instantly and if yes, perform commit
        if (userProvider.shouldAutoCommitActivation(identity, customAttributes)) {
            powerAuthClient.commitActivation(response.getActivationId());
        }
        // Return response
        return powerAuthApiResponse;
    } catch (IOException e) {
        throw new PowerAuthActivationException();
    }
}
Also used : CreateActivationResponse(io.getlime.powerauth.soap.CreateActivationResponse) ActivationCreateResponse(io.getlime.security.powerauth.rest.api.model.response.ActivationCreateResponse) PowerAuthNonPersonalizedEncryptor(io.getlime.security.powerauth.rest.api.base.encryption.PowerAuthNonPersonalizedEncryptor) IOException(java.io.IOException) PowerAuthActivationException(io.getlime.security.powerauth.rest.api.base.exception.PowerAuthActivationException) ActivationCreateCustomRequest(io.getlime.security.powerauth.rest.api.model.request.ActivationCreateCustomRequest) NonPersonalizedEncryptedPayloadModel(io.getlime.security.powerauth.rest.api.model.entity.NonPersonalizedEncryptedPayloadModel) ActivationCreateRequest(io.getlime.security.powerauth.rest.api.model.request.ActivationCreateRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1991 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1700 HashMap (java.util.HashMap)458 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)212 IOException (java.io.IOException)207 JSONObject (com.alibaba.fastjson.JSONObject)200 Map (java.util.Map)172 ApiOperation (io.swagger.annotations.ApiOperation)170 ArrayList (java.util.ArrayList)169 GetMapping (org.springframework.web.bind.annotation.GetMapping)112 ResponseEntity (org.springframework.http.ResponseEntity)102 ApiRest (build.dream.common.api.ApiRest)101 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)101 AuthPassport (com.ngtesting.platform.util.AuthPassport)99 PostMapping (org.springframework.web.bind.annotation.PostMapping)94 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)87 Date (java.util.Date)81 UserVo (com.ngtesting.platform.vo.UserVo)78 LogDetail (com.bc.pmpheep.annotation.LogDetail)71 ResponseBean (com.bc.pmpheep.controller.bean.ResponseBean)65