<legend id='b6NUx'><style id='b6NUx'><dir id='b6NUx'><q id='b6NUx'></q></dir></style></legend>

    1. <i id='b6NUx'><tr id='b6NUx'><dt id='b6NUx'><q id='b6NUx'><span id='b6NUx'><b id='b6NUx'><form id='b6NUx'><ins id='b6NUx'></ins><ul id='b6NUx'></ul><sub id='b6NUx'></sub></form><legend id='b6NUx'></legend><bdo id='b6NUx'><pre id='b6NUx'><center id='b6NUx'></center></pre></bdo></b><th id='b6NUx'></th></span></q></dt></tr></i><div id='b6NUx'><tfoot id='b6NUx'></tfoot><dl id='b6NUx'><fieldset id='b6NUx'></fieldset></dl></div>

      1. <tfoot id='b6NUx'></tfoot>
          <bdo id='b6NUx'></bdo><ul id='b6NUx'></ul>

        <small id='b6NUx'></small><noframes id='b6NUx'>

        如何将 AD 组映射到用户角色 Spring Security LDAP

        时间:2024-05-10
      2. <tfoot id='bMVbH'></tfoot>
        <i id='bMVbH'><tr id='bMVbH'><dt id='bMVbH'><q id='bMVbH'><span id='bMVbH'><b id='bMVbH'><form id='bMVbH'><ins id='bMVbH'></ins><ul id='bMVbH'></ul><sub id='bMVbH'></sub></form><legend id='bMVbH'></legend><bdo id='bMVbH'><pre id='bMVbH'><center id='bMVbH'></center></pre></bdo></b><th id='bMVbH'></th></span></q></dt></tr></i><div id='bMVbH'><tfoot id='bMVbH'></tfoot><dl id='bMVbH'><fieldset id='bMVbH'></fieldset></dl></div>

        1. <legend id='bMVbH'><style id='bMVbH'><dir id='bMVbH'><q id='bMVbH'></q></dir></style></legend>

              <tbody id='bMVbH'></tbody>

                <small id='bMVbH'></small><noframes id='bMVbH'>

                  <bdo id='bMVbH'></bdo><ul id='bMVbH'></ul>
                  本文介绍了如何将 AD 组映射到用户角色 Spring Security LDAP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个使用 Java Spring MVC 构建的 Web 应用程序.

                  I have a web application built using Java Spring MVC.

                  我只是设置连接到 LDAP 服务器进行身份验证的 Spring Security.

                  I'm just setting up spring security connecting to an LDAP server for authentication.

                  我已成功设置,以便能够登录到我的应用程序,但我找不到任何可以帮助我将 AD 组映射到 Java 中的用户角色的东西,因为我只能获得 403 禁止页面即我已经通过身份验证但还没有权限.

                  I've successfully set it up so that I am able to login to my application but I can't find anything to help me in mapping an AD group to a user role within Java as I can only get a 403 forbidden page i.e. I've been authenticated but don't have permissions yet.

                  我目前有:

                  <http auto-config="true">
                      <intercept-url pattern="/**" access="ROLE_USER" />      
                  </http>
                  
                  <ldap-server id="ldapServer" url="LDAPURL" manager-dn="USER" manager-password="PASSWORD"  />
                  
                  <authentication-manager > 
                      <ldap-authentication-provider           
                          group-search-base="OU=GROUPS"
                          group-search-filter="sAMAccountName={0}"
                  
                          user-search-base="OU=USERS"
                          user-search-filter="sAMAccountName={0}" 
                  
                          />
                  </authentication-manager>
                  

                  假设该用户是 AD 组 g-group-UK-user 的一部分,然后我希望能够将该 AD 组映射到 ROLE_USER 以便用户可以看到整个网络应用程序.

                  Say that user was a part of the AD group g-group-UK-user I then want to be able to map that AD group to ROLE_USER so that user can then see the whole web app.

                  我似乎只能找到组是 ADMIN 或 USER 的非常简单的示例,在这种情况下前缀 ROLE 只是添加到组中,或者其他方法似乎正在使用 UserDetailContextMapper 但我找不到明确的用途这个.

                  I can only seem to find very simple examples where the groups are either ADMIN or USER in which case the prefix ROLE is just added to the group or the other method seems to be using UserDetailContextMapper but I can't find a clear use of this.

                  推荐答案

                  为此,我在身份验证管理器中使用了以下内容:

                  To do this I used the following within authentication manager:

                  user-context-mapper-ref="customUserContextMapper"
                  

                  然后我使用以下类来检查该用户是否属于某个 AD 组,然后将 ROLE_USER 角色分配给他们的权限:

                  I then used the following class to check if that user belongs to a certain AD group and then assign the ROLE_USER role to their authorities:

                  @Override
                  public UserDetails mapUserFromContext(DirContextOperations ctx, String username, Collection<? extends GrantedAuthority> authorities) 
                  {
                  
                      Attributes attributes = ctx.getAttributes();
                      Object[] groups = new Object[100];
                      groups = ctx.getObjectAttributes("memberOf");
                  
                      LOGGER.debug("Attributes: {}", attributes);
                  
                      Set<GrantedAuthority> authority = new HashSet<GrantedAuthority>();
                  
                      for(Object group: groups)
                      {
                  
                          if (group.toString().toLowerCase().contains("AD_GROUP_NAME".toLowerCase()) == true)
                          {
                              authority.add(new SimpleGrantedAuthority("ROLE_USER"));
                              break;          
                          }
                      }
                  
                      User userDetails = new User(username, "", false, false, false, false, authority);
                      return userDetails;
                  }
                  

                  请注意,由于我连接的 LDAP 服务器的结构与平常不同,该类比平常稍微复杂一点,因为用户有权访问的组存储在用户下的属性中,而不是另一种方式是,一个组将拥有属于它的所有用户作为属性.

                  Please note that the class is a little more complicated than usual because of the LDAP server I was connecting which has a different structure than usual in that the groups a user has access to are stored in an attribute under the user and not the other way round in which a group would have as an attribute all the users that belong to it.

                  这篇关于如何将 AD 组映射到用户角色 Spring Security LDAP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使用 Spring Security 对 Active Directory 服务器进行身份验证? 下一篇:Java、LDAP:让它不忽略空白密码?

                  相关文章

                  <small id='LsXQZ'></small><noframes id='LsXQZ'>

                    <legend id='LsXQZ'><style id='LsXQZ'><dir id='LsXQZ'><q id='LsXQZ'></q></dir></style></legend>
                      <tfoot id='LsXQZ'></tfoot>
                        <bdo id='LsXQZ'></bdo><ul id='LsXQZ'></ul>

                    1. <i id='LsXQZ'><tr id='LsXQZ'><dt id='LsXQZ'><q id='LsXQZ'><span id='LsXQZ'><b id='LsXQZ'><form id='LsXQZ'><ins id='LsXQZ'></ins><ul id='LsXQZ'></ul><sub id='LsXQZ'></sub></form><legend id='LsXQZ'></legend><bdo id='LsXQZ'><pre id='LsXQZ'><center id='LsXQZ'></center></pre></bdo></b><th id='LsXQZ'></th></span></q></dt></tr></i><div id='LsXQZ'><tfoot id='LsXQZ'></tfoot><dl id='LsXQZ'><fieldset id='LsXQZ'></fieldset></dl></div>