mirror of
https://gitee.com/dromara/MaxKey.git
synced 2025-12-07 01:18:27 +08:00
CAS service ${errorMessage!} not registered .
This commit is contained in:
parent
c2d7230e2a
commit
0636df5d3c
@ -54,8 +54,10 @@ public class AppsCasDetailsService extends JpaBaseService<AppsCasDetails>{
|
|||||||
details = detailsCache.getIfPresent(id);
|
details = detailsCache.getIfPresent(id);
|
||||||
if(details == null) {
|
if(details == null) {
|
||||||
details = getMapper().getAppDetails(id);
|
details = getMapper().getAppDetails(id);
|
||||||
|
if(details != null) {
|
||||||
detailsCache.put(id, details);
|
detailsCache.put(id, details);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}else {
|
}else {
|
||||||
details = getMapper().getAppDetails(id);
|
details = getMapper().getAppDetails(id);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,8 +37,8 @@ import org.maxkey.web.WebConstants;
|
|||||||
import org.maxkey.web.WebContext;
|
import org.maxkey.web.WebContext;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
|
||||||
import org.springframework.stereotype.Controller;
|
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.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
@ -58,36 +58,41 @@ public class CasAuthorizeEndpoint extends CasBaseAuthorizeEndpoint{
|
|||||||
final static Logger _logger = LoggerFactory.getLogger(CasAuthorizeEndpoint.class);
|
final static Logger _logger = LoggerFactory.getLogger(CasAuthorizeEndpoint.class);
|
||||||
|
|
||||||
@Operation(summary = "CAS页面跳转service认证接口", description = "传递参数service",method="GET")
|
@Operation(summary = "CAS页面跳转service认证接口", description = "传递参数service",method="GET")
|
||||||
@RequestMapping(CasConstants.ENDPOINT.ENDPOINT_LOGIN)
|
@GetMapping(CasConstants.ENDPOINT.ENDPOINT_LOGIN)
|
||||||
public ModelAndView casLogin(
|
public ModelAndView casLogin(@RequestParam(value=CasConstants.PARAMETER.SERVICE,required=false) String casService,
|
||||||
HttpServletRequest request,
|
HttpServletRequest request,
|
||||||
HttpServletResponse response,
|
HttpServletResponse response
|
||||||
@RequestParam(value=CasConstants.PARAMETER.SERVICE,required=false) String casService){
|
){
|
||||||
|
|
||||||
AppsCasDetails casDetails=casDetailsService.getAppDetails(casService , true);
|
AppsCasDetails casDetails = casDetailsService.getAppDetails(casService , true);
|
||||||
|
|
||||||
return buildCasModelAndView(request,response,casDetails,casService);
|
return buildCasModelAndView(request,response,casDetails,casService);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "CAS页面跳转应用ID认证接口", description = "传递参数应用ID",method="GET")
|
@Operation(summary = "CAS页面跳转应用ID认证接口", description = "传递参数应用ID",method="GET")
|
||||||
@RequestMapping(CasConstants.ENDPOINT.ENDPOINT_BASE + "/{id}")
|
@GetMapping(CasConstants.ENDPOINT.ENDPOINT_BASE + "/{id}")
|
||||||
public ModelAndView authorize(
|
public ModelAndView authorize( @PathVariable("id") String id,
|
||||||
HttpServletRequest request,
|
HttpServletRequest request,
|
||||||
HttpServletResponse response,
|
HttpServletResponse response
|
||||||
@PathVariable("id") String id){
|
){
|
||||||
|
|
||||||
AppsCasDetails casDetails=casDetailsService.getAppDetails(id , true);
|
AppsCasDetails casDetails = casDetailsService.getAppDetails(id , true);
|
||||||
|
|
||||||
return buildCasModelAndView(request,response,casDetails,casDetails.getCallbackUrl());
|
return buildCasModelAndView(request,response,casDetails,casDetails == null ? id : casDetails.getCallbackUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ModelAndView buildCasModelAndView(
|
private ModelAndView buildCasModelAndView( HttpServletRequest request,
|
||||||
HttpServletRequest request,
|
|
||||||
HttpServletResponse response,
|
HttpServletResponse response,
|
||||||
AppsCasDetails casDetails,
|
AppsCasDetails casDetails,
|
||||||
String casService){
|
String casService){
|
||||||
|
if(casDetails == null) {
|
||||||
|
_logger.debug("service {} not registered " , casService);
|
||||||
|
ModelAndView modelAndView = new ModelAndView("authorize/cas_sso_submint");
|
||||||
|
modelAndView.addObject("errorMessage", casService);
|
||||||
|
return modelAndView;
|
||||||
|
}
|
||||||
|
|
||||||
_logger.debug(""+casDetails);
|
_logger.debug("Detail {}" , casDetails);
|
||||||
Map<String, String> parameterMap = WebContext.getRequestParameterMap(request);
|
Map<String, String> parameterMap = WebContext.getRequestParameterMap(request);
|
||||||
String service = casService;
|
String service = casService;
|
||||||
_logger.debug("CAS Parameter service = {}" , service);
|
_logger.debug("CAS Parameter service = {}" , service);
|
||||||
@ -101,23 +106,21 @@ public class CasAuthorizeEndpoint extends CasBaseAuthorizeEndpoint{
|
|||||||
}
|
}
|
||||||
_logger.debug("CAS service with Parameter : {}" , parameterMap);
|
_logger.debug("CAS service with Parameter : {}" , parameterMap);
|
||||||
}
|
}
|
||||||
WebContext.setAttribute(
|
WebContext.setAttribute(CasConstants.PARAMETER.PARAMETER_MAP, parameterMap);
|
||||||
CasConstants.PARAMETER.PARAMETER_MAP,
|
|
||||||
parameterMap
|
|
||||||
);
|
|
||||||
|
|
||||||
WebContext.setAttribute(CasConstants.PARAMETER.ENDPOINT_CAS_DETAILS, casDetails);
|
WebContext.setAttribute(CasConstants.PARAMETER.ENDPOINT_CAS_DETAILS, casDetails);
|
||||||
WebContext.setAttribute(WebConstants.SINGLE_SIGN_ON_APP_ID, casDetails.getId());
|
WebContext.setAttribute(WebConstants.SINGLE_SIGN_ON_APP_ID, casDetails.getId());
|
||||||
WebContext.setAttribute(WebConstants.AUTHORIZE_SIGN_ON_APP,casDetails);
|
WebContext.setAttribute(WebConstants.AUTHORIZE_SIGN_ON_APP,casDetails);
|
||||||
return WebContext.redirect(CasConstants.ENDPOINT.ENDPOINT_SERVICE_TICKET_GRANTING);
|
return WebContext.redirect(CasConstants.ENDPOINT.ENDPOINT_SERVICE_TICKET_GRANTING);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(CasConstants.ENDPOINT.ENDPOINT_SERVICE_TICKET_GRANTING)
|
@RequestMapping(CasConstants.ENDPOINT.ENDPOINT_SERVICE_TICKET_GRANTING)
|
||||||
public ModelAndView grantingTicket(Principal principal,
|
public ModelAndView grantingTicket( Principal principal,
|
||||||
@AuthenticationPrincipal Object user,
|
|
||||||
HttpServletRequest request,
|
HttpServletRequest request,
|
||||||
HttpServletResponse response){
|
HttpServletResponse response){
|
||||||
|
ModelAndView modelAndView = new ModelAndView("authorize/cas_sso_submint");
|
||||||
AppsCasDetails casDetails = (AppsCasDetails)WebContext.getAttribute(CasConstants.PARAMETER.ENDPOINT_CAS_DETAILS);
|
AppsCasDetails casDetails = (AppsCasDetails)WebContext.getAttribute(CasConstants.PARAMETER.ENDPOINT_CAS_DETAILS);
|
||||||
|
|
||||||
ServiceTicketImpl serviceTicket = new ServiceTicketImpl(AuthorizationUtils.getAuthentication(),casDetails);
|
ServiceTicketImpl serviceTicket = new ServiceTicketImpl(AuthorizationUtils.getAuthentication(),casDetails);
|
||||||
|
|
||||||
String ticket = ticketServices.createTicket(serviceTicket,casDetails.getExpires());
|
String ticket = ticketServices.createTicket(serviceTicket,casDetails.getExpires());
|
||||||
@ -159,8 +162,6 @@ public class CasAuthorizeEndpoint extends CasBaseAuthorizeEndpoint{
|
|||||||
}
|
}
|
||||||
|
|
||||||
_logger.debug("redirect to CAS Client URL {}" , callbackUrl);
|
_logger.debug("redirect to CAS Client URL {}" , callbackUrl);
|
||||||
|
|
||||||
ModelAndView modelAndView=new ModelAndView("authorize/cas_sso_submint");
|
|
||||||
modelAndView.addObject("callbackUrl", callbackUrl.toString());
|
modelAndView.addObject("callbackUrl", callbackUrl.toString());
|
||||||
return modelAndView;
|
return modelAndView;
|
||||||
}
|
}
|
||||||
@ -174,11 +175,9 @@ public class CasAuthorizeEndpoint extends CasBaseAuthorizeEndpoint{
|
|||||||
*/
|
*/
|
||||||
@Operation(summary = "CAS注销接口", description = "CAS注销接口",method="GET")
|
@Operation(summary = "CAS注销接口", description = "CAS注销接口",method="GET")
|
||||||
@RequestMapping(CasConstants.ENDPOINT.ENDPOINT_LOGOUT)
|
@RequestMapping(CasConstants.ENDPOINT.ENDPOINT_LOGOUT)
|
||||||
public ModelAndView logout(
|
public ModelAndView logout(HttpServletRequest request , HttpServletResponse response,
|
||||||
HttpServletRequest request,
|
@RequestParam(value = CasConstants.PARAMETER.SERVICE , required = false) String casService){
|
||||||
HttpServletResponse response,
|
StringBuffer logoutUrl = new StringBuffer("force/logout");
|
||||||
@RequestParam(value=CasConstants.PARAMETER.SERVICE,required=false) String casService){
|
|
||||||
StringBuffer logoutUrl = new StringBuffer("/force/logout");
|
|
||||||
if(StringUtils.isNotBlank(casService)){
|
if(StringUtils.isNotBlank(casService)){
|
||||||
logoutUrl.append("?").append("redirect_uri=").append(casService);
|
logoutUrl.append("?").append("redirect_uri=").append(casService);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -106,6 +106,12 @@ public class SingleSignOnInterceptor implements AsyncHandlerInterceptor {
|
|||||||
request.getParameter(OAuth2Constants.PARAMETER.CLIENT_ID),true);
|
request.getParameter(OAuth2Constants.PARAMETER.CLIENT_ID),true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(app == null) {
|
||||||
|
_logger.debug("preHandle app is not exist . ");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
SignPrincipal principal = AuthorizationUtils.getPrincipal();
|
SignPrincipal principal = AuthorizationUtils.getPrincipal();
|
||||||
if(principal != null && app !=null) {
|
if(principal != null && app !=null) {
|
||||||
if(principal.getGrantedAuthorityApps().contains(new SimpleGrantedAuthority(app.getId()))) {
|
if(principal.getGrantedAuthorityApps().contains(new SimpleGrantedAuthority(app.getId()))) {
|
||||||
|
|||||||
@ -5,24 +5,29 @@
|
|||||||
<#include "authorize_common.ftl">
|
<#include "authorize_common.ftl">
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function redirectToLogin(){
|
function redirectToLogin(){
|
||||||
|
<#if callbackUrl??>
|
||||||
var srcUrl = window.top.location.href;
|
var srcUrl = window.top.location.href;
|
||||||
srcUrl = srcUrl.substring(srcUrl.indexOf("#"));
|
srcUrl = srcUrl.substring(srcUrl.indexOf("#"));
|
||||||
var callbackUrl = "${callbackUrl}";
|
var callbackUrl = "${callbackUrl!}";
|
||||||
if(srcUrl.indexOf("#") >-1 ){
|
if(srcUrl.indexOf("#") >-1 ){
|
||||||
callbackUrl =callbackUrl + srcUrl;
|
callbackUrl =callbackUrl + srcUrl;
|
||||||
}
|
}
|
||||||
window.top.location.href = callbackUrl;
|
window.top.location.href = callbackUrl;
|
||||||
|
</#if>
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body onload="redirectToLogin()" style="display:none">
|
<body onload="redirectToLogin()" >
|
||||||
<form id="cas_sso_form" name="cas_sso_form" action="${callbackUrl}" method="get">
|
<form id="cas_sso_form" name="cas_sso_form" action="${callbackUrl!}" method="get" style="display:none">
|
||||||
<table style="width:100%">
|
<table style="width:100%">
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2"><input type="submit" name="submitBtn" value="Continue..." /></td>
|
<td colspan="2"><input type="submit" name="submitBtn" value="Continue..." /></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</form>
|
</form>
|
||||||
|
<#if errorMessage??>
|
||||||
|
service ${errorMessage!} not registered .
|
||||||
|
</#if>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user