0
我構建了一個簡單的webapp,它是我學習彈簧技術的一部分。如何使用spring創建自定義用戶會話對象
我正在考慮創建一些自定義用戶會話,該會話持有許多用戶屬性的引用,例如語言,貨幣等等。
我怎樣才能在春天實現這一目標?或者有一些已經存在的東西?
我構建了一個簡單的webapp,它是我學習彈簧技術的一部分。如何使用spring創建自定義用戶會話對象
我正在考慮創建一些自定義用戶會話,該會話持有許多用戶屬性的引用,例如語言,貨幣等等。
我怎樣才能在春天實現這一目標?或者有一些已經存在的東西?
您可以編寫自定義authentication provider
,並通過自定義UserDetailsService
<authentication-manager>
<authentication-provider user-service-ref="customUserService" />
</authentication-manager>
<beans:bean id="customUserService" class="custom.UserServiceImpl">
</beans:bean>
public class UserServiceImpl implements UserDetailsService {
@Override
public UserDetails loadUserByUsername(String username)
throws UsernameNotFoundException {
//Your logic
return new AuthenticatedUser("", "", true, true, true, new HashSet<GrantedAuthority>());
}
}
public class AuthenticatedUser extends
org.springframework.security.core.userdetails.User {
private static final long serialVersionUID = 1L;
// Your additional properties
public AuthenticatedUser(String username, String password,
boolean enabled, boolean accountNonExpired,
boolean credentialsNonExpired,
Collection<? extends GrantedAuthority> authorities)
throws IllegalArgumentException {
super(username, password, enabled, accountNonExpired,
credentialsNonExpired, true, authorities);
}
}