cn.bestwu.api.sign.ApiSignEndpoint Maven / Gradle / Ivy
package cn.bestwu.api.sign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.common.exceptions.InvalidRequestException;
import org.springframework.security.oauth2.provider.endpoint.FrameworkEndpoint;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpServletRequest;
import static org.springframework.http.ResponseEntity.ok;
/**
* 签名计算接口
*
* @author Peter Wu
*/
@FrameworkEndpoint
public class ApiSignEndpoint {
@Autowired
private HttpServletRequest request;
@Autowired
private ApiSignAdpter apiSignAdpter;
private final ApiSignProperties properties;
public ApiSignEndpoint(ApiSignProperties properties) {
this.properties = properties;
}
/**
* 可计算传入参数的签名值
*
* @return 签名
*/
@RequestMapping(value = "/apiSign", method = RequestMethod.POST)
public Object apiSign() {
String client_id = request.getHeader(properties.getClient_idParameter());
if (!StringUtils.hasText(client_id)) {
throw new InvalidRequestException("invalid_request");
}
return ok(apiSignAdpter.sign(request.getParameterMap(), client_id, String.valueOf(System.currentTimeMillis())));
}
}