0

让我先说我不熟悉 Spring。我在工作中被投入到一个项目中,并试图尽快启动

考虑到这一点,我正在尝试使用 Jasig 的 CAS 和 LDAP 来实现 spring 安全性。

当我从本地 LDAP 加载此设置时,一切正常。但是,由于我已将其重新定位到公司 LDAP,因此 web 应用程序不再工作。

目前,我可以确认此脚本成功登录到 LDAP 并验证容器的路径,但是在页面加载之前我收到了服务器错误。

代码:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:sec="http://www.springframework.org/schema/security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd" >


<bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
    <!-- The URL of the ldap server, along with the base path that all other ldap path will be relative to -->
    <constructor-arg value="ldaps://141.161.99.74:636/dc=testing,dc=com"/>
    <property name="userDn" value="uid=OdinAdmin,ou=Specials,dc=testing,dc=com" />
    <property name="password" value="testpw" />
</bean>

<bean id="ldapAuthProvider" class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
    <constructor-arg>
    <bean class="org.springframework.security.ldap.authentication.BindAuthenticator">
            <constructor-arg ref="contextSource"/>
            <property name="userSearch" ref="ldapUserSearch"/>
    </bean>
    </constructor-arg>
    <constructor-arg ref="authoritiesPopulator" />                       <!-- Populates authorities in the UserDetails object -->
    <property name="userDetailsContextMapper" ref="userDetailsMapper" /> <!-- Adds OWF groups to the UserDetails object -->
</bean>

<bean id="authoritiesPopulator" class="org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator">
    <constructor-arg ref="contextSource"/>
    <constructor-arg value="ou=OdinRoles,ou=Odin,ou=Apps"/> <!-- search base for determining what roles a user has -->
    <property name="groupRoleAttribute" value="cn"/>
    <!-- the following properties are shown with their default values -->
    <property name="rolePrefix" value="ROLE_"/>
    <property name="convertToUpperCase" value="true"/>
    <property name="searchSubtree" value="true"/>
</bean>

<bean id="ldapUserSearch" class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
    <constructor-arg value="ou=people" /> <!-- search base for finding User records -->
    <constructor-arg value="(uid={0})" /> <!-- filter applied to entities under the search base in order to find a given user.
                                            this default searches for an entity with a matching uid -->
    <constructor-arg ref="contextSource" />
</bean>

<!-- Custom class that goes back to the ldap database to search for OWF group records and also adds
     extra attributes from the user's ldap record to the UserDetails object.
     The class implementation of this will likely need to be changed out for differnt setups -->
<bean id="userDetailsMapper" class="ozone.securitysample.authentication.ldap.OWFUserDetailsContextMapper">
    <constructor-arg ref="contextSource" />
    <constructor-arg value="ou=OdinGroups,ou=Odin,ou=Apps" /> <!-- search base for finding OWF group membership -->
    <constructor-arg value="(uniqueMember={0})" /> <!-- filter that matches only groups that have the given username listed
                                                  as a "member" attribute -->
    <property name="searchSubtree" value="true"/>
</bean>

<bean id="ldapUserService" class="org.springframework.security.ldap.userdetails.LdapUserDetailsService">
    <constructor-arg ref="ldapUserSearch" />
    <constructor-arg ref="authoritiesPopulator" />
    <property name="userDetailsMapper" ref="userDetailsMapper" />
</bean>

</beans>

我的问题是,我是否允许在组和角色搜索的构造函数参数值中包含子容器?在我以前的版本中,所有东西都在同一个容器中。这样我就可以将所有内容都包含在我的 base-dn 中,并在其中引用特定的 OU。IE。代替

我不确定这是否会导致问题,但任何洞察力将不胜感激。谢谢!

4

2 回答 2

0

你能提供你得到的错误到底是什么,哪个部分实际上失败了?那里有相当多的配置,如果我们将其缩小到一个错误左右,它将对我们非常有帮助。

PS:我希望这是一个评论,但很抱歉,由于 SO 的限制,我还不能发表评论。

于 2013-09-26T19:12:16.263 回答
0

这个问题实际上是基于我正在实施的应用程序。它需要特定的角色名称(ROLE_ADMIN、ROLE_USER)才能发挥作用。我必须通过自定义 Java 类将现有角色映射到这 2 个角色。

谢谢您的帮助!

于 2013-10-21T15:22:39.377 回答