#I844NY 消除Session与Authentication来回嵌套

This commit is contained in:
MaxKey 2023-09-26 14:17:45 +08:00
parent b111a52ccc
commit ef4bfb86f0
16 changed files with 28 additions and 28 deletions

View File

@ -32,7 +32,7 @@ public class SignPrincipal implements UserDetails {
UserDetails userDetails; UserDetails userDetails;
Session session; String sessionId;
ArrayList<GrantedAuthority> grantedAuthority; ArrayList<GrantedAuthority> grantedAuthority;
ArrayList<GrantedAuthority> grantedAuthorityApps; ArrayList<GrantedAuthority> grantedAuthorityApps;
boolean authenticated; boolean authenticated;
@ -71,7 +71,7 @@ public class SignPrincipal implements UserDetails {
this.accountNonLocked = true; this.accountNonLocked = true;
this.credentialsNonExpired =true; this.credentialsNonExpired =true;
this.enabled = true; this.enabled = true;
this.session = session; this.sessionId = session.getId();
this.userInfo.setSessionId(session.getId()); this.userInfo.setSessionId(session.getId());
} }
@ -120,13 +120,6 @@ public class SignPrincipal implements UserDetails {
this.grantedAuthority = grantedAuthority; this.grantedAuthority = grantedAuthority;
} }
public Session getSession() {
return session;
}
public void setSession(Session session) {
this.session = session;
}
public boolean isRoleAdministrators() { public boolean isRoleAdministrators() {
return roleAdministrators; return roleAdministrators;
@ -152,7 +145,16 @@ public class SignPrincipal implements UserDetails {
return this.credentialsNonExpired; return this.credentialsNonExpired;
} }
@Override
public String getSessionId() {
return sessionId;
}
public void setSessionId(String sessionId) {
this.sessionId = sessionId;
}
@Override
public boolean isEnabled() { public boolean isEnabled() {
return this.enabled; return this.enabled;
} }
@ -192,8 +194,6 @@ public class SignPrincipal implements UserDetails {
builder.append(userInfo); builder.append(userInfo);
builder.append(", userDetails="); builder.append(", userDetails=");
builder.append(userDetails); builder.append(userDetails);
builder.append(", session=");
builder.append(session);
builder.append(", grantedAuthority="); builder.append(", grantedAuthority=");
builder.append(grantedAuthority); builder.append(grantedAuthority);
builder.append(", grantedAuthorityApps="); builder.append(", grantedAuthorityApps=");

View File

@ -89,7 +89,7 @@ public class AuthJwt implements Serializable {
this.expiresIn = expiresIn; this.expiresIn = expiresIn;
this.refreshToken = refreshToken; this.refreshToken = refreshToken;
this.ticket = principal.getSession().getId(); this.ticket = principal.getSessionId();
this.id = principal.getUserInfo().getId(); this.id = principal.getUserInfo().getId();
this.username = principal.getUserInfo().getUsername(); this.username = principal.getUserInfo().getUsername();
this.name = this.username; this.name = this.username;

View File

@ -56,7 +56,7 @@ public class AuthJwtService {
JWTClaimsSet jwtClaims =new JWTClaimsSet.Builder() JWTClaimsSet jwtClaims =new JWTClaimsSet.Builder()
.issuer(issuer) .issuer(issuer)
.subject(subject) .subject(subject)
.jwtID(principal.getSession().getId()) .jwtID(principal.getSessionId())
.issueTime(currentDateTime.toDate()) .issueTime(currentDateTime.toDate())
.expirationTime(expirationTime) .expirationTime(expirationTime)
.claim("locale", userInfo.getLocale()) .claim("locale", userInfo.getLocale())

View File

@ -65,7 +65,7 @@ public class HttpSessionListenerAdapter implements HttpSessionListener {
session.getId(), session.getId(),
signPrincipal.getUserInfo().getId(), signPrincipal.getUserInfo().getId(),
signPrincipal.getUserInfo().getUsername(), signPrincipal.getUserInfo().getUsername(),
signPrincipal.getSession().getId()); signPrincipal.getSessionId());
}else if(principal instanceof User) { }else if(principal instanceof User) {
User user = (User)principal; User user = (User)principal;
_logger.trace("{} HttpSession Id {} for username {} password {} Destroyed" , _logger.trace("{} HttpSession Id {} for username {} password {} Destroyed" ,

View File

@ -35,7 +35,7 @@ public class ProductEnvironment {
String key = it.next(); String key = it.next();
logger.trace("{} = {}" , key , map.get(key)); logger.trace("{} = {}" , key , map.get(key));
} }
logger.debug("APP_HOME" + " = {}" , PathUtils.getInstance().getAppPath()); logger.info("APP_HOME" + " = {}" , PathUtils.getInstance().getAppPath());
Processor processor = ArchUtils.getProcessor(); Processor processor = ArchUtils.getProcessor();
if (Objects.isNull(processor)){ if (Objects.isNull(processor)){

View File

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

View File

@ -155,7 +155,7 @@ public class CasAuthorizeEndpoint extends CasBaseAuthorizeEndpoint{
if(casDetails.getLogoutType()==LogoutType.BACK_CHANNEL) { if(casDetails.getLogoutType()==LogoutType.BACK_CHANNEL) {
_logger.debug("CAS LogoutType BACK_CHANNEL ... "); _logger.debug("CAS LogoutType BACK_CHANNEL ... ");
String sessionId = AuthorizationUtils.getPrincipal().getSession().getId(); String sessionId = AuthorizationUtils.getPrincipal().getSessionId();
_logger.trace("get session by id {} . ",sessionId); _logger.trace("get session by id {} . ",sessionId);
Session session = sessionManager.get(sessionId); Session session = sessionManager.get(sessionId);
_logger.trace("current session {} ",session); _logger.trace("current session {} ",session);

View File

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

View File

@ -61,7 +61,7 @@ public class CasPlainAdapter extends AbstractAuthorizeAdapter {
serviceResponseBuilder.setAttribute("departmentId", userInfo.getDepartmentId()); serviceResponseBuilder.setAttribute("departmentId", userInfo.getDepartmentId());
serviceResponseBuilder.setAttribute("workRegion",userInfo.getWorkRegion()); serviceResponseBuilder.setAttribute("workRegion",userInfo.getWorkRegion());
serviceResponseBuilder.setAttribute("institution", userInfo.getInstId()); serviceResponseBuilder.setAttribute("institution", userInfo.getInstId());
serviceResponseBuilder.setAttribute(WebConstants.ONLINE_TICKET_NAME,principal.getSession().getFormattedId()); serviceResponseBuilder.setAttribute(WebConstants.ONLINE_TICKET_NAME,principal.getSessionId());
return serviceResponseBuilder; return serviceResponseBuilder;
} }

View File

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

View File

@ -50,7 +50,7 @@ public class OAuth2UserDetailsService implements UserDetailsService {
SignPrincipal principal = new SignPrincipal(userInfo); SignPrincipal principal = new SignPrincipal(userInfo);
Session onlineTicket = new Session(onlineTickitId); Session onlineTicket = new Session(onlineTickitId);
//set OnlineTicket //set OnlineTicket
principal.setSession(onlineTicket); principal.setSessionId(onlineTicket.getId());
ArrayList<GrantedAuthority> grantedAuthoritys = loginRepository.grantAuthority(userInfo); ArrayList<GrantedAuthority> grantedAuthoritys = loginRepository.grantAuthority(userInfo);
principal.setAuthenticated(true); principal.setAuthenticated(true);

View File

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

View File

@ -123,7 +123,7 @@ public class UserInfoOIDCEndpoint {
String userJson = ""; String userJson = "";
Builder jwtClaimsSetBuilder= new JWTClaimsSet.Builder(); Builder jwtClaimsSetBuilder= new JWTClaimsSet.Builder();
SignPrincipal authentication = (SignPrincipal)oAuth2Authentication.getUserAuthentication().getPrincipal(); SignPrincipal oauthPrincipal = (SignPrincipal)oAuth2Authentication.getUserAuthentication().getPrincipal();
String subject = AbstractAuthorizeAdapter.getValueByUserAttr(userInfo, clientDetails.getSubject()); String subject = AbstractAuthorizeAdapter.getValueByUserAttr(userInfo, clientDetails.getSubject());
_logger.debug("userId : {} , username : {} , displayName : {} , subject : {}" , _logger.debug("userId : {} , username : {} , displayName : {} , subject : {}" ,
@ -134,7 +134,7 @@ public class UserInfoOIDCEndpoint {
jwtClaimsSetBuilder.claim("sub", subject); jwtClaimsSetBuilder.claim("sub", subject);
jwtClaimsSetBuilder.claim("institution", userInfo.getInstId()); jwtClaimsSetBuilder.claim("institution", userInfo.getInstId());
jwtClaimsSetBuilder.claim(WebConstants.ONLINE_TICKET_NAME, authentication.getSession().getFormattedId()); jwtClaimsSetBuilder.claim(WebConstants.ONLINE_TICKET_NAME, oauthPrincipal.getSessionId());
if(scopes.contains("profile")){ if(scopes.contains("profile")){
jwtClaimsSetBuilder.claim("userId", userInfo.getId()); jwtClaimsSetBuilder.claim("userId", userInfo.getId());

View File

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

View File

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

View File

@ -63,7 +63,7 @@ public class HistorySignOnAppInterceptor implements AsyncHandlerInterceptor {
SignPrincipal principal = AuthorizationUtils.getPrincipal(); SignPrincipal principal = AuthorizationUtils.getPrincipal();
if(principal != null && app !=null) { if(principal != null && app !=null) {
final UserInfo userInfo = principal.getUserInfo(); final UserInfo userInfo = principal.getUserInfo();
String sessionId = principal.getSession().getId(); String sessionId = principal.getSessionId();
logger.debug("sessionId : {} , appId {}" , sessionId , app.getId()); logger.debug("sessionId : {} , appId {}" , sessionId , app.getId());
HistoryLoginApps historyLoginApps = new HistoryLoginApps(); HistoryLoginApps historyLoginApps = new HistoryLoginApps();
historyLoginApps.setAppId(app.getId()); historyLoginApps.setAppId(app.getId());