支持无权限用户的身份证

This commit is contained in:
chenjun committed 2020-05-23 23:04:30 +08:00
1 parent 2dfd732d04
commit 8d659cff85
2 files changed
+7 -2

No files matched your search

@@ -100,7 +100,7 @@ public class PigxUserAuthenticationConverter implements UserAuthenticationConver
return AuthorityUtils.commaSeparatedStringToAuthorityList(StringUtils
.collectionToCommaDelimitedString((Collection<?>) authorities));
}
throw new IllegalArgumentException("Authorities must be either a String or a Collection");
return AuthorityUtils.NO_AUTHORITIES;
}
private void validateTenantId(Map<String, ?> map) {
@@ -23,6 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
@@ -46,7 +47,7 @@ public class AuthenticationSuccessEventListener implements ApplicationListener<A
@Override
public void onApplicationEvent(AuthenticationSuccessEvent event) {
Authentication authentication = (Authentication) event.getSource();
if (CollUtil.isNotEmpty(authentication.getAuthorities()) && successHandler != null) {
if (successHandler != null && isUserAuthentication(authentication)) {
ServletRequestAttributes requestAttributes = (ServletRequestAttributes)
RequestContextHolder.getRequestAttributes();
HttpServletRequest request = requestAttributes.getRequest();
@@ -56,4 +57,8 @@ public class AuthenticationSuccessEventListener implements ApplicationListener<A
}
}
private boolean isUserAuthentication(Authentication authentication){
return authentication instanceof User || CollUtil.isNotEmpty(authentication.getAuthorities());
}
}