220413
This commit is contained in:
+1
-1
@@ -42,6 +42,6 @@ public class OnlineTicketEndpoint {
|
||||
public String ticketValidate(
|
||||
@RequestParam(value ="ticket",required = true) String ticket) {
|
||||
OnlineTicket onlineTicket = onlineTicketService.get(ticket);
|
||||
return onlineTicket == null ? "" : onlineTicket.getTicketId();
|
||||
return onlineTicket == null ? "" : onlineTicket.getFormattedTicketId();
|
||||
}
|
||||
}
|
||||
|
||||
+5
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
|
||||
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -44,7 +44,7 @@ public abstract class AbstractAuthorizeAdapter {
|
||||
|
||||
protected Accounts account;
|
||||
|
||||
protected SigninPrincipal authentication;
|
||||
protected SigninPrincipal principal;
|
||||
|
||||
public abstract Object generateInfo();
|
||||
|
||||
@@ -127,12 +127,9 @@ public abstract class AbstractAuthorizeAdapter {
|
||||
return "";
|
||||
};
|
||||
|
||||
public void setAuthentication(SigninPrincipal authentication) {
|
||||
this.authentication = authentication;
|
||||
}
|
||||
|
||||
public void setUserInfo(UserInfo userInfo) {
|
||||
this.userInfo = userInfo;
|
||||
public void setPrincipal(SigninPrincipal principal) {
|
||||
this.principal = principal;
|
||||
this.userInfo = principal.getUserInfo();
|
||||
}
|
||||
|
||||
public void setApp(Apps app) {
|
||||
|
||||
+1
-1
@@ -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().getTicketId());
|
||||
logoutParameters.put("ticket", ((SigninPrincipal)authentication.getPrincipal()).getOnlineTicket().getFormattedTicketId());
|
||||
postMessage(logoutApp.getLogoutUrl(),logoutParameters);
|
||||
|
||||
}
|
||||
|
||||
+2
-9
@@ -36,7 +36,6 @@ import org.maxkey.authz.cas.endpoint.ticket.ProxyTicketImpl;
|
||||
import org.maxkey.authz.cas.endpoint.ticket.Ticket;
|
||||
import org.maxkey.authz.endpoint.adapter.AbstractAuthorizeAdapter;
|
||||
import org.maxkey.constants.ConstsBoolean;
|
||||
import org.maxkey.entity.UserInfo;
|
||||
import org.maxkey.util.Instance;
|
||||
import org.maxkey.util.StringUtils;
|
||||
import org.maxkey.web.HttpResponseConstants;
|
||||
@@ -228,11 +227,8 @@ For all error codes, it is RECOMMENDED that CAS provide a more detailed message
|
||||
_logger.error("setProperty error . ", e);
|
||||
}
|
||||
|
||||
UserInfo userInfo = (UserInfo) userInfoService.findByUsername(authentication.getUsername());
|
||||
|
||||
AbstractAuthorizeAdapter adapter =(AbstractAuthorizeAdapter)samlAdapter;
|
||||
adapter.setAuthentication(authentication);
|
||||
adapter.setUserInfo(userInfo);
|
||||
adapter.setPrincipal(authentication);
|
||||
adapter.setApp(storedTicket.getCasDetails());
|
||||
adapter.generateInfo();
|
||||
}
|
||||
@@ -345,11 +341,8 @@ Response on ticket validation failure:
|
||||
_logger.error("setProperty error . ", e);
|
||||
}
|
||||
|
||||
UserInfo userInfo = (UserInfo) userInfoService.findByUsername(authentication.getUsername());
|
||||
|
||||
AbstractAuthorizeAdapter adapter =(AbstractAuthorizeAdapter)samlAdapter;
|
||||
adapter.setAuthentication(authentication);
|
||||
adapter.setUserInfo(userInfo);
|
||||
adapter.setPrincipal(authentication);
|
||||
adapter.setApp(storedTicket.getCasDetails());
|
||||
adapter.generateInfo();
|
||||
}
|
||||
|
||||
+2
-9
@@ -36,7 +36,6 @@ import org.maxkey.authz.cas.endpoint.ticket.ProxyTicketImpl;
|
||||
import org.maxkey.authz.cas.endpoint.ticket.Ticket;
|
||||
import org.maxkey.authz.endpoint.adapter.AbstractAuthorizeAdapter;
|
||||
import org.maxkey.constants.ConstsBoolean;
|
||||
import org.maxkey.entity.UserInfo;
|
||||
import org.maxkey.util.Instance;
|
||||
import org.maxkey.util.StringUtils;
|
||||
import org.maxkey.web.HttpResponseConstants;
|
||||
@@ -109,11 +108,8 @@ public class Cas30AuthorizeEndpoint extends CasBaseAuthorizeEndpoint{
|
||||
_logger.error("setProperty error . ", e);
|
||||
}
|
||||
|
||||
UserInfo userInfo = (UserInfo) userInfoService.findByUsername(authentication.getUsername());
|
||||
|
||||
AbstractAuthorizeAdapter adapter =(AbstractAuthorizeAdapter)samlAdapter;
|
||||
adapter.setAuthentication(authentication);
|
||||
adapter.setUserInfo(userInfo);
|
||||
adapter.setPrincipal(authentication);
|
||||
adapter.setApp(storedTicket.getCasDetails());
|
||||
adapter.generateInfo();
|
||||
}
|
||||
@@ -190,11 +186,8 @@ public class Cas30AuthorizeEndpoint extends CasBaseAuthorizeEndpoint{
|
||||
_logger.error("setProperty error . ", e);
|
||||
}
|
||||
|
||||
UserInfo userInfo = (UserInfo) userInfoService.findByUsername(authentication.getUsername());
|
||||
|
||||
AbstractAuthorizeAdapter adapter =(AbstractAuthorizeAdapter)samlAdapter;
|
||||
adapter.setAuthentication(authentication);
|
||||
adapter.setUserInfo(userInfo);
|
||||
adapter.setPrincipal(authentication);
|
||||
adapter.setApp(storedTicket.getCasDetails());
|
||||
adapter.generateInfo();
|
||||
}
|
||||
|
||||
+1
-1
@@ -149,7 +149,7 @@ public class CasAuthorizeEndpoint extends CasBaseAuthorizeEndpoint{
|
||||
}
|
||||
|
||||
if(casDetails.getLogoutType()==LogoutType.BACK_CHANNEL) {
|
||||
String onlineTicketId = AuthorizationUtils.getPrincipal().getOnlineTicket().getTicketId();
|
||||
String onlineTicketId = AuthorizationUtils.getPrincipal().getOnlineTicket().getFormattedTicketId();
|
||||
OnlineTicket onlineTicket = onlineTicketService.get(onlineTicketId);
|
||||
//set cas ticket as OnlineTicketId
|
||||
casDetails.setOnlineTicket(ticket);
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
|
||||
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -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,authentication.getOnlineTicket().getTicketId());
|
||||
serviceResponseBuilder.setAttribute(WebConstants.ONLINE_TICKET_NAME,principal.getOnlineTicket().getFormattedTicketId());
|
||||
|
||||
return serviceResponseBuilder;
|
||||
}
|
||||
|
||||
+1
-2
@@ -67,8 +67,7 @@ public class ExtendApiAuthorizeEndpoint extends AuthorizeBaseEndpoint{
|
||||
return generateInitCredentialModelAndView(id,"/authorize/api/"+id);
|
||||
}
|
||||
|
||||
adapter.setAuthentication(AuthorizationUtils.getPrincipal());
|
||||
adapter.setUserInfo(currentUser);
|
||||
adapter.setPrincipal(AuthorizationUtils.getPrincipal());
|
||||
adapter.setApp(apps);
|
||||
adapter.setAccount(account);
|
||||
|
||||
|
||||
+1
-2
@@ -90,8 +90,7 @@ public class FormBasedAuthorizeEndpoint extends AuthorizeBaseEndpoint{
|
||||
FormBasedDefaultAdapter formBasedDefaultAdapter =new FormBasedDefaultAdapter();
|
||||
adapter =(AbstractAuthorizeAdapter)formBasedDefaultAdapter;
|
||||
}
|
||||
adapter.setAuthentication(AuthorizationUtils.getPrincipal());
|
||||
adapter.setUserInfo(currentUser);
|
||||
adapter.setPrincipal(AuthorizationUtils.getPrincipal());
|
||||
adapter.setApp(formBasedDetails);
|
||||
adapter.setAccount(account);
|
||||
|
||||
|
||||
+1
-1
@@ -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, authentication.getOnlineTicket().getTicketId())
|
||||
.claim(WebConstants.ONLINE_TICKET_NAME, principal.getOnlineTicket().getFormattedTicketId())
|
||||
.claim("kid", jwtDetails.getId()+ "_sig")
|
||||
.claim("institution", userInfo.getInstId())
|
||||
.build();
|
||||
|
||||
+1
-2
@@ -101,8 +101,7 @@ public class JwtAuthorizeEndpoint extends AuthorizeBaseEndpoint{
|
||||
adapter = (AbstractAuthorizeAdapter)jwtAdapter;
|
||||
}
|
||||
|
||||
adapter.setAuthentication(AuthorizationUtils.getPrincipal());
|
||||
adapter.setUserInfo(currentUser);
|
||||
adapter.setPrincipal(AuthorizationUtils.getPrincipal());
|
||||
|
||||
adapter.generateInfo();
|
||||
//sign
|
||||
|
||||
+6
-6
@@ -47,25 +47,25 @@ public class OAuth2UserDetailsService implements UserDetailsService {
|
||||
|
||||
String onlineTickitId = WebConstants.ONLINE_TICKET_PREFIX + "-" + java.util.UUID.randomUUID().toString().toLowerCase();
|
||||
|
||||
SigninPrincipal signinPrincipal = new SigninPrincipal(userInfo);
|
||||
SigninPrincipal principal = new SigninPrincipal(userInfo);
|
||||
OnlineTicket onlineTicket = new OnlineTicket(onlineTickitId);
|
||||
//set OnlineTicket
|
||||
signinPrincipal.setOnlineTicket(onlineTicket);
|
||||
principal.setOnlineTicket(onlineTicket);
|
||||
|
||||
ArrayList<GrantedAuthority> grantedAuthoritys = loginRepository.grantAuthority(userInfo);
|
||||
signinPrincipal.setAuthenticated(true);
|
||||
principal.setAuthenticated(true);
|
||||
|
||||
for(GrantedAuthority administratorsAuthority : AbstractAuthenticationProvider.grantedAdministratorsAuthoritys) {
|
||||
if(grantedAuthoritys.contains(administratorsAuthority)) {
|
||||
signinPrincipal.setRoleAdministrators(true);
|
||||
principal.setRoleAdministrators(true);
|
||||
_logger.trace("ROLE ADMINISTRATORS Authentication .");
|
||||
}
|
||||
}
|
||||
_logger.debug("Granted Authority " + grantedAuthoritys);
|
||||
|
||||
signinPrincipal.setGrantedAuthorityApps(grantedAuthoritys);
|
||||
principal.setGrantedAuthorityApps(grantedAuthoritys);
|
||||
|
||||
return signinPrincipal;
|
||||
return principal;
|
||||
}
|
||||
|
||||
public void setLoginRepository(LoginRepository loginRepository) {
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
|
||||
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
|
||||
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -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, authentication.getOnlineTicket().getTicketId());
|
||||
beanMap.put(WebConstants.ONLINE_TICKET_NAME, principal.getOnlineTicket().getFormattedTicketId());
|
||||
|
||||
String info= JsonUtils.object2Json(beanMap);
|
||||
|
||||
|
||||
+1
-6
@@ -93,18 +93,14 @@ public class UserInfoEndpoint {
|
||||
httpResponseAdapter.write(response,JsonUtils.gson2Json(accessTokenFormatError(access_token)),"json");
|
||||
}
|
||||
|
||||
String principal="";
|
||||
OAuth2Authentication oAuth2Authentication =null;
|
||||
try{
|
||||
oAuth2Authentication = oauth20tokenServices.loadAuthentication(access_token);
|
||||
|
||||
principal=((SigninPrincipal)oAuth2Authentication.getUserAuthentication().getPrincipal()).getUsername();
|
||||
|
||||
String client_id= oAuth2Authentication.getOAuth2Request().getClientId();
|
||||
ClientDetails clientDetails =
|
||||
clientDetailsService.loadClientByClientId(client_id,true);
|
||||
|
||||
UserInfo userInfo=queryUserInfo(principal);
|
||||
Apps app = appsService.get(client_id);
|
||||
|
||||
AbstractAuthorizeAdapter adapter;
|
||||
@@ -118,8 +114,7 @@ public class UserInfoEndpoint {
|
||||
}else{
|
||||
adapter =(AbstractAuthorizeAdapter)new OAuthDefaultUserInfoAdapter(clientDetails);
|
||||
}
|
||||
adapter.setAuthentication((SigninPrincipal)oAuth2Authentication.getUserAuthentication().getPrincipal());
|
||||
adapter.setUserInfo(userInfo);
|
||||
adapter.setPrincipal((SigninPrincipal)oAuth2Authentication.getUserAuthentication().getPrincipal());
|
||||
adapter.setApp(app);
|
||||
|
||||
Object jsonData = adapter.generateInfo();
|
||||
|
||||
+1
-1
@@ -134,7 +134,7 @@ public class UserInfoOIDCEndpoint {
|
||||
|
||||
jwtClaimsSetBuilder.claim("sub", subject);
|
||||
jwtClaimsSetBuilder.claim("institution", userInfo.getInstId());
|
||||
jwtClaimsSetBuilder.claim(WebConstants.ONLINE_TICKET_NAME, authentication.getOnlineTicket().getTicketId());
|
||||
jwtClaimsSetBuilder.claim(WebConstants.ONLINE_TICKET_NAME, authentication.getOnlineTicket().getFormattedTicketId());
|
||||
|
||||
if(scopes.contains("profile")){
|
||||
jwtClaimsSetBuilder.claim("userId", userInfo.getId());
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
|
||||
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -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().getTicketId());
|
||||
AuthorizationUtils.getPrincipal().getOnlineTicket().getFormattedTicketId());
|
||||
|
||||
//saml20Details
|
||||
Response authResponse = authnResponseGenerator.generateAuthnResponse(
|
||||
|
||||
+1
-2
@@ -87,8 +87,7 @@ public class TokenBasedAuthorizeEndpoint extends AuthorizeBaseEndpoint{
|
||||
}else{
|
||||
adapter =(AbstractAuthorizeAdapter)new TokenBasedDefaultAdapter();
|
||||
}
|
||||
adapter.setAuthentication(AuthorizationUtils.getPrincipal());
|
||||
adapter.setUserInfo(currentUser);
|
||||
adapter.setPrincipal(AuthorizationUtils.getPrincipal());
|
||||
adapter.setApp(tokenBasedDetails);
|
||||
|
||||
adapter.generateInfo();
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ public class TokenBasedDefaultAdapter extends AbstractAuthorizeAdapter {
|
||||
}
|
||||
|
||||
beanMap.put("displayName", userInfo.getDisplayName());
|
||||
beanMap.put(WebConstants.ONLINE_TICKET_NAME, authentication.getOnlineTicket().getTicketId());
|
||||
beanMap.put(WebConstants.ONLINE_TICKET_NAME, principal.getOnlineTicket().getFormattedTicketId());
|
||||
|
||||
/*
|
||||
* use UTC date time format
|
||||
|
||||
Reference in New Issue
Block a user