0

私は春の技術の学習の一部である単純な webapp を構築します。

language 、 currency などの多くのユーザー属性への参照を保持する、ある種のカスタム ユーザー セッションを作成することを考えていました。

春にこれを達成するにはどうすればよいですか?または、すでに存在するものがありますか?

4

1 に答える 1

0

カスタムを書いてカスタム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);
    }
}
于 2013-02-11T11:51:22.700 に答える