This commit is contained in:
MaxKey
2022-04-26 17:41:04 +08:00
parent 946b346282
commit e51a3a25ba
37 changed files with 236 additions and 218 deletions

View File

@@ -17,8 +17,8 @@
package org.maxkey.authz.endpoint;
import org.maxkey.authn.online.OnlineTicket;
import org.maxkey.authn.online.OnlineTicketService;
import org.maxkey.authn.session.Session;
import org.maxkey.authn.session.SessionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -34,14 +34,14 @@ import io.swagger.v3.oas.annotations.tags.Tag;
public class OnlineTicketEndpoint {
@Autowired
protected OnlineTicketService onlineTicketService;
protected SessionService onlineTicketService;
@Operation(summary = "在线ticket验证接口", description = "",method="GET")
@ResponseBody
@RequestMapping(value="/validate")
public String ticketValidate(
@RequestParam(value ="ticket",required = true) String ticket) {
OnlineTicket onlineTicket = onlineTicketService.get(ticket);
return onlineTicket == null ? "" : onlineTicket.getFormattedTicketId();
Session onlineTicket = onlineTicketService.get(ticket);
return onlineTicket == null ? "" : onlineTicket.getFormattedId();
}
}

View File

@@ -34,7 +34,7 @@ public class DefaultSingleLogout extends SingleLogout{
logoutParameters.put("principal", authentication.getName());
logoutParameters.put("request", "logoutRequest");
logoutParameters.put("issueInstant", DateUtils.getCurrentDateAsString(DateUtils.FORMAT_DATE_ISO_TIMESTAMP));
logoutParameters.put("ticket", ((SigninPrincipal)authentication.getPrincipal()).getOnlineTicket().getFormattedTicketId());
logoutParameters.put("ticket", ((SigninPrincipal)authentication.getPrincipal()).getSession().getFormattedId());
postMessage(logoutApp.getLogoutUrl(),logoutParameters);
}

View File

@@ -26,7 +26,7 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.maxkey.authn.online.OnlineTicket;
import org.maxkey.authn.session.Session;
import org.maxkey.authn.web.AuthorizationUtils;
import org.maxkey.authz.cas.endpoint.ticket.CasConstants;
import org.maxkey.authz.cas.endpoint.ticket.ServiceTicketImpl;
@@ -149,12 +149,12 @@ public class CasAuthorizeEndpoint extends CasBaseAuthorizeEndpoint{
}
if(casDetails.getLogoutType()==LogoutType.BACK_CHANNEL) {
String onlineTicketId = AuthorizationUtils.getPrincipal().getOnlineTicket().getFormattedTicketId();
OnlineTicket onlineTicket = onlineTicketService.get(onlineTicketId);
String sessionId = AuthorizationUtils.getPrincipal().getSession().getFormattedId();
Session session = sessionService.get(sessionId);
//set cas ticket as OnlineTicketId
casDetails.setOnlineTicket(ticket);
onlineTicket.setAuthorizedApp(casDetails);
onlineTicketService.store(onlineTicketId, onlineTicket);
session.setAuthorizedApp(casDetails);
sessionService.store(sessionId, session);
}
_logger.debug("redirect to CAS Client URL {}" , callbackUrl);

View File

@@ -17,7 +17,7 @@
package org.maxkey.authz.cas.endpoint;
import org.maxkey.authn.online.OnlineTicketService;
import org.maxkey.authn.session.SessionService;
import org.maxkey.authz.cas.endpoint.ticket.TicketServices;
import org.maxkey.authz.endpoint.AuthorizeBaseEndpoint;
import org.maxkey.persistence.service.AppsCasDetailsService;
@@ -49,7 +49,7 @@ public class CasBaseAuthorizeEndpoint extends AuthorizeBaseEndpoint{
protected TicketServices casTicketGrantingTicketServices;
@Autowired
protected OnlineTicketService onlineTicketService;
protected SessionService sessionService;
@Autowired
@Qualifier("casProxyGrantingTicketServices")

View File

@@ -75,7 +75,7 @@ public class CasDefaultAdapter extends AbstractAuthorizeAdapter {
serviceResponseBuilder.setAttribute("departmentId", userInfo.getDepartmentId());
serviceResponseBuilder.setAttribute("workRegion",base64Attr(userInfo.getWorkRegion()));
serviceResponseBuilder.setAttribute("institution", userInfo.getInstId());
serviceResponseBuilder.setAttribute(WebConstants.ONLINE_TICKET_NAME,principal.getOnlineTicket().getFormattedTicketId());
serviceResponseBuilder.setAttribute(WebConstants.ONLINE_TICKET_NAME,principal.getSession().getFormattedId());
return serviceResponseBuilder;
}

View File

@@ -82,7 +82,7 @@ public class JwtAdapter extends AbstractAuthorizeAdapter {
.claim("user_id", userInfo.getId())
.claim("external_id", userInfo.getId())
.claim("locale", userInfo.getLocale())
.claim(WebConstants.ONLINE_TICKET_NAME, principal.getOnlineTicket().getFormattedTicketId())
.claim(WebConstants.ONLINE_TICKET_NAME, principal.getSession().getFormattedId())
.claim("kid", jwtDetails.getId()+ "_sig")
.claim("institution", userInfo.getInstId())
.build();

View File

@@ -16,7 +16,7 @@ import java.util.ArrayList;
import org.maxkey.authn.AbstractAuthenticationProvider;
import org.maxkey.authn.SigninPrincipal;
import org.maxkey.authn.online.OnlineTicket;
import org.maxkey.authn.session.Session;
import org.maxkey.entity.UserInfo;
import org.maxkey.persistence.repository.LoginRepository;
import org.maxkey.web.WebConstants;
@@ -48,9 +48,9 @@ public class OAuth2UserDetailsService implements UserDetailsService {
String onlineTickitId = WebConstants.ONLINE_TICKET_PREFIX + "-" + java.util.UUID.randomUUID().toString().toLowerCase();
SigninPrincipal principal = new SigninPrincipal(userInfo);
OnlineTicket onlineTicket = new OnlineTicket(onlineTickitId);
Session onlineTicket = new Session(onlineTickitId);
//set OnlineTicket
principal.setOnlineTicket(onlineTicket);
principal.setSession(onlineTicket);
ArrayList<GrantedAuthority> grantedAuthoritys = loginRepository.grantAuthority(userInfo);
principal.setAuthenticated(true);

View File

@@ -66,7 +66,7 @@ public class OAuthDefaultUserInfoAdapter extends AbstractAuthorizeAdapter {
beanMap.put("state", userInfo.getWorkRegion());
beanMap.put("gender", userInfo.getGender());
beanMap.put("institution", userInfo.getInstId());
beanMap.put(WebConstants.ONLINE_TICKET_NAME, principal.getOnlineTicket().getFormattedTicketId());
beanMap.put(WebConstants.ONLINE_TICKET_NAME, principal.getSession().getFormattedId());
String info= JsonUtils.object2Json(beanMap);

View File

@@ -134,7 +134,7 @@ public class UserInfoOIDCEndpoint {
jwtClaimsSetBuilder.claim("sub", subject);
jwtClaimsSetBuilder.claim("institution", userInfo.getInstId());
jwtClaimsSetBuilder.claim(WebConstants.ONLINE_TICKET_NAME, authentication.getOnlineTicket().getFormattedTicketId());
jwtClaimsSetBuilder.claim(WebConstants.ONLINE_TICKET_NAME, authentication.getSession().getFormattedId());
if(scopes.contains("profile")){
jwtClaimsSetBuilder.claim("userId", userInfo.getId());

View File

@@ -78,7 +78,7 @@ public class AssertionEndpoint {
logger.debug("AuthnRequestInfo: {}", authnRequestInfo);
HashMap <String,String>attributeMap=new HashMap<String,String>();
attributeMap.put(WebConstants.ONLINE_TICKET_NAME,
AuthorizationUtils.getPrincipal().getOnlineTicket().getFormattedTicketId());
AuthorizationUtils.getPrincipal().getSession().getFormattedId());
//saml20Details
Response authResponse = authnResponseGenerator.generateAuthnResponse(

View File

@@ -73,7 +73,7 @@ public class TokenBasedDefaultAdapter extends AbstractAuthorizeAdapter {
}
beanMap.put("displayName", userInfo.getDisplayName());
beanMap.put(WebConstants.ONLINE_TICKET_NAME, principal.getOnlineTicket().getFormattedTicketId());
beanMap.put(WebConstants.ONLINE_TICKET_NAME, principal.getSession().getFormattedId());
/*
* use UTC date time format