This commit is contained in:
MaxKey
2022-04-13 18:47:33 +08:00
parent 3e0764c7cf
commit 786ca40b3c
95 changed files with 1146 additions and 513 deletions

View File

@@ -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) {

View File

@@ -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.

View File

@@ -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);

View File

@@ -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();

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().getTicketId());
jwtClaimsSetBuilder.claim(WebConstants.ONLINE_TICKET_NAME, authentication.getOnlineTicket().getFormattedTicketId());
if(scopes.contains("profile")){
jwtClaimsSetBuilder.claim("userId", userInfo.getId());