2

我正在使用 Spring 5 Web 应用程序。

我对 Waffle 完全陌生,我想使用 waffle 让用户使用他们的 Windows 凭据在我的 Web 应用程序上进行身份验证。获得用户名后,我将进行 LDAP 搜索。

但我不确定我可以在哪里编写自定义代码来获取用户名进行验证?

我尝试使用弹簧安全 LDAP。但无法获取窗口用户登录名。网上有人建议使用 waffle 来获取窗口用户信息

WebSecurityConfig 代码

 @Autowired
public WindowsAuthenticationProvider windowsAuthenticationProvider;

@Autowired
private NegotiateSecurityFilter securityFilter;

@Autowired
private NegotiateSecurityFilterEntryPoint authenticationEntryPoint;


@Override
protected void configure(final HttpSecurity http) throws Exception {
    http
        .authorizeRequests()
            .anyRequest().authenticated()
        .and()
            .addFilterBefore(this.securityFilter, BasicAuthenticationFilter.class)
            .httpBasic()
            .authenticationEntryPoint(this.authenticationEntryPoint)
        .and()
            .authenticationProvider(windowsAuthenticationProvider) // Set authentication provider here
            .formLogin();
            //.authenticationDetailsSource(waffleAuthenticationDetailsSource);

}

//Waffle Spring Security Beans
@Bean
public WindowsAuthProviderImpl windowsAuthProvider() {
    WindowsAuthProviderImpl waffle = new WindowsAuthProviderImpl();
    return waffle;
}
@Bean
@Autowired
public NegotiateSecurityFilterProvider negotiateSecurityFilterProvider(final WindowsAuthProviderImpl windowsAuthProvider) {

    return new NegotiateSecurityFilterProvider(windowsAuthProvider);
}
@Bean
@Autowired
public SecurityFilterProviderCollection waffleSecurityFilterProviderCollection(final NegotiateSecurityFilterProvider negotiateSecurityFilterProvider) {

    final List<SecurityFilterProvider> securityFilterProviders = new ArrayList<SecurityFilterProvider>();
    securityFilterProviders.add(negotiateSecurityFilterProvider);
    return new SecurityFilterProviderCollection(securityFilterProviders.toArray(new SecurityFilterProvider[]{}));
}
@Bean
@Autowired
public NegotiateSecurityFilterEntryPoint negotiateSecurityFilterEntryPoint(final SecurityFilterProviderCollection securityFilterProviderCollection) {
    final NegotiateSecurityFilterEntryPoint negotiateSecurityFilterEntryPoint = new NegotiateSecurityFilterEntryPoint();
    negotiateSecurityFilterEntryPoint.setProvider(securityFilterProviderCollection);
    return negotiateSecurityFilterEntryPoint;
}
@Bean
@Autowired
public NegotiateSecurityFilter waffleNegotiateSecurityFilter(final SecurityFilterProviderCollection securityFilterProviderCollection) {
    final NegotiateSecurityFilter negotiateSecurityFilter = new NegotiateSecurityFilter();
    negotiateSecurityFilter.setProvider(securityFilterProviderCollection);
    return negotiateSecurityFilter;
}

@Bean
@Autowired
public WindowsAuthenticationProvider windowsAuthenticationProvider(final WindowsAuthProviderImpl windowsAuthProvider) {

    WindowsAuthenticationProvider provider = new WindowsAuthenticationProvider();

    provider.setAuthProvider(windowsAuthProvider);
    return provider;
}

xml

<http use-expressions="true">
    <intercept-url pattern="/**" access="isAuthenticated()" />
    <custom-filter ref="waffleNegotiateSecurityFilter" position="BASIC_AUTH_FILTER" />
    <http-basic />
</http>

<beans:bean id="waffleNegotiateSecurityFilter" class="waffle.spring.NegotiateSecurityFilter">
    <beans:property name="Provider" ref="waffleSecurityFilterProviderCollection" />
</beans:bean>

<authentication-manager>
    <authentication-provider ref="customAuthenticationProvider" />
</authentication-manager>

<beans:bean id="customAuthenticationProvider" class="sunrise.crm.webapp.common.security.CustomAuthenticationProvider">
    <!-- <beans:property name="userDetailsService" ref="userDetailsService" /> -->
</beans:bean>

<beans:bean id="waffleWindowsAuthProvider" class="waffle.windows.auth.impl.WindowsAuthProviderImpl" />

<beans:bean id="negotiateSecurityFilterProvider" class="waffle.servlet.spi.NegotiateSecurityFilterProvider">
    <beans:constructor-arg ref="waffleWindowsAuthProvider" />
</beans:bean>

<beans:bean id="basicSecurityFilterProvider" class="waffle.servlet.spi.BasicSecurityFilterProvider">
    <beans:constructor-arg ref="waffleWindowsAuthProvider" />
</beans:bean>

<beans:bean id="waffleSecurityFilterProviderCollection" class="waffle.servlet.spi.SecurityFilterProviderCollection">
    <beans:constructor-arg>
        <beans:list>
            <beans:ref bean="negotiateSecurityFilterProvider" />               
            <beans:ref bean="basicSecurityFilterProvider" />               
        </beans:list>
    </beans:constructor-arg>
</beans:bean>
4

0 回答 0