2017-03-09 10 views
1

私はSpringブートアプリケーションを作成しています。これはLDAPのユーザだけがアクセス可能でなければなりません。このアプリケーションは、組み込みサーバーではなくTomcatサーバーにデプロイする必要があります。私はTomcatのマネージャーにアクセスしようとすると、私はLDAPの資格情報を使用して認証できるTom BootによるLDAP認証(事前認証)

<Realm className="org.apache.catalina.realm.LockOutRealm"> 
    <Realm className="org.apache.catalina.realm.UserDatabaseRealm" 
     resourceName="UserDatabase"/> 
    <Realm className="org.apache.catalina.realm.JNDIRealm" 
     connectionURL="ldap://someldapserver:389" 
     userPattern="uid={0},dc=example,dc=com" 
     roleBase="dc=example,dc=com" 
     roleName="cn" 
     roleSearch="(uniqueMember={0})"/> 
</Realm> 

ので、接続は基本的に動作します:LDAPのための構成は、Tomcat自体で行われます。

これは私の設定です:

@Configuration 
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER) 
public class SecurityConfiguration extends WebSecurityConfigurerAdapter { 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http 
      .authorizeRequests() 
       .antMatchers("/test").permitAll() 
       .anyRequest().authenticated() 
       .and() 
      .formLogin().permitAll() 
       .and() 
      .logout().permitAll() 
       .and() 
      .csrf().disable(); 
    } 
} 

私はアプリケーション(authenticationManagerBuilder.ldapAuthentication()...)で直接LDAP接続を設定することも可能だろうが、これは私が欲しいものではありません。

アプリケーションでTomcatのLDAP認証を使用するようにSpring Bootに指示するにはどうすればよいですか?

UPDATE

私はPre-Authenticationを有効にしているように見えます。これは.and().jee().mappableRoles("ROLE_ADMIN")で行うことができます。これはうまくいくようですが、私はまだ認証できません:No pre-authenticated principal found in request

Tomcatの設定に何か追加する必要がありますか?

答えて

1

私はSpring Securityを完全に削除し、制約をweb.xmlに追加しました。 context.xmlでは、認証方法を設定することができます(たとえば、tomcat-users.xml認証に切り替える場合は、下記の例を参照してください)。 Tomcat上の認証が機能します。

のweb.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app> 
    <security-constraint> 
     <web-resource-collection> 
      <web-resource-name>Authentication</web-resource-name> 
      <url-pattern>/test/test</url-pattern> 
     </web-resource-collection> 
     <auth-constraint> 
      <role-name>users</role-name> 
     </auth-constraint> 
    </security-constraint> 
    <login-config> 
     <auth-method>BASIC</auth-method> 
    </login-config> 
    <security-role> 
     <role-name>users</role-name> 
    </security-role> 
</web-app> 

のcontext.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<Context> 
    <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> 
</Context>