2012-06-18 5 views
4

독립 실행 형 응용 프로그램에서 스프링 보안을 사용하는 방법은 무엇입니까? 스프링 보안의 인증 부분 만 사용하면됩니다. Windows Active Directory에 대해 사용자를 인증해야합니다. Servlets에서 스프링 보안을 사용하는 웹에는 많은 예제가 있지만 독립 실행 형 응용 프로그램에서 스프링 보안을 많이 사용할 수는 없습니다. 나는 단지이 방법을독립 실행 형 응용 프로그램의 스프링 보안

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

답변

1

를 완료하기 위해 뭔가를 찾고 있어요

방금 ​​인증을 수행해야하는 경우는 봄 보안 LDAP에서 ActiveDirectoryLdapAuthenticationProvider를 사용할 수 있습니다. 그런 다음

try { 
    adAuthProvider.authenticate(new UsernamePasswordAuthenticationToken("user", "password")); 
} catch (AuthenticationException ae) { 
    // failed 
} 
+0

많은 도움 [pap]을 보내 주셔서 감사합니다. –

0

using-spring-security-in-a-swing-desktop-application

public Authentication authenticate(String username, String password) { 
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password); 

Authentication auth = _authProvider.authenticate(token); 
if (null != auth) { 
    SecurityContextHolder.getContext().setAuthentication(auth); 

    _eventPublisher.publishEvent(new InteractiveAuthenticationSuccessEvent(auth, this.getClass())); 

    return auth; 
} 
throw new BadCredentialsException("null authentication"); 
} 

나 자신에 의해 위의 코드를 시도하지 않은처럼 사용

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

:

그냥 같은 응용 프로그램 컨텍스트에서 빈을 생성 그러나 합리적으로 보인다. 편의상 javadoc에 대한 링크 아래 SecurityContextHolder

관련 문제