2013-07-18 27 views
5

我正在研究一个非常简单的Java应用程序,需要使用用户名和密码进行保护。我必须使用Active Directory进行身份验证。我只能允许经过身份验证的用户访问它。我不需要任何种类的组/角色检查来确定用户可以看到或不看。我正在使用JETTY来运行应用程序。Jetty - JAAS和活动目录 - 只有身份验证?

我一直在尝试相当一段时间来实现与Jetty的LDAP登录模块。但每次提交登录表单时,我都会收到“!role”消息的403错误。

HTTP ERROR 403 

Problem accessing /JAAS/. Reason: 

    !role 

码头时,我提交登录表单标准输出:

​​

码头日志文件时,我提交登录表单(我在日志中输入出现的用户名,所以认证的一部分,似乎工作):在web.xml的

0:0:0:0:0:0:0:1 - - [18/Jul/2013:17:28:38 +0000] "GET /JAAS/ HTTP/1.1" 302 0 
0:0:0:0:0:0:0:1 - - [18/Jul/2013:17:28:38 +0000] "GET /JAAS/login.html HTTP/1.1" 304 0 
0:0:0:0:0:0:0:1 - - [18/Jul/2013:17:28:47 +0000] "POST /JAAS/j_security_check HTTP/1.1" 302 0 
0:0:0:0:0:0:0:1 - username [18/Jul/2013:17:28:47 +0000] "GET /JAAS/ HTTP/1.1" 403 1362 

提取物那里的安全约束和安全洛克声明:

<security-constraint> 
    <web-resource-collection> 
     <web-resource-name>Entire Application</web-resource-name> 
     <url-pattern>/*</url-pattern> 
    </web-resource-collection> 

    <auth-constraint> 
     <role-name>*</role-name> 
    </auth-constraint> 
    </security-constraint> 

    <security-role> 
     <role-name>*</role-name> 
    </security-role> 

    <security-role> 
     <role-name>Domain Users</role-name> 
    </security-role> 

    <security-role> 
     <role-name>MyLocalGroup</role-name> 
    </security-role> 

LDAP登录模块配置文件(ldaploginmodule.conf):

myloginmodule { 
    org.eclipse.jetty.plus.jaas.spi.LdapLoginModule required 
    debug="true" 
    debugNative="true" 
    contextFactory="com.sun.jndi.ldap.LdapCtxFactory" 
    hostname="ldapserver" 
    port="389" 
    bindDn="CN=Administrator,CN=Users,DC=mydomain,DC=test,DC=local" 
    bindPassword="secret" 
    directGroupExtraction="true" 
    userGroupAttribute="cn" 
    allRolesMode="authOnly" 
    userFilter="(objectClass=organizationalPerson)" 
    authenticationMethod="simple" 
    forceBindingLogin="true" 
    userBaseDn="DC=mydomain,DC=test,DC=local" 
    userRdnAttribute="cn" 
    userIdAttribute="sAMAccountName" 
    userPasswordAttribute="unicodePwd" 
    userObjectClass="user" 
    roleSearch="(member={0})" 
    roleName="cn" 
    roleSubtree="true" 
    roleBaseDn="CN=Users,DC=mydomain,DC=test,DC=local"; 
    }; 

码头领域配置(MY-jaas.xml):

<Configure id="Server" class="org.eclipse.jetty.server.Server"> 

    <!-- JAAS TEST --> 
    <Call name="addBean"> 
     <Arg> 
      <New class="org.eclipse.jetty.plus.jaas.JAASLoginService"> 
      <Set name="Name">Test JAAS Realm</Set> 
      <Set name="LoginModuleName">myloginmodule</Set> 

      <Set name="roleClassNames"> 
       <Array type="java.lang.String"> 
        <Item>org.eclipse.jetty.plus.jaas.JAASRole</Item> 
       </Array> 
      </Set> 

      </New> 
     </Arg> 
    </Call> 

</Configure> 

最后,码头启动命令:

java -Xdebug -Djava.naming.referral=follow -Djava.security.auth.login.config=etc/ldaploginmodule.conf -jar start.jar etc/my-jaas.xml 

我检查了Windows安全事件日志,并且确实看到登录成功的审核条目r我在登录表单中提供的用户。

事情是,我不需要任何角色。我只想执行身份验证并允许所有经过身份验证的用户访问应用程序。

任何想法如何我只能进行身份验证,并避免角色?我正在考虑重写LdapLoginModule类并强制一个我将在web.xml中声明的“虚拟”角色。但我不确定这是否是正确的做法。

回答

0

您的验证成功。

由于您希望允许所有经过身份验证的用户访问所有内容,因此您仍然需要保护网址格式/ *。您可以使用RegExpAuthorizationFilter(请参阅https://wiki.apache.org/solr/SolrSecurity)。现在,他们不包括这个类的定期分布。我在这里找到了代码(https://issues.apache.org/jira/secure/attachment/12572819/SOLR-4470_branch_4x_r1454444.patch),它很容易编译。

当您配置过滤器时,请指定一个任意角色(不存在,如/ abcde)的URL模式。它的工作方式是,它会查看请求的URL是否与此模式匹配。既然没有,它就会前进。但是没有更多的规则,并且允许访问。

因此,它需要对所有URL进行身份验证,但所有有效的URL在验证成功后都可以访问。

我的设置是在Jetty上运行solr的上下文中进行的。但是,我认为我的所有配置都与web.xml等标准内容绑定。

0

您需要修改web.xml中使用的特殊作用**如下所示:Authorization section for Jetty Authentication:授予谁被验证,不管角色的任何用户

访问。这是通过特殊的值表示“**”为<角色名在<安全约束>

所以一个< AUTH-约束>的>,这就是我的安全约束的样子:

<security-constraint> 
    <web-resource-collection> 
    <web-resource-name>Secured Solr Admin User Interface</web-resource-name> 
    <url-pattern>/*</url-pattern> 
    </web-resource-collection> 
    <auth-constraint> 
    <role-name>**</role-name> 
    </auth-constraint> 
</security-constraint>