簡體   English   中英

Jetty - JAAS和Active Directory - 僅限身份驗證?

[英]Jetty - JAAS and Active Directory - Authentication Only?

我正在開發一個非常簡單的Java應用程序,需要使用用戶名和密碼進行保護。 我必須使用Active Directory進行身份驗證。 我只能允許經過身份驗證的用戶訪問它。 我不需要任何類型的組/角色檢查來確定用戶可能看到的內容。 我正在使用JETTY來運行該應用程序。

我一直在嘗試用Jetty實現LDAP登錄模塊已經有一段時間了。 但每次我提交登錄表單時,我都會收到403錯誤的“!role”消息。

HTTP ERROR 403

Problem accessing /JAAS/. Reason:

    !role

提交登錄表單時Jetty標准輸出:

2013-07-18 19:28:47.035:INFO:oejpjs.LdapLoginModule:Searching for users with filter: '(&(objectClass={0})({1}={2}))' from base dn: DC=mydomain,DC=test,DC=local
2013-07-18 19:28:47.041:INFO:oejpjs.LdapLoginModule:Found user?: true
2013-07-18 19:28:47.042:INFO:oejpjs.LdapLoginModule:Attempting authentication: CN=User Name,OU=ADMIN_HOME,DC=mydomain,DC=test,DC=local

我提交登錄表單時的Jetty日志文件(我輸入的用戶名出現在日志中,因此部分驗證似乎有效):

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和security-roke的web.xml的摘錄:

<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";
   };

Jetty領域配置(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>

最后,jetty啟動命令:

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

我檢查了Windows安全事件日志,我確實看到了一個成功的審核條目,用於登錄表單中提供的用戶登錄。

問題是,我不需要任何角色。 我只想執行身份驗證並允許所有經過身份驗證的用戶訪問該應用程序。

知道如何才能進行身份驗證並避免角色嗎? 我正在考慮覆蓋LdapLoginModule類並強制我將在web.xml中聲明的“虛擬”角色。 但我不確定這是否是正確的方法。

您的身份驗證成功。

由於您希望允許所有經過身份驗證的用戶訪問所有內容,因此您仍需要保護URL模式/ *。 您可以使用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。

您需要修改web.xml以使用特殊角色**,如下所示: Jetty身份驗證的授權部分

無論角色如何,都授予任何經過身份驗證的用戶訪問權限。 這由<security-constraint>中<auth-constraint>的<role-name>的特殊值“**”表示。

所以,這就是我的安全約束的樣子:

<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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM