CAS优化
This commit is contained in:
@@ -41,18 +41,18 @@ import org.springframework.web.servlet.ModelAndView;
|
||||
public class AuthorizeBaseEndpoint {
|
||||
final static Logger _logger = LoggerFactory.getLogger(AuthorizeBaseEndpoint.class);
|
||||
|
||||
@Autowired
|
||||
@Qualifier("applicationConfig")
|
||||
protected ApplicationConfig applicationConfig;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("appsService")
|
||||
protected AppsService appsService;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("applicationConfig")
|
||||
protected ApplicationConfig applicationConfig;
|
||||
|
||||
|
||||
@Autowired
|
||||
AccountsService accountsService;
|
||||
|
||||
|
||||
@Qualifier("accountsService")
|
||||
protected AccountsService accountsService;
|
||||
|
||||
protected Apps getApp(String id){
|
||||
Apps app=(Apps)WebContext.getAttribute(AuthorizeBaseEndpoint.class.getName());
|
||||
//session中为空或者id不一致重新加载
|
||||
|
||||
@@ -27,13 +27,8 @@ import org.maxkey.authn.BasicAuthentication;
|
||||
import org.maxkey.authz.cas.endpoint.response.Service10ResponseBuilder;
|
||||
import org.maxkey.authz.cas.endpoint.ticket.CasConstants;
|
||||
import org.maxkey.authz.cas.endpoint.ticket.Ticket;
|
||||
import org.maxkey.authz.cas.endpoint.ticket.service.TicketServices;
|
||||
import org.maxkey.authz.endpoint.AuthorizeBaseEndpoint;
|
||||
import org.maxkey.configuration.ApplicationConfig;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
@@ -44,17 +39,10 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
||||
* https://apereo.github.io/cas/5.0.x/protocol/CAS-Protocol-V2-Specification.html
|
||||
*/
|
||||
@Controller
|
||||
public class Cas10AuthorizeEndpoint extends AuthorizeBaseEndpoint{
|
||||
public class Cas10AuthorizeEndpoint extends CasBaseAuthorizeEndpoint{
|
||||
|
||||
final static Logger _logger = LoggerFactory.getLogger(Cas10AuthorizeEndpoint.class);
|
||||
|
||||
@Autowired
|
||||
ApplicationConfig applicationConfig;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("casTicketServices")
|
||||
TicketServices ticketServices;
|
||||
|
||||
/**
|
||||
* @param request
|
||||
* @param response
|
||||
|
||||
@@ -28,19 +28,12 @@ import org.maxkey.authz.cas.endpoint.response.ProxyServiceResponseBuilder;
|
||||
import org.maxkey.authz.cas.endpoint.response.ServiceResponseBuilder;
|
||||
import org.maxkey.authz.cas.endpoint.ticket.CasConstants;
|
||||
import org.maxkey.authz.cas.endpoint.ticket.Ticket;
|
||||
import org.maxkey.authz.cas.endpoint.ticket.service.TicketServices;
|
||||
import org.maxkey.authz.endpoint.AuthorizeBaseEndpoint;
|
||||
import org.maxkey.authz.endpoint.adapter.AbstractAuthorizeAdapter;
|
||||
import org.maxkey.configuration.ApplicationConfig;
|
||||
import org.maxkey.constants.Boolean;
|
||||
import org.maxkey.domain.UserInfo;
|
||||
import org.maxkey.persistence.service.AppsCasDetailsService;
|
||||
import org.maxkey.persistence.service.UserInfoService;
|
||||
import org.maxkey.util.Instance;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
@@ -51,25 +44,10 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
||||
* https://apereo.github.io/cas/5.0.x/protocol/CAS-Protocol-V2-Specification.html
|
||||
*/
|
||||
@Controller
|
||||
public class Cas20AuthorizeEndpoint extends AuthorizeBaseEndpoint{
|
||||
public class Cas20AuthorizeEndpoint extends CasBaseAuthorizeEndpoint{
|
||||
|
||||
final static Logger _logger = LoggerFactory.getLogger(Cas20AuthorizeEndpoint.class);
|
||||
@Autowired
|
||||
AppsCasDetailsService casDetailsService;
|
||||
|
||||
@Autowired
|
||||
ApplicationConfig applicationConfig;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("userInfoService")
|
||||
private UserInfoService userInfoService;
|
||||
|
||||
|
||||
@Autowired
|
||||
@Qualifier("casTicketServices")
|
||||
TicketServices ticketServices;
|
||||
|
||||
|
||||
/**
|
||||
* @param request
|
||||
* @param response
|
||||
@@ -196,7 +174,8 @@ For all error codes, it is RECOMMENDED that CAS provide a more detailed message
|
||||
@RequestParam(value = CasConstants.PARAMETER.RENEW,required=false) String renew,
|
||||
@RequestParam(value = CasConstants.PARAMETER.FORMAT,required=false,defaultValue=CasConstants.FORMAT_TYPE.XML) String format){
|
||||
|
||||
|
||||
setContentType(request,response,format);
|
||||
|
||||
Ticket storedTicket=null;
|
||||
try {
|
||||
storedTicket = ticketServices.consumeTicket(ticket);
|
||||
@@ -222,8 +201,6 @@ For all error codes, it is RECOMMENDED that CAS provide a more detailed message
|
||||
.setDescription("Ticket "+ticket+" not recognized");
|
||||
}
|
||||
|
||||
|
||||
|
||||
return serviceResponseBuilder.serviceResponseBuilder();
|
||||
}
|
||||
|
||||
@@ -298,6 +275,7 @@ Response on ticket validation failure:
|
||||
@RequestParam(value = CasConstants.PARAMETER.RENEW,required=false) String renew,
|
||||
@RequestParam(value = CasConstants.PARAMETER.FORMAT,required=false,defaultValue=CasConstants.FORMAT_TYPE.XML) String format){
|
||||
|
||||
setContentType(request,response,format);
|
||||
|
||||
Ticket storedTicket=null;
|
||||
try {
|
||||
@@ -380,7 +358,10 @@ For all error codes, it is RECOMMENDED that CAS provide a more detailed message
|
||||
@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=CasConstants.FORMAT_TYPE.XML) String format){
|
||||
ProxyServiceResponseBuilder proxyServiceResponseBuilder=new ProxyServiceResponseBuilder();
|
||||
|
||||
setContentType(request,response,format);
|
||||
|
||||
ProxyServiceResponseBuilder proxyServiceResponseBuilder=new ProxyServiceResponseBuilder();
|
||||
return proxyServiceResponseBuilder.success().setTicket("").setFormat(format).serviceResponseBuilder();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,19 +27,12 @@ import org.maxkey.authn.BasicAuthentication;
|
||||
import org.maxkey.authz.cas.endpoint.response.ServiceResponseBuilder;
|
||||
import org.maxkey.authz.cas.endpoint.ticket.CasConstants;
|
||||
import org.maxkey.authz.cas.endpoint.ticket.Ticket;
|
||||
import org.maxkey.authz.cas.endpoint.ticket.service.TicketServices;
|
||||
import org.maxkey.authz.endpoint.AuthorizeBaseEndpoint;
|
||||
import org.maxkey.authz.endpoint.adapter.AbstractAuthorizeAdapter;
|
||||
import org.maxkey.configuration.ApplicationConfig;
|
||||
import org.maxkey.constants.Boolean;
|
||||
import org.maxkey.domain.UserInfo;
|
||||
import org.maxkey.persistence.service.AppsCasDetailsService;
|
||||
import org.maxkey.persistence.service.UserInfoService;
|
||||
import org.maxkey.util.Instance;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
@@ -50,22 +43,9 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
||||
* https://apereo.github.io/cas/5.0.x/protocol/CAS-Protocol.html
|
||||
*/
|
||||
@Controller
|
||||
public class Cas30AuthorizeEndpoint extends AuthorizeBaseEndpoint{
|
||||
public class Cas30AuthorizeEndpoint extends CasBaseAuthorizeEndpoint{
|
||||
|
||||
final static Logger _logger = LoggerFactory.getLogger(Cas30AuthorizeEndpoint.class);
|
||||
@Autowired
|
||||
AppsCasDetailsService casDetailsService;
|
||||
|
||||
@Autowired
|
||||
ApplicationConfig applicationConfig;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("userInfoService")
|
||||
private UserInfoService userInfoService;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("casTicketServices")
|
||||
TicketServices ticketServices;
|
||||
|
||||
@RequestMapping("/authz/cas/p3/serviceValidate")
|
||||
@ResponseBody
|
||||
@@ -78,7 +58,8 @@ public class Cas30AuthorizeEndpoint extends AuthorizeBaseEndpoint{
|
||||
@RequestParam(value = CasConstants.PARAMETER.RENEW,required=false) String renew,
|
||||
@RequestParam(value = CasConstants.PARAMETER.FORMAT,required=false,defaultValue=CasConstants.FORMAT_TYPE.XML) String format){
|
||||
|
||||
|
||||
setContentType(request,response,format);
|
||||
|
||||
Ticket storedTicket=null;
|
||||
try {
|
||||
storedTicket = ticketServices.consumeTicket(ticket);
|
||||
@@ -102,8 +83,6 @@ public class Cas30AuthorizeEndpoint extends AuthorizeBaseEndpoint{
|
||||
.setDescription("Ticket "+ticket+" not recognized");
|
||||
}
|
||||
|
||||
|
||||
|
||||
return serviceResponseBuilder.serviceResponseBuilder();
|
||||
}
|
||||
|
||||
@@ -118,7 +97,8 @@ public class Cas30AuthorizeEndpoint extends AuthorizeBaseEndpoint{
|
||||
@RequestParam(value = CasConstants.PARAMETER.RENEW,required=false) String renew,
|
||||
@RequestParam(value = CasConstants.PARAMETER.FORMAT,required=false,defaultValue=CasConstants.FORMAT_TYPE.XML) String format){
|
||||
|
||||
|
||||
setContentType(request,response,format);
|
||||
|
||||
Ticket storedTicket=null;
|
||||
try {
|
||||
storedTicket = ticketServices.consumeTicket(ticket);
|
||||
@@ -142,8 +122,6 @@ public class Cas30AuthorizeEndpoint extends AuthorizeBaseEndpoint{
|
||||
.setDescription("Ticket "+ticket+" not recognized");
|
||||
}
|
||||
|
||||
|
||||
|
||||
return serviceResponseBuilder.serviceResponseBuilder();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,17 +27,12 @@ import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.maxkey.authz.cas.endpoint.ticket.CasConstants;
|
||||
import org.maxkey.authz.cas.endpoint.ticket.ServiceTicketImpl;
|
||||
import org.maxkey.authz.cas.endpoint.ticket.service.TicketServices;
|
||||
import org.maxkey.authz.endpoint.AuthorizeBaseEndpoint;
|
||||
import org.maxkey.configuration.ApplicationConfig;
|
||||
import org.maxkey.domain.apps.AppsCasDetails;
|
||||
import org.maxkey.persistence.service.AppsCasDetailsService;
|
||||
import org.maxkey.web.WebConstants;
|
||||
import org.maxkey.web.WebContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -49,19 +44,9 @@ import org.springframework.web.servlet.ModelAndView;
|
||||
* https://apereo.github.io/cas/5.0.x/protocol/CAS-Protocol-V2-Specification.html
|
||||
*/
|
||||
@Controller
|
||||
public class CasAuthorizeEndpoint extends AuthorizeBaseEndpoint{
|
||||
public class CasAuthorizeEndpoint extends CasBaseAuthorizeEndpoint{
|
||||
|
||||
final static Logger _logger = LoggerFactory.getLogger(CasAuthorizeEndpoint.class);
|
||||
|
||||
@Autowired
|
||||
AppsCasDetailsService casDetailsService;
|
||||
|
||||
@Autowired
|
||||
ApplicationConfig applicationConfig;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("casTicketServices")
|
||||
TicketServices ticketServices;
|
||||
|
||||
@RequestMapping("/authz/cas/login")
|
||||
public ModelAndView casLogin(
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.maxkey.authz.cas.endpoint;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.maxkey.authz.cas.endpoint.ticket.CasConstants;
|
||||
import org.maxkey.authz.cas.endpoint.ticket.service.TicketServices;
|
||||
import org.maxkey.authz.endpoint.AuthorizeBaseEndpoint;
|
||||
import org.maxkey.constants.ContentType;
|
||||
import org.maxkey.persistence.service.AppsCasDetailsService;
|
||||
import org.maxkey.persistence.service.UserInfoService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
|
||||
public class CasBaseAuthorizeEndpoint extends AuthorizeBaseEndpoint{
|
||||
final static Logger _logger = LoggerFactory.getLogger(CasBaseAuthorizeEndpoint.class);
|
||||
|
||||
@Autowired
|
||||
@Qualifier("appsCasDetailsService")
|
||||
protected AppsCasDetailsService casDetailsService;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("userInfoService")
|
||||
protected UserInfoService userInfoService;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("casTicketServices")
|
||||
protected TicketServices ticketServices;
|
||||
|
||||
public void setContentType(
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
String format) {
|
||||
|
||||
if(format == null || format.equalsIgnoreCase("") || format.equalsIgnoreCase(CasConstants.FORMAT_TYPE.XML)) {
|
||||
//response.setContentType(ContentType.APPLICATION_XML_UTF8);
|
||||
}else {
|
||||
response.setContentType(ContentType.APPLICATION_JSON_UTF8);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user