4

スタンドアロン アプリケーションで Spring Security を使用するにはどうすればよいですか。Spring Security の認証部分を使用するだけです。Windows Active Directory に対してユーザーを認証する必要があります。サーブレットでスプリング セキュリティを使用する例は Web にたくさんありますが、スタンドアロン アプリケーションでそれらを使用する例はあまり見つかりませんでした。

このメソッドを完了するための何かを探しているだけです

boolean isValidCredentials(String username, String password)
{
    //TODO use spring security for authentication here..
}
4

2 に答える 2

3

You can use the ActiveDirectoryLdapAuthenticationProvider from spring-security-ldap if you just need to do authentication.

Just create a bean in your application context like:

<bean id="adAuthProvider" class="org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider">
    <constructor-arg value="your.domain" />
    <constructor-arg value="ldap://your.ad.server" />
</bean>

Then use it like

try {
    adAuthProvider.authenticate(new UsernamePasswordAuthenticationToken("user", "password"));
} catch (AuthenticationException ae) {
    // failed
}
于 2012-06-18T14:36:23.720 に答える