修复登录问题

This commit is contained in:
Saturneric 2020-02-16 15:52:22 +08:00
parent ee9d71413a
commit 00d626d394
9 changed files with 41 additions and 34 deletions

View File

@ -0,0 +1,19 @@
package com.codesdream.ase.component;
import com.codesdream.ase.model.permission.User;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Collection;
@Component
public class UserAuthoritiesGenerator {
@Resource
UserRolesListGenerator userRolesListGenerator;
public Collection<? extends GrantedAuthority> grantedAuthorities(User user){
return userRolesListGenerator.generateRoles(user);
}
}

View File

@ -1,6 +1,7 @@
package com.codesdream.ase.component;
import com.codesdream.ase.model.permission.*;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Collection;
@ -8,6 +9,7 @@ import java.util.Collection;
/**
* 生成功能性权限容器列表
*/
@Component
public class UserFunctionalPermissionContainersListGenerator {
private UserFunctionalScopeRelationsListGenerator functionalScopeRelationsListGenerator;

View File

@ -3,6 +3,7 @@ package com.codesdream.ase.component;
import com.codesdream.ase.model.permission.FunctionalScopeRelation;
import com.codesdream.ase.model.permission.PermissionContainersCollection;
import com.codesdream.ase.model.permission.User;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Collection;
@ -10,6 +11,7 @@ import java.util.Collection;
/**
* 生成功能性权限容器与范围性权限容器关联对列表
*/
@Component
public class UserFunctionalScopeRelationsListGenerator {
private UserPermissionContainersCollectionsListGenerator userPermissionContainersCollectionsListGenerator;

View File

@ -3,6 +3,7 @@ package com.codesdream.ase.component;
import com.codesdream.ase.model.permission.PermissionContainersCollection;
import com.codesdream.ase.model.permission.Tag;
import com.codesdream.ase.model.permission.User;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Collection;
@ -10,6 +11,7 @@ import java.util.Collection;
/**
* 生成权限容器集合列表
*/
@Component
public class UserPermissionContainersCollectionsListGenerator {
private UserTagsListGenerator userTagsListGenerator;

View File

@ -4,6 +4,7 @@ import com.codesdream.ase.model.permission.FunctionalPermissionContainer;
import com.codesdream.ase.model.permission.User;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Collection;
@ -11,7 +12,7 @@ import java.util.Collection;
/**
* 生成用户访问权限角色列表
*/
@Component
public class UserRolesListGenerator {
private UserFunctionalPermissionContainersListGenerator functionalPermissionContainersListGenerator;

View File

@ -14,6 +14,7 @@ import java.util.Optional;
/**
* 生成用户标签列表
*/
@Component
public class UserTagsListGenerator {
@Resource
UserRepository userRepository;

View File

@ -6,29 +6,6 @@ import org.springframework.context.annotation.Configuration;
@Configuration
public class ComponentsConfigure {
@Bean
UserTagsListGenerator userTagsListGenerator(){
return new UserTagsListGenerator();
}
@Bean
UserPermissionContainersCollectionsListGenerator userPermissionContainersCollectionsListGenerator(){
return new UserPermissionContainersCollectionsListGenerator(userTagsListGenerator());
}
@Bean
UserFunctionalScopeRelationsListGenerator userFunctionalScopeRelationsListGenerator(){
return new UserFunctionalScopeRelationsListGenerator(userPermissionContainersCollectionsListGenerator());
}
@Bean
UserFunctionalPermissionContainersListGenerator userFunctionalPermissionContainersListGenerator(){
return new UserFunctionalPermissionContainersListGenerator(userFunctionalScopeRelationsListGenerator());
}
@Bean
UserRolesListGenerator userRolesListGenerator(){
return new UserRolesListGenerator(userFunctionalPermissionContainersListGenerator());
}
}

View File

@ -1,8 +1,9 @@
package com.codesdream.ase.model.permission;
import com.codesdream.ase.component.UserAuthoritiesGenerator;
import com.codesdream.ase.component.UserRolesListGenerator;
import com.codesdream.ase.model.activity.UserActivity;
import com.codesdream.ase.service.UserService;
import com.codesdream.ase.service.IUserService;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
@ -10,6 +11,7 @@ import org.springframework.security.core.userdetails.UserDetails;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
@ -19,9 +21,6 @@ import java.util.Set;
@Table(name = "user")
public class User implements UserDetails {
@Resource
private transient UserService userService;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@ -49,6 +48,9 @@ public class User implements UserDetails {
@Column(nullable = false)
private boolean deleted;
// 访问控制角色(不在数据表中) Spring Security
private transient Collection<?extends GrantedAuthority> authorities;
// 用户关联标签
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private Set<Tag> tags;
@ -90,11 +92,7 @@ public class User implements UserDetails {
this.tags = new HashSet<>();
this.userDetail = new UserDetail();
this.userAuth = new UserAuth();
}
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return userService.getUserAuthorities(this);
this.authorities = new ArrayList<>();
}
}

View File

@ -1,5 +1,6 @@
package com.codesdream.ase.service;
import com.codesdream.ase.component.UserAuthoritiesGenerator;
import com.codesdream.ase.model.permission.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
@ -14,7 +15,10 @@ import java.util.Optional;
public class ASEUserDetailsService implements UserDetailsService {
@Resource
UserService userService;
IUserService userService;
@Resource
UserAuthoritiesGenerator userAuthoritiesGenerator;
@Override
@Transactional
@ -27,6 +31,7 @@ public class ASEUserDetailsService implements UserDetailsService {
else {
System.out.println("Returning user information");
System.out.println("User Password: "+user.get().getPassword());
user.get().setAuthorities(userAuthoritiesGenerator.grantedAuthorities(user.get()));
return user.get();
}
}