|
@@ -1,10 +1,12 @@
|
|
|
package cn.reghao.tnb.auth.app.security;
|
|
package cn.reghao.tnb.auth.app.security;
|
|
|
|
|
|
|
|
|
|
+import cn.reghao.tnb.auth.app.model.po.UserAuthority;
|
|
|
import cn.reghao.tnb.auth.app.security.form.AccountAuthToken;
|
|
import cn.reghao.tnb.auth.app.security.form.AccountAuthToken;
|
|
|
import cn.reghao.tnb.auth.model.JwtPayload;
|
|
import cn.reghao.tnb.auth.model.JwtPayload;
|
|
|
import org.springframework.security.core.GrantedAuthority;
|
|
import org.springframework.security.core.GrantedAuthority;
|
|
|
import org.springframework.security.core.authority.AuthorityUtils;
|
|
import org.springframework.security.core.authority.AuthorityUtils;
|
|
|
|
|
|
|
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
@@ -19,8 +21,9 @@ public class AuthConverter {
|
|
|
long userId = accountAuthToken.getUserId();
|
|
long userId = accountAuthToken.getUserId();
|
|
|
int loginType = accountAuthToken.getLoginType();
|
|
int loginType = accountAuthToken.getLoginType();
|
|
|
String authorities = accountAuthToken.getAuthorities().stream()
|
|
String authorities = accountAuthToken.getAuthorities().stream()
|
|
|
- .map(GrantedAuthority::getAuthority)
|
|
|
|
|
- .collect(Collectors.toList())
|
|
|
|
|
|
|
+ .map(grantedAuthority -> grantedAuthority.getAuthority()
|
|
|
|
|
+ .replace("ROLE_", "").toLowerCase())
|
|
|
|
|
+ .toList()
|
|
|
.toString();
|
|
.toString();
|
|
|
String jti = "";
|
|
String jti = "";
|
|
|
return new JwtPayload(plat, loginId, userId, loginType, authorities, jti);
|
|
return new JwtPayload(plat, loginId, userId, loginType, authorities, jti);
|
|
@@ -33,7 +36,10 @@ public class AuthConverter {
|
|
|
int loginType = jwtPayload.getLoginType();
|
|
int loginType = jwtPayload.getLoginType();
|
|
|
String authoritiesStr = jwtPayload.getAuthorities();
|
|
String authoritiesStr = jwtPayload.getAuthorities();
|
|
|
String authoritiesStr0 = authoritiesStr.replace("[", "").replace("]", "");
|
|
String authoritiesStr0 = authoritiesStr.replace("[", "").replace("]", "");
|
|
|
- List<GrantedAuthority> authorities = AuthorityUtils.commaSeparatedStringToAuthorityList(authoritiesStr0);
|
|
|
|
|
|
|
+ List<String> authorityList = Arrays.stream(authoritiesStr0.split(","))
|
|
|
|
|
+ .map(role -> String.format("ROLE_%s", role.toUpperCase()))
|
|
|
|
|
+ .toList();
|
|
|
|
|
+ List<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList(authorityList);
|
|
|
return new AccountAuthToken(plat, loginId, loginType, userId, authorities);
|
|
return new AccountAuthToken(plat, loginId, loginType, userId, authorities);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|