当前位置: 首页 > 知识库问答 >
问题:

Vaadin和Spring,通过LDAP对活动目录进行身份验证

商棋
2023-03-14

我正在尝试对使用Vaadin创建的应用程序中的AD进行身份验证,该应用程序也使用Spring(SpringVaadinIntegration)。

我找不到任何关于如何实现这一点的信息,也找不到许多令人困惑的、不同的和部分的用Spring security连接到Active Directory的方法。由于Vaadin表单字段没有名称,我甚至不知道我是否可以使用普通的表单,或者我必须编写自己的JSP。我的印象是,要将表单中输入的用户名和密码映射到xml,字段必须有名称。

有没有人做到了这一点,或者有人知道如何做到这一点?

如果有人可以提供一步一步解释的链接,对于傻瓜来说,这也很棒。我只能找到部分解决方案,您无法获得系统的整体以及应该如何配置。

共有2个答案

卢英范
2023-03-14

即使这个问题已经得到了回答,我想向你展示我的解决方案。

我们使用 Spring 安全性进行 LDAP 身份验证,因此我们有以下两个配置类:

@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true, proxyTargetClass = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter
{
    @Override
    protected void configure(HttpSecurity http) throws Exception
    {
        // @formatter:off
        http
            .authorizeRequests()
                .anyRequest().authenticated() // Alle Requests erfordern einen Login...
                .and()
            .formLogin().loginPage("/login").defaultSuccessUrl("/#!").permitAll() // http://docs.spring.io/spring-security/site/docs/4.0.3.RELEASE/reference/htmlsingle/#jc-form
                .and()
            .logout().permitAll() // http://docs.spring.io/spring-security/site/docs/4.0.3.RELEASE/reference/htmlsingle/#jc-logout
                .and()
            .csrf().disable(); // CSRF (https://docs.spring.io/spring-security/site/docs/current/reference/html/csrf.html) wird von Vaadin selbst gehandhabt!
        // @formatter:on
    }

    /**
     * @see http://stackoverflow.com/questions/34944617/java-config-for-spring-security-with-vaadin/35212403#35212403
     */
    @Override
    public void configure(WebSecurity web) throws Exception
    {
        // @formatter:off
        web
            .ignoring()
                .antMatchers("/resources/**", "/VAADIN/**");
        // @formatter:on
    }
}

@Configuration
public class SecurityConfigActiveDirectory
{
    @Value("${ldap.url}")
    String ldapUrl;

    @Value("${ldap.domain}")
    String ldapDomain;

    @Bean
    public AuthenticationManager authenticationManager()
    {
        ActiveDirectoryLdapAuthenticationProvider adProvider = new ActiveDirectoryLdapAuthenticationProvider(ldapDomain, ldapUrl);
        adProvider.setConvertSubErrorCodesToExceptions(true);
        adProvider.setUseAuthenticationRequestCredentials(true);
        adProvider.setAuthoritiesMapper(getAuthorityMapper());
        return new ProviderManager(Arrays.asList(adProvider));
    }

    private static SimpleAuthorityMapper getAuthorityMapper()
    {
        SimpleAuthorityMapper mapper = new SimpleAuthorityMapper();
        mapper.setConvertToUpperCase(true);
        return mapper;
    }
}

SecurityConfig 类定义了哪些页面应该在我们的 Web 应用程序中受到保护,SecurityConfigActiveDirectory 定义了 LDAP 身份验证提供程序。

< code>ldap.domain可能类似于private.myTest.de,而< code>ldap.url可能类似于LDAP://myldaphost . private . mytest . de:389。

干杯!

安奇
2023-03-14

我们在< code>UI上有一个< code>TextField(用户名)、一个< code>PasswordField(密码)和一个< code >按钮:

public class MyUI extends UI {
    @Override
    protected void init( VaadinRequest request ) {
        setContent( VaadinSession.getCurrent().getAttribute("userId") == null ? getNewLoginLayout() : getNewMainLayout() );
    }
    private VerticalLayout getNewLoginLayout() {
        TextField username = ...
        TextField password = ...
        Button login = ...
        return new VerticalLayout(username, password, login);
    }
}

按下按钮后,我们在服务器端执行类似这样的简单LDAP搜索(例如,将这些参数传递给Springbean)。如果成功,我们将设置一个VaadinSession属性(userId),并将UI内容更改为主布局。Spring安全不一定需要。

 类似资料:
  • 问题内容: 如何使用Python + LDAP针对AD进行身份验证。我目前正在使用python-ldap库,它所产生的只是眼泪。 我什至不能绑定执行简单的查询: 运行此命令会给我两个错误之一: -输入错误或故意使用错误的凭据时,它无法通过身份验证。 ldap.INVALID_CREDENTIALS:{‘info’:‘80090308:LdapErr:DSID-0C090334,评论:AcceptS

  • 嗨,我正在进行Spring Boot,我正在尝试使用Spring Security性来从active Directory进行用户身份验证。但是我无法将用户登录到应用程序中,我已经尝试了几个东西,下面是我尝试的代码: 当我试图从administrator登录时,我得到的错误如下: 原因:LDAP处理过程中出现未分类异常;嵌套异常是javax.naming.namingException:[LDAP:

  • 问题: 我们有一个spring的基于MVC的RESTful API,它包含敏感信息。API应该是安全的,但是不希望在每个请求中发送用户的凭据(User/Pass组合)。根据REST指南(和内部业务需求),服务器必须保持无状态。API将由另一台服务器以混搭方式使用。 要求: > 客户端请求使用凭据(不受保护的URL);服务器返回一个安全令牌,该令牌包含足够的信息,供服务器验证未来的请求并保持无状态。

  • 在我配置了下面的配置之后,它不会连接到Active Directory。我无法使用Active Directory的帐户登录。会有什么问题? 我有一个Ubuntu服务器18.04,带有ApacheGuacamoleV1。0.0. 安装。我想使用LDAP身份验证来验证用户。我已经下载了鳄梨酱-auth-ldap-1.0.0。jar和jldap-4.3。jar扩展。 10.10.10.21,10.10

  • 我无法使用真正的active directory进行身份验证,让我更好地解释一下,我尝试使用spring提出的示例进行身份验证。io无问题—内部服务启动时没有任何问题。参考https://spring.io/guides/gs/authenticating-ldap/ 我试图通过插入active directory的配置来修改下面的代码,但没有成功。你能不能给我一个真实的例子,让我看看在不使用内部

  • 我有一个工作的概念验证应用程序,它可以通过测试服务器上的LDAP成功地对Active Directory进行身份验证,但是生产应用程序必须通过TLS进行身份验证--域控制器关闭任何不通过TLS发起的连接。 ldap.xml: 是一个重写类,它扩展了Spring的类的副本,该类出于某种原因被指定为。我要重写的原因与自定义在用户对象上填充权限/权限的方式有关(我们要么使用相关组的组成员身份来构建用户的

  • 问题内容: 我有一个有效的概念验证应用程序,可以通过测试服务器上的LDAP通过Active Directory进行成功的身份验证,但是生产应用程序必须通过TLS进行身份验证-域控制器会关闭所有未通过TLS发起的连接。 我已经在Eclipse中安装了LDAP浏览器,并且确实可以在 其中 使用TLS进行绑定,但是我一生都无法弄清楚如何让我的应用程序使用TLS。 ldap.xml : 是重写类,它扩展了

  • 我有一个react应用程序在一个单独的端口(localhost:3000)上运行,我想用它来验证用户,目前我的Spring后端(localhost:8080)有一个代理设置。 我能以某种方式手动验证而不是通过发送一个请求到我的后端,并获得一个会话cookie,然后在每个请求中包含cookie吗?这也将简化iOS方面的验证过程(使用此过程,我只能将会话cookie值存储在keychain中,并在每次