bug修复+代码调整+日志优化
This commit is contained in:
@@ -27,10 +27,10 @@ import org.dromara.maxkey.authz.cas.endpoint.ticket.CasConstants;
|
||||
import org.dromara.maxkey.authz.cas.endpoint.ticket.Ticket;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -42,7 +42,7 @@ import jakarta.servlet.http.HttpServletResponse;
|
||||
* https://apereo.github.io/cas/6.2.x/protocol/CAS-Protocol-Specification.html
|
||||
*/
|
||||
@Tag(name = "2-3-CAS API文档模块")
|
||||
@Controller
|
||||
@RestController
|
||||
public class Cas10AuthorizeEndpoint extends CasBaseAuthorizeEndpoint{
|
||||
|
||||
static final Logger _logger = LoggerFactory.getLogger(Cas10AuthorizeEndpoint.class);
|
||||
@@ -82,20 +82,14 @@ renew [OPTIONAL] - if this parameter is set, ticket validation will only succeed
|
||||
<LF>
|
||||
*/
|
||||
@Operation(summary = "CAS 1.0 ticket验证接口", description = "通过ticket获取当前登录用户信息",method="POST")
|
||||
@RequestMapping(CasConstants.ENDPOINT.ENDPOINT_VALIDATE)
|
||||
@ResponseBody
|
||||
@RequestMapping(value=CasConstants.ENDPOINT.ENDPOINT_VALIDATE,method={RequestMethod.GET,RequestMethod.POST})
|
||||
public String validate(
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
@RequestParam(value = CasConstants.PARAMETER.TICKET) String ticket,
|
||||
@RequestParam(value = CasConstants.PARAMETER.SERVICE) String service,
|
||||
@RequestParam(value = CasConstants.PARAMETER.RENEW,required=false) String renew
|
||||
){
|
||||
_logger.debug("serviceValidate "
|
||||
+ " ticket " + ticket
|
||||
+" , service " + service
|
||||
+" , renew " + renew
|
||||
);
|
||||
@RequestParam(value = CasConstants.PARAMETER.RENEW,required=false) String renew){
|
||||
_logger.debug("serviceValidate ticket {} , service {} , renew {}" , ticket,service,renew);
|
||||
|
||||
Ticket storedTicket = null;
|
||||
try {
|
||||
@@ -106,7 +100,7 @@ renew [OPTIONAL] - if this parameter is set, ticket validation will only succeed
|
||||
|
||||
if(storedTicket != null){
|
||||
String principal=((SignPrincipal)storedTicket.getAuthentication().getPrincipal()).getUsername();
|
||||
_logger.debug("principal "+principal);
|
||||
_logger.debug("principal {}",principal);
|
||||
return new Service10ResponseBuilder().success()
|
||||
.setUser(principal)
|
||||
.serviceResponseBuilder();
|
||||
|
||||
@@ -39,11 +39,11 @@ import org.dromara.maxkey.web.HttpResponseConstants;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
@@ -54,9 +54,8 @@ import jakarta.servlet.http.HttpServletResponse;
|
||||
* https://apereo.github.io/cas/6.2.x/protocol/CAS-Protocol-V2-Specification.html
|
||||
*/
|
||||
@Tag(name = "2-3-CAS API文档模块")
|
||||
@Controller
|
||||
@RestController
|
||||
public class Cas20AuthorizeEndpoint extends CasBaseAuthorizeEndpoint{
|
||||
|
||||
static final Logger _logger = LoggerFactory.getLogger(Cas20AuthorizeEndpoint.class);
|
||||
|
||||
/**
|
||||
@@ -176,7 +175,6 @@ For all error codes, it is RECOMMENDED that CAS provide a more detailed message
|
||||
*/
|
||||
@Operation(summary = "CAS 2.0 ticket验证接口", description = "通过ticket获取当前登录用户信息",method="POST")
|
||||
@RequestMapping(value=CasConstants.ENDPOINT.ENDPOINT_SERVICE_VALIDATE,produces =MediaType.APPLICATION_XML_VALUE,method={RequestMethod.GET,RequestMethod.POST})
|
||||
@ResponseBody
|
||||
public String serviceValidate(
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
@@ -185,13 +183,7 @@ For all error codes, it is RECOMMENDED that CAS provide a more detailed message
|
||||
@RequestParam(value = CasConstants.PARAMETER.PROXY_CALLBACK_URL,required=false) String pgtUrl,
|
||||
@RequestParam(value = CasConstants.PARAMETER.RENEW,required=false) String renew,
|
||||
@RequestParam(value = CasConstants.PARAMETER.FORMAT,required=false,defaultValue=HttpResponseConstants.FORMAT_TYPE.XML) String format){
|
||||
_logger.debug("serviceValidate "
|
||||
+ " ticket " + ticket
|
||||
+" , service " + service
|
||||
+" , pgtUrl " + pgtUrl
|
||||
+" , renew " + renew
|
||||
+" , format " + format
|
||||
);
|
||||
_logger.debug("serviceValidate ticket {} , service {} , pgtUrl {} , renew {} , format {}" , ticket,service,pgtUrl,renew,format);
|
||||
|
||||
Ticket storedTicket=null;
|
||||
if(ticket.startsWith(CasConstants.PREFIX.SERVICE_TICKET_PREFIX)) {
|
||||
@@ -303,8 +295,8 @@ Response on ticket validation failure:
|
||||
*/
|
||||
|
||||
@Operation(summary = "CAS 2.0 ticket代理验证接口", description = "通过ticket获取当前登录用户信息",method="POST")
|
||||
@RequestMapping(value=CasConstants.ENDPOINT.ENDPOINT_PROXY_VALIDATE,produces =MediaType.APPLICATION_XML_VALUE)
|
||||
@ResponseBody
|
||||
@RequestMapping(value=CasConstants.ENDPOINT.ENDPOINT_PROXY_VALIDATE,produces =MediaType.APPLICATION_XML_VALUE,method={RequestMethod.GET,RequestMethod.POST})
|
||||
|
||||
public String proxy(
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
@@ -313,13 +305,7 @@ Response on ticket validation failure:
|
||||
@RequestParam(value = CasConstants.PARAMETER.PROXY_CALLBACK_URL,required=false) String pgtUrl,
|
||||
@RequestParam(value = CasConstants.PARAMETER.RENEW,required=false) String renew,
|
||||
@RequestParam(value = CasConstants.PARAMETER.FORMAT,required=false,defaultValue=HttpResponseConstants.FORMAT_TYPE.XML) String format){
|
||||
_logger.debug("proxyValidate "
|
||||
+ " ticket " + ticket
|
||||
+" , service " + service
|
||||
+" , pgtUrl " + pgtUrl
|
||||
+" , renew " + renew
|
||||
+" , format " + format
|
||||
);
|
||||
_logger.debug("proxyValidate ticket {} , service {} , pgtUrl {} , renew {} , format {}" ,ticket,service, pgtUrl,renew,format);
|
||||
|
||||
Ticket storedTicket=null;
|
||||
if(ticket.startsWith(CasConstants.PREFIX.PROXY_TICKET_PREFIX)) {
|
||||
@@ -408,25 +394,21 @@ INTERNAL_ERROR - an internal error occurred during ticket validation
|
||||
|
||||
For all error codes, it is RECOMMENDED that CAS provide a more detailed message as the body of the <cas:authenticationFailure> block of the XML response.
|
||||
*/
|
||||
@RequestMapping(value=CasConstants.ENDPOINT.ENDPOINT_PROXY ,produces =MediaType.APPLICATION_XML_VALUE)
|
||||
@ResponseBody
|
||||
@RequestMapping(value=CasConstants.ENDPOINT.ENDPOINT_PROXY ,produces =MediaType.APPLICATION_XML_VALUE,method={RequestMethod.GET,RequestMethod.POST})
|
||||
|
||||
public String proxy(
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
@RequestParam(value = CasConstants.PARAMETER.PROXY_GRANTING_TICKET) String pgt,
|
||||
@RequestParam(value = CasConstants.PARAMETER.TARGET_SERVICE) String targetService,
|
||||
@RequestParam(value = CasConstants.PARAMETER.FORMAT,required=false,defaultValue=HttpResponseConstants.FORMAT_TYPE.XML) String format){
|
||||
_logger.debug("proxy "
|
||||
+ " pgt " + pgt
|
||||
+" , targetService " + targetService
|
||||
+" , format " + format
|
||||
);
|
||||
_logger.debug("proxy pgt {} , targetService {} , format {}" ,pgt,targetService, format);
|
||||
ProxyServiceResponseBuilder proxyServiceResponseBuilder=new ProxyServiceResponseBuilder(format);
|
||||
|
||||
ProxyGrantingTicketImpl proxyGrantingTicketImpl = (ProxyGrantingTicketImpl)casProxyGrantingTicketServices.get(pgt);
|
||||
if(proxyGrantingTicketImpl != null) {
|
||||
ProxyTicketImpl ProxyTicketImpl = new ProxyTicketImpl(proxyGrantingTicketImpl.getAuthentication(),proxyGrantingTicketImpl.getCasDetails());
|
||||
String proxyTicket =ticketServices.createTicket(ProxyTicketImpl);
|
||||
ProxyTicketImpl proxyTicketImpl = new ProxyTicketImpl(proxyGrantingTicketImpl.getAuthentication(),proxyGrantingTicketImpl.getCasDetails());
|
||||
String proxyTicket =ticketServices.createTicket(proxyTicketImpl);
|
||||
proxyServiceResponseBuilder.success().setTicket(proxyTicket).setFormat(format);
|
||||
}else {
|
||||
proxyServiceResponseBuilder.success().setTicket("").setFormat(format);
|
||||
|
||||
@@ -67,13 +67,7 @@ public class Cas30AuthorizeEndpoint extends CasBaseAuthorizeEndpoint{
|
||||
@RequestParam(value = CasConstants.PARAMETER.PROXY_CALLBACK_URL,required=false) String pgtUrl,
|
||||
@RequestParam(value = CasConstants.PARAMETER.RENEW,required=false) String renew,
|
||||
@RequestParam(value = CasConstants.PARAMETER.FORMAT,required=false,defaultValue=HttpResponseConstants.FORMAT_TYPE.XML) String format){
|
||||
_logger.debug("serviceValidate "
|
||||
+ " ticket " + ticket
|
||||
+" , service " + service
|
||||
+" , pgtUrl " + pgtUrl
|
||||
+" , renew " + renew
|
||||
+" , format " + format
|
||||
);
|
||||
_logger.debug("serviceValidate ticket {} , service {} , pgtUrl {} , renew {} , format {}", ticket,service,pgtUrl,renew,format);
|
||||
|
||||
Ticket storedTicket=null;
|
||||
if(ticket.startsWith(CasConstants.PREFIX.SERVICE_TICKET_PREFIX)) {
|
||||
@@ -123,23 +117,19 @@ public class Cas30AuthorizeEndpoint extends CasBaseAuthorizeEndpoint{
|
||||
}
|
||||
|
||||
@Operation(summary = "CAS 3.0 ProxyTicket代理验证接口", description = "通过ProxyGrantingTicket获取ProxyTicket",method="POST")
|
||||
@RequestMapping(CasConstants.ENDPOINT.ENDPOINT_PROXY_V3)
|
||||
@RequestMapping(value=CasConstants.ENDPOINT.ENDPOINT_PROXY_V3,method={RequestMethod.GET,RequestMethod.POST})
|
||||
public void proxy(
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
@RequestParam(value = CasConstants.PARAMETER.PROXY_GRANTING_TICKET) String pgt,
|
||||
@RequestParam(value = CasConstants.PARAMETER.TARGET_SERVICE) String targetService,
|
||||
@RequestParam(value = CasConstants.PARAMETER.FORMAT,required=false,defaultValue=HttpResponseConstants.FORMAT_TYPE.XML) String format){
|
||||
_logger.debug("proxy "
|
||||
+ " pgt " + pgt
|
||||
+" , targetService " + targetService
|
||||
+" , format " + format
|
||||
);
|
||||
_logger.debug("proxy pgt {} , targetService {} , format {}" , pgt,targetService,format);
|
||||
ProxyServiceResponseBuilder proxyServiceResponseBuilder=new ProxyServiceResponseBuilder(format);
|
||||
ProxyGrantingTicketImpl proxyGrantingTicketImpl = (ProxyGrantingTicketImpl)casProxyGrantingTicketServices.get(pgt);
|
||||
if(proxyGrantingTicketImpl != null) {
|
||||
ProxyTicketImpl ProxyTicketImpl = new ProxyTicketImpl(proxyGrantingTicketImpl.getAuthentication(),proxyGrantingTicketImpl.getCasDetails());
|
||||
String proxyTicket =ticketServices.createTicket(ProxyTicketImpl);
|
||||
ProxyTicketImpl proxyTicketImpl = new ProxyTicketImpl(proxyGrantingTicketImpl.getAuthentication(),proxyGrantingTicketImpl.getCasDetails());
|
||||
String proxyTicket =ticketServices.createTicket(proxyTicketImpl);
|
||||
proxyServiceResponseBuilder.success().setTicket(proxyTicket).setFormat(format);
|
||||
}else {
|
||||
proxyServiceResponseBuilder.success().setTicket("").setFormat(format);
|
||||
@@ -149,7 +139,7 @@ public class Cas30AuthorizeEndpoint extends CasBaseAuthorizeEndpoint{
|
||||
}
|
||||
|
||||
@Operation(summary = "CAS 3.0 ticket代理验证接口", description = "通过ProxyTicket获取当前登录用户信息",method="POST")
|
||||
@RequestMapping(CasConstants.ENDPOINT.ENDPOINT_PROXY_VALIDATE_V3)
|
||||
@RequestMapping(value=CasConstants.ENDPOINT.ENDPOINT_PROXY_VALIDATE_V3,method={RequestMethod.GET,RequestMethod.POST})
|
||||
public void proxy(
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
@@ -158,13 +148,7 @@ public class Cas30AuthorizeEndpoint extends CasBaseAuthorizeEndpoint{
|
||||
@RequestParam(value = CasConstants.PARAMETER.PROXY_CALLBACK_URL,required=false) String pgtUrl,
|
||||
@RequestParam(value = CasConstants.PARAMETER.RENEW,required=false) String renew,
|
||||
@RequestParam(value = CasConstants.PARAMETER.FORMAT,required=false,defaultValue=HttpResponseConstants.FORMAT_TYPE.XML) String format){
|
||||
_logger.debug("proxyValidate "
|
||||
+ " ticket " + ticket
|
||||
+" , service " + service
|
||||
+" , pgtUrl " + pgtUrl
|
||||
+" , renew " + renew
|
||||
+" , format " + format
|
||||
);
|
||||
_logger.debug("proxyValidate ticket {} , service {} , pgtUrl {} , renew {} , format {}" , ticket,service,pgtUrl,renew,format);
|
||||
|
||||
Ticket storedTicket=null;
|
||||
if(ticket.startsWith(CasConstants.PREFIX.PROXY_TICKET_PREFIX)) {
|
||||
|
||||
@@ -22,8 +22,8 @@ package org.dromara.maxkey.authz.cas.endpoint;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dromara.maxkey.authn.session.Session;
|
||||
import org.dromara.maxkey.authn.web.AuthorizationUtils;
|
||||
import org.dromara.maxkey.authz.cas.endpoint.ticket.CasConstants;
|
||||
@@ -37,7 +37,6 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
@@ -113,7 +112,7 @@ public class CasAuthorizeEndpoint extends CasBaseAuthorizeEndpoint{
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping(CasConstants.ENDPOINT.ENDPOINT_SERVICE_TICKET_GRANTING)
|
||||
@GetMapping(CasConstants.ENDPOINT.ENDPOINT_SERVICE_TICKET_GRANTING)
|
||||
public ModelAndView grantingTicket( Principal principal,
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response){
|
||||
@@ -148,8 +147,8 @@ public class CasAuthorizeEndpoint extends CasBaseAuthorizeEndpoint{
|
||||
Map <String, String> parameterMap = (Map <String, String>)WebContext.getAttribute(CasConstants.PARAMETER.PARAMETER_MAP);
|
||||
parameterMap.remove(CasConstants.PARAMETER.TICKET);
|
||||
parameterMap.remove(CasConstants.PARAMETER.SERVICE);
|
||||
for (String key : parameterMap.keySet()) {
|
||||
callbackUrl.append("&").append(key).append("=").append(parameterMap.get(key));
|
||||
for (Entry<String, String> entry : parameterMap.entrySet()) {
|
||||
callbackUrl.append("&").append(entry.getKey()).append("=").append(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.dromara.maxkey.web.WebContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
@@ -54,7 +54,7 @@ public class CasLogoutEndpoint extends CasBaseAuthorizeEndpoint{
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "CAS注销接口", description = "CAS注销接口",method="GET")
|
||||
@RequestMapping(CasConstants.ENDPOINT.ENDPOINT_LOGOUT)
|
||||
@GetMapping(CasConstants.ENDPOINT.ENDPOINT_LOGOUT)
|
||||
public ModelAndView logout(HttpServletRequest request , HttpServletResponse response,
|
||||
@RequestParam(value = CasConstants.PARAMETER.SERVICE , required = false) String casService){
|
||||
StringBuffer logoutUrl = new StringBuffer("/force/logout");
|
||||
|
||||
Reference in New Issue
Block a user