私は春の技術の学習の一部である単純な webapp を構築します。
language 、 currency などの多くのユーザー属性への参照を保持する、ある種のカスタム ユーザー セッションを作成することを考えていました。
春にこれを達成するにはどうすればよいですか?または、すでに存在するものがありますか?
カスタムを書いてカスタム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);
}
}