-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ 业务模块使用 ballcat 提供的安全权限注解,方便与 spring security 解耦
- Loading branch information
Showing
48 changed files
with
408 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...ation/DefaultUserInfoCoordinatorImpl.java → ...urity/DefaultUserInfoCoordinatorImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...min-core/src/main/java/org/ballcat/admin/springsecurity/SpringSecurityPasswordHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.ballcat.admin.springsecurity; | ||
|
||
import org.ballcat.business.system.component.AbstractPasswordHelper; | ||
import org.ballcat.business.system.properties.SystemProperties; | ||
import org.ballcat.security.properties.SecurityProperties; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
|
||
/** | ||
* 基于 SpringSecurity 的密码工具类 | ||
* | ||
* @author Hccake | ||
* @since 2.0.0 | ||
*/ | ||
public class SpringSecurityPasswordHelper extends AbstractPasswordHelper { | ||
|
||
private final PasswordEncoder passwordEncoder; | ||
|
||
public SpringSecurityPasswordHelper(SecurityProperties securityProperties, SystemProperties systemProperties, | ||
PasswordEncoder passwordEncoder) { | ||
super(securityProperties, systemProperties); | ||
this.passwordEncoder = passwordEncoder; | ||
} | ||
|
||
@Override | ||
public String encode(String rawPassword) { | ||
return passwordEncoder.encode(rawPassword); | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
.../main/java/org/ballcat/admin/springsecurity/SpringSecurityPrincipalAttributeAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.ballcat.admin.springsecurity; | ||
|
||
import org.ballcat.security.core.PrincipalAttributeAccessor; | ||
import org.ballcat.springsecurity.oauth2.userdetails.User; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
|
||
public class SpringSecurityPrincipalAttributeAccessor implements PrincipalAttributeAccessor { | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public <A> A getAttribute(String name) { | ||
User user = getUser(); | ||
if (user != null) { | ||
return (A) user.getAttributes().get(name); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public Long getUserId() { | ||
User user = getUser(); | ||
if (user != null) { | ||
return user.getUserId(); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
User user = getUser(); | ||
if (user != null) { | ||
return user.getUsername(); | ||
} | ||
return null; | ||
} | ||
|
||
private static Authentication getAuthentication() { | ||
return SecurityContextHolder.getContext().getAuthentication(); | ||
} | ||
|
||
private static User getUser() { | ||
Authentication authentication = getAuthentication(); | ||
if (authentication == null) { | ||
return null; | ||
} | ||
Object principal = authentication.getPrincipal(); | ||
if (principal instanceof User) { | ||
return (User) principal; | ||
} | ||
else { | ||
return null; | ||
} | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...entication/SysUserDetailsServiceImpl.java → ...ngsecurity/SysUserDetailsServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...m/authentication/UserInfoCoordinator.java → ...n/springsecurity/UserInfoCoordinator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...n/BallcatOAuth2TokenResponseEnhancer.java → ...2/BallcatOAuth2TokenResponseEnhancer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.