0

LDAPに対して春の認証を使用しています。指定されたユーザー ID とパスワードが LDAP に存在する場合、ユーザー ログインを取得できました。LDAP のユーザーの memberOf 属性に基づいてこれを制限したいと思います。ユーザーが特定の CN 値 (CN=adminaccess または CN=superadminaccess) を持つ memberOf 属性を持っている場合、認証/承認はパスする必要があります。それ以外の場合、認証/承認は失敗するはずです。

<security:http auto-config="true" use-expressions="true" access-denied-page="/admin/auth/denied">
    <security:intercept-url pattern="/admin/auth/login" access="permitAll" />
    <security:intercept-url pattern="/admin/dashboard/*" access="hasAnyRole('ROLE_ADMINACCESS','ROLE_SUPERADMINACCESS')"/>
</security:http>

<security:authentication-manager>   
  <security:ldap-authentication-provider   user-dn-pattern="CN={0},CN=Users" group-search-base="CN=adminaccess,CN=Users" />  
</security:authentication-manager>

<bean id="ldapContext"
        class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
    <constructor-arg value="ldap://xxx.ds.yyy.com:389/DC=xxx,DC=ds,DC=yyy,DC=com"/>
    <property name="userDn" value="CN=aaa,CN=Users,DC=xxx,DC=ds,DC=yyy,DC=com"/>
    <property name="password" value="thepassword"/>
</bean>

上記の構成では、常にアクセス拒否ページにアクセスします。access="hasAnyRole('ROLE_ADMINACCESS','ROLE_SUPERADMINACCESS')" を security:intercept-url から削除すると、たとえユーザーが adminaccess (これは私のグループ -search-base が CN=adminaccess を指定していたので、制限されることを望んでいました)。構成がどうあるべきか疑問に思っています:

  1. memberOf CN=adminaccess および/または CN=superadminaccess であるユーザーだけにアクセスを制限するには
  2. 正しいグループ検索ベースを指定してください。CN=Users のみを指定すると、会社の LDAP に違反するため、タイムアウトが発生します。LDAP ブラウザーでユーザーを調べたところ、役立つ "ou" が見つかりませんでした。上記の構成 group-search-base="CN=adminaccess,CN=Users" では、タイムアウトは発生しませんが、正しいとは思いません
4

1 に答える 1

1

Not sure if there is a better way, but I was able to successfully get this working using DefaultLdapAuthoritiesPopulator and updating to the below configuration:

<security:http auto-config="true" use-expressions="true" access-denied-page="/admin/auth/denied">
<security:intercept-url pattern="/admin/auth/login" access="permitAll" />
<security:intercept-url pattern="/admin/dashboard/*" access="hasAnyRole('ROLE_ADMINACCESS','ROLE_SUPERADMINACCESS')"/>
</security:http>

<security:authentication-manager>
    <security:authentication-provider
        ref="ldapAuthProvider"></security:authentication-provider>
</security:authentication-manager>

<bean id="ldapContext"
    class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
 <constructor-arg value="ldap://xxx.ds.yyy.com:389/DC=xxx,DC=ds,DC=yyy,DC=com"/>
 <property name="userDn" value="CN=aaa,CN=Users,DC=xxx,DC=ds,DC=yyy,DC=com"/>
 <property name="password" value="thepassword"/>
</bean>

<bean id="ldapAuthProvider"
     class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
    <constructor-arg>
        <bean
            class="org.springframework.security.ldap.authentication.BindAuthenticator">
            <constructor-arg ref="ldapContext" />
            <property name="userDnPatterns">
                <list>
                    <value>CN={0},CN=Users</value>
                </list>
            </property>
        </bean>
    </constructor-arg>
    <constructor-arg>
        <bean
            class="org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator">
            <constructor-arg ref="ldapContext" />
            <constructor-arg value="CN=Users" />
            <property name="groupRoleAttribute" value="CN" />
        </bean>
    </constructor-arg>
</bean>

With this configuration, if the login username/password provided is correct, all the groups that the user is "memberOf" (pattern CN=Users,DC=xxx,DC=ds,DC=yyy,DC=com), get loaded as his "roles" (prefixed with ROLE_) and I'm able to manage access to these roles using security:intercept-url

于 2014-01-14T01:03:59.220 に答える