Как создать пользовательское исключение с помощью службы Spring Boot SOAP для базовой аутентификации LDAP и отправить его в виде XML - PullRequest
0 голосов
/ 05 июня 2019

Я пытаюсь выполнить базовую аутентификацию с использованием LDAP в сервисе Spring Boot SOAP с SOAP UI Tool и не смог найти способ отправить пользовательский код и сообщение в виде XML-ответа.

@Override
protected void configure(HttpSecurity http) throws Exception {

    http.authorizeRequests().anyRequest().fullyAuthenticated().and().csrf().disable().httpBasic();
}
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {

    auth.ldapAuthentication().userDnPatterns("cn={0}").contextSource(contextSource());

    auth.inMemoryAuthentication().withUser(env.getProperty("spring.ldap.username"))
            .password(env.getProperty("spring.ldap.password")).roles("USER");
}

@Bean
public BaseLdapPathContextSource contextSource() {
    LdapContextSource contextSource = new LdapContextSource();
    contextSource.setAnonymousReadOnly(false);
    contextSource.setBase(env.getProperty("spring.ldap.base"));
    contextSource.setUserDn(env.getProperty("spring.ldap.username"));
    contextSource.setPassword(env.getProperty("spring.ldap.password"));
    contextSource.setUrl(env.getProperty("spring.ldap.urls"));
    return contextSource;
}


public boolean authenticate(String userDn, String credentials) {
    LdapContextSource contextSource = new LdapContextSource();
      DirContext ctx = null;
      String uDn=env.getProperty("spring.ldap.username");
      String credential= env.getProperty("spring.ldap.password");
      try {
        ctx = contextSource.getContext(uDn, credential);
        ctx.lookup(uDn);
        return true;
      } catch (Exception e) {
        // Context creation failed - authentication did not succeed
        e.printStackTrace();
        return false;
      } finally {
        // It is imperative that the created DirContext instance is always closed
        LdapUtils.closeContext(ctx);
      }
    }
}

2019-06-05 12: 07: 20,858 ИНФОРМАЦИЯ org.springframework.web.servlet.DispatcherServlet Инициализация сервлета dispatcherServlet 2019-06-05 12: 07: 20,871 ИНФОРМАЦИЯ org.springframework.web.servlet.DispatcherServlet Завершена инициализация за 13 мс

...