11package com .featureprobe .api .auth ;
22
33import com .featureprobe .api .base .enums .RoleEnum ;
4+ import com .featureprobe .api .entity .Member ;
45import org .springframework .security .authentication .AbstractAuthenticationToken ;
56import org .springframework .security .core .GrantedAuthority ;
67
@@ -12,7 +13,7 @@ public class UserPasswordAuthenticationToken extends AbstractAuthenticationToken
1213
1314 private String password ;
1415
15- private String role ;
16+ private Member principal ;
1617
1718 public UserPasswordAuthenticationToken (String account , String password ) {
1819 super (null );
@@ -21,16 +22,15 @@ public UserPasswordAuthenticationToken(String account, String password) {
2122 super .setAuthenticated (false );
2223 }
2324
24- public UserPasswordAuthenticationToken (String account , String role ,
25- Collection <? extends GrantedAuthority > authorities ) {
25+ public UserPasswordAuthenticationToken (Member principal , Collection <? extends GrantedAuthority > authorities ) {
2626 super (authorities );
27- this .account = account ;
28- this .role = role ;
27+ this .principal = principal ;
28+ this .account = principal . getAccount () ;
2929 super .setAuthenticated (true );
3030 }
3131
3232 public boolean isAdmin () {
33- return RoleEnum .ADMIN .name ().equals (role );
33+ return RoleEnum .ADMIN .name ().equals (getRole () );
3434 }
3535
3636 @ Override
@@ -39,31 +39,24 @@ public Object getCredentials() {
3939 }
4040
4141 @ Override
42- public Object getPrincipal () {
43- return "admin" ;
42+ public Member getPrincipal () {
43+ return principal ;
4444 }
4545
4646 public String getAccount () {
4747 return account ;
4848 }
4949
50- public void setAccount (String account ) {
51- this .account = account ;
52- }
53-
5450 public String getPassword () {
5551 return password ;
5652 }
5753
58- public void setPassword (String password ) {
59- this .password = password ;
60- }
6154
6255 public String getRole () {
63- return role ;
56+ if (principal == null ) {
57+ return null ;
58+ }
59+ return principal .getRole ().name ();
6460 }
6561
66- public void setRole (String role ) {
67- this .role = role ;
68- }
6962}
0 commit comments