TSK-1301: Cleaned up ldap properties in order to allow users to define custom LdapTemplate bean
This commit is contained in:
parent
0367a3deac
commit
ec4d919dd0
|
@ -8,9 +8,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
@ -19,8 +17,6 @@ import pro.taskana.simplehistory.rest.sampledata.SampleDataGenerator;
|
|||
|
||||
/** Example Application showing the implementation of taskana-rest-spring. */
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = "pro.taskana.simplehistory.rest")
|
||||
@Import({TaskHistoryRestConfiguration.class, WebMvcConfig.class})
|
||||
public class ExampleRestApplication {
|
||||
|
||||
@Value("${taskana.schemaName:TASKANA}")
|
||||
|
|
|
@ -10,7 +10,7 @@ import pro.taskana.simplehistory.rest.resource.TaskHistoryEventResourceAssembler
|
|||
|
||||
/** Configuration for Taskana history REST service. */
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = {"pro.taskana", "pro.taskana.simplehistory.rest"})
|
||||
@ComponentScan({"pro.taskana", "pro.taskana.simplehistory.rest"})
|
||||
@EnableTransactionManagement
|
||||
public class TaskHistoryRestConfiguration {
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
@ -21,7 +20,6 @@ import pro.taskana.simplehistory.rest.sampledata.SampleDataGenerator;
|
|||
|
||||
/** Example Application to create the documentation. */
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = "pro.taskana.rest.simplehistory")
|
||||
@Import({TaskHistoryRestConfiguration.class})
|
||||
public class ExampleDocumentationApplication {
|
||||
|
||||
|
|
|
@ -1,49 +1,30 @@
|
|||
package pro.taskana.rest;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
import pro.taskana.RestConfiguration;
|
||||
import pro.taskana.jobs.TransactionalJobsConfiguration;
|
||||
import pro.taskana.sampledata.SampleDataGenerator;
|
||||
|
||||
/** Example Application showing the implementation of taskana-rest-spring. */
|
||||
@SpringBootApplication
|
||||
/** Example Application showing a minimal implementation of the taskana REST service. */
|
||||
@EnableScheduling
|
||||
@ComponentScan(basePackages = "pro.taskana")
|
||||
@SuppressWarnings("checkstyle:Indentation")
|
||||
@Import({
|
||||
ExampleRestConfiguration.class,
|
||||
TransactionalJobsConfiguration.class,
|
||||
RestConfiguration.class,
|
||||
WebMvcConfig.class
|
||||
})
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan("pro.taskana")
|
||||
public class ExampleRestApplication {
|
||||
|
||||
private final SampleDataGenerator sampleDataGenerator;
|
||||
|
||||
@Value("${generateSampleData:true}")
|
||||
public boolean generateSampleData;
|
||||
|
||||
@Autowired
|
||||
public ExampleRestApplication(SampleDataGenerator sampleDataGenerator) {
|
||||
this.sampleDataGenerator = sampleDataGenerator;
|
||||
public ExampleRestApplication(
|
||||
SampleDataGenerator sampleDataGenerator,
|
||||
@Value("${generateSampleData:true}") boolean generateSampleData) {
|
||||
if (generateSampleData) {
|
||||
sampleDataGenerator.generateSampleData();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ExampleRestApplication.class, args);
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
if (generateSampleData) {
|
||||
sampleDataGenerator.generateSampleData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,25 @@
|
|||
package pro.taskana.rest;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import pro.taskana.sampledata.SampleDataGenerator;
|
||||
|
||||
@Configuration
|
||||
public class ExampleRestConfiguration {
|
||||
|
||||
@Value("${taskana.schemaName:TASKANA}")
|
||||
public String schemaName;
|
||||
private final String schemaName;
|
||||
|
||||
@Autowired
|
||||
public ExampleRestConfiguration(@Value("${taskana.schemaName:TASKANA}") String schemaName) {
|
||||
this.schemaName = schemaName;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager txManager(DataSource dataSource) {
|
||||
|
|
|
@ -25,8 +25,6 @@ devMode=false
|
|||
####### property that control if the database is cleaned and sample data is generated
|
||||
generateSampleData=true
|
||||
|
||||
####### control LDAP usage
|
||||
taskana.ldap.useLdap=false
|
||||
####### properties to connect to LDAP
|
||||
taskana.ldap.serverUrl=ldap://localhost:10389
|
||||
taskana.ldap.bindDn=uid=admin,ou=system
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package pro.taskana;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import pro.taskana.sampledata.SampleDataGenerator;
|
||||
|
||||
@SpringBootApplication
|
||||
@DependsOn("getTaskanaEngine") // wait for schema to be created BEFORE inserting test data
|
||||
public class CommonTestConfiguration {
|
||||
|
||||
@Autowired
|
||||
public CommonTestConfiguration(
|
||||
@Value("${taskana.schemaName:TASKANA}") String schemaName, DataSource dataSource) {
|
||||
new SampleDataGenerator(dataSource, schemaName).generateSampleData();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager txManager(DataSource dataSource) {
|
||||
return new DataSourceTransactionManager(dataSource);
|
||||
}
|
||||
}
|
|
@ -22,6 +22,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
|
|||
@ActiveProfiles({"test"})
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(
|
||||
classes = RestConfiguration.class,
|
||||
classes = CommonTestConfiguration.class,
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public @interface TaskanaSpringBootTest {}
|
||||
|
|
|
@ -50,7 +50,7 @@ class AsyncUpdateJobIntTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testUpdateClassificationPrioServiceLevel() throws Exception {
|
||||
void testUpdateClassificationPrioServiceLevel() {
|
||||
|
||||
// 1st step: get old classification :
|
||||
final Instant before = Instant.now();
|
||||
|
|
|
@ -4,23 +4,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import pro.taskana.RestConfiguration;
|
||||
import pro.taskana.TaskanaSpringBootTest;
|
||||
import pro.taskana.common.api.exceptions.InvalidArgumentException;
|
||||
import pro.taskana.common.rest.ldap.LdapClient;
|
||||
import pro.taskana.common.rest.models.AccessIdRepresentationModel;
|
||||
|
||||
/** Test Ldap attachment. */
|
||||
@ActiveProfiles({"test"})
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(
|
||||
classes = RestConfiguration.class,
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@TaskanaSpringBootTest
|
||||
class LdapTest {
|
||||
|
||||
@Autowired private LdapClient ldapClient;
|
||||
|
|
|
@ -1,68 +0,0 @@
|
|||
package pro.taskana.rest;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.sql.DataSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import pro.taskana.RestConfiguration;
|
||||
import pro.taskana.common.rest.ldap.LdapClient;
|
||||
import pro.taskana.common.rest.ldap.LdapConfiguration;
|
||||
import pro.taskana.jobs.TransactionalJobsConfiguration;
|
||||
import pro.taskana.sampledata.SampleDataGenerator;
|
||||
|
||||
/** Example Application showing the implementation of taskana-rest-spring. */
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
@ComponentScan(basePackages = "pro.taskana")
|
||||
@SuppressWarnings("checkstyle:Indentation")
|
||||
@Import({
|
||||
TransactionalJobsConfiguration.class,
|
||||
LdapConfiguration.class,
|
||||
RestConfiguration.class,
|
||||
WebMvcConfig.class
|
||||
})
|
||||
public class ExampleRestApplication {
|
||||
|
||||
@Value("${taskana.schemaName:TASKANA}")
|
||||
public String schemaName;
|
||||
|
||||
@Value("${generateSampleData:true}")
|
||||
public boolean generateSampleData;
|
||||
|
||||
@Autowired private SampleDataGenerator sampleDataGenerator;
|
||||
|
||||
@Autowired private LdapClient ldapClient;
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ExampleRestApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager txManager(DataSource dataSource) {
|
||||
return new DataSourceTransactionManager(dataSource);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@DependsOn("getTaskanaEngine") // generate sample data after schema was inserted
|
||||
public SampleDataGenerator generateSampleData(DataSource dataSource) {
|
||||
sampleDataGenerator = new SampleDataGenerator(dataSource, schemaName);
|
||||
return sampleDataGenerator;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
if (generateSampleData) {
|
||||
sampleDataGenerator.generateSampleData();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,6 +23,7 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
|||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import pro.taskana.common.rest.RestConfiguration;
|
||||
import pro.taskana.common.rest.ldap.LdapClient;
|
||||
import pro.taskana.common.rest.ldap.LdapConfiguration;
|
||||
import pro.taskana.jobs.TransactionalJobsConfiguration;
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
datasource.jndi=java:/TaskanaDS
|
||||
taskana.schemaName=taskana
|
||||
|
||||
####### control LDAP usage
|
||||
taskana.ldap.useLdap=false
|
||||
####### properties to connect to LDAP
|
||||
taskana.ldap.serverUrl=ldap://localhost:10389
|
||||
taskana.ldap.bindDn=uid=admin,ou=system
|
||||
|
|
|
@ -3,8 +3,6 @@ spring.profiles.active=@activatedProperties@
|
|||
datasource.jndi=java:/TaskanaDS
|
||||
taskana.schemaName=TASKANA
|
||||
|
||||
####### control LDAP usage
|
||||
taskana.ldap.useLdap=false
|
||||
####### properties to connect to LDAP
|
||||
taskana.ldap.serverUrl=ldap://localhost:10389
|
||||
taskana.ldap.bindDn=uid=admin,ou=system
|
||||
|
|
|
@ -5,8 +5,6 @@ datasource.jndi=java:jboss/datasources/TestDS
|
|||
taskana.schemaName=taskana
|
||||
|
||||
devMode=true
|
||||
####### control LDAP usage
|
||||
taskana.ldap.useLdap=false
|
||||
####### properties to connect to LDAP
|
||||
taskana.ldap.serverUrl=ldap://localhost:10389
|
||||
taskana.ldap.bindDn=uid=admin,ou=system
|
||||
|
|
|
@ -69,8 +69,17 @@
|
|||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
<groupId>com.unboundid</groupId>
|
||||
<artifactId>unboundid-ldapsdk</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
|
@ -133,10 +142,6 @@
|
|||
<artifactId>h2</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.unboundid</groupId>
|
||||
<artifactId>unboundid-ldapsdk</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -1,75 +0,0 @@
|
|||
package pro.taskana;
|
||||
|
||||
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator;
|
||||
import java.sql.SQLException;
|
||||
import javax.sql.DataSource;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.http.converter.json.SpringHandlerInstantiator;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
import pro.taskana.classification.api.ClassificationService;
|
||||
import pro.taskana.common.api.TaskanaEngine;
|
||||
import pro.taskana.common.rest.ldap.LdapClient;
|
||||
import pro.taskana.monitor.api.MonitorService;
|
||||
import pro.taskana.task.api.TaskService;
|
||||
import pro.taskana.workbasket.api.WorkbasketService;
|
||||
|
||||
/** Configuration for REST service. */
|
||||
@Configuration
|
||||
@ComponentScan
|
||||
@EnableTransactionManagement
|
||||
public class RestConfiguration {
|
||||
|
||||
@Value("${taskana.schemaName:TASKANA}")
|
||||
private String schemaName;
|
||||
|
||||
@Bean
|
||||
public ClassificationService getClassificationService(TaskanaEngine taskanaEngine) {
|
||||
return taskanaEngine.getClassificationService();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TaskService getTaskService(TaskanaEngine taskanaEngine) {
|
||||
return taskanaEngine.getTaskService();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MonitorService getMonitorService(TaskanaEngine taskanaEngine) {
|
||||
return taskanaEngine.getMonitorService();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WorkbasketService getWorkbasketService(TaskanaEngine taskanaEngine) {
|
||||
return taskanaEngine.getWorkbasketService();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
|
||||
public TaskanaEngine getTaskanaEngine(TaskanaEngineConfiguration taskanaEngineConfiguration) {
|
||||
return taskanaEngineConfiguration.buildTaskanaEngine();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
|
||||
public TaskanaEngineConfiguration taskanaEngineConfiguration(DataSource dataSource)
|
||||
throws SQLException {
|
||||
return new SpringTaskanaEngineConfiguration(dataSource, true, true, schemaName);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public LdapClient ldapClient() {
|
||||
return new LdapClient();
|
||||
}
|
||||
|
||||
// Needed for injection into jackson deserializer.
|
||||
@Bean
|
||||
public HandlerInstantiator handlerInstantiator(ApplicationContext context) {
|
||||
return new SpringHandlerInstantiator(context.getAutowireCapableBeanFactory());
|
||||
}
|
||||
}
|
|
@ -1,33 +1,36 @@
|
|||
package pro.taskana;
|
||||
package pro.taskana.common.rest;
|
||||
|
||||
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator;
|
||||
import java.sql.SQLException;
|
||||
import javax.sql.DataSource;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.http.converter.json.SpringHandlerInstantiator;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
import pro.taskana.SpringTaskanaEngineConfiguration;
|
||||
import pro.taskana.TaskanaEngineConfiguration;
|
||||
import pro.taskana.classification.api.ClassificationService;
|
||||
import pro.taskana.common.api.TaskanaEngine;
|
||||
import pro.taskana.common.rest.ldap.LdapClient;
|
||||
import pro.taskana.monitor.api.MonitorService;
|
||||
import pro.taskana.task.api.TaskService;
|
||||
import pro.taskana.workbasket.api.WorkbasketService;
|
||||
|
||||
/** Configuration for REST service. */
|
||||
@Configuration
|
||||
@ComponentScan
|
||||
@ComponentScan("pro.taskana")
|
||||
@EnableTransactionManagement
|
||||
public class RestConfiguration {
|
||||
|
||||
@Value("${taskana.schemaName:TASKANA}")
|
||||
private String schemaName;
|
||||
private final String schemaName;
|
||||
|
||||
public RestConfiguration(@Value("${taskana.schemaName:TASKANA}") String schemaName) {
|
||||
this.schemaName = schemaName;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClassificationService getClassificationService(TaskanaEngine taskanaEngine) {
|
||||
|
@ -50,21 +53,21 @@ public class RestConfiguration {
|
|||
}
|
||||
|
||||
@Bean
|
||||
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
|
||||
public TaskanaEngine getTaskanaEngine(TaskanaEngineConfiguration taskanaEngineConfiguration) {
|
||||
return taskanaEngineConfiguration.buildTaskanaEngine();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
|
||||
@ConditionalOnMissingBean(TaskanaEngineConfiguration.class)
|
||||
public TaskanaEngineConfiguration taskanaEngineConfiguration(DataSource dataSource)
|
||||
throws SQLException {
|
||||
return new SpringTaskanaEngineConfiguration(dataSource, true, true, schemaName);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public LdapClient ldapClient() {
|
||||
return new LdapClient();
|
||||
@ConditionalOnMissingBean(DataSource.class)
|
||||
public DataSource dataSource() {
|
||||
return TaskanaEngineConfiguration.createDefaultDataSource();
|
||||
}
|
||||
|
||||
// Needed for injection into jackson deserializer.
|
|
@ -4,7 +4,6 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.PostConstruct;
|
||||
|
@ -34,26 +33,22 @@ import pro.taskana.common.rest.models.AccessIdRepresentationModel;
|
|||
@Component
|
||||
public class LdapClient {
|
||||
|
||||
static final String MISSING_CONFIGURATION_S =
|
||||
"LdapClient was called but is not active due to missing configuration: %s ";
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(LdapClient.class);
|
||||
|
||||
private static final String CN = "cn";
|
||||
|
||||
private final Environment env;
|
||||
private final LdapTemplate ldapTemplate;
|
||||
private boolean active = false;
|
||||
|
||||
@Autowired private Environment env;
|
||||
|
||||
@Autowired(required = false)
|
||||
private LdapTemplate ldapTemplate;
|
||||
|
||||
private int minSearchForLength;
|
||||
|
||||
private int maxNumberOfReturnedAccessIds;
|
||||
|
||||
private String message;
|
||||
|
||||
@Autowired
|
||||
public LdapClient(Environment env, LdapTemplate ldapTemplate) {
|
||||
this.env = env;
|
||||
this.ldapTemplate = ldapTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search LDAP for matching users or groups.
|
||||
*
|
||||
|
@ -164,7 +159,7 @@ public class LdapClient {
|
|||
getGroupSearchBase(),
|
||||
andFilter.encode(),
|
||||
SearchControls.SUBTREE_SCOPE,
|
||||
getLookUpGoupAttributesToReturn(),
|
||||
getLookUpGroupAttributesToReturn(),
|
||||
new GroupContextMapper());
|
||||
LOGGER.debug("Exit from searchGroupsByName. Retrieved the following groups: {}", accessIds);
|
||||
return accessIds;
|
||||
|
@ -182,7 +177,7 @@ public class LdapClient {
|
|||
"Removed baseDN {} from given DN. New DN to be used: {}", getBaseDn(), nameWithoutBaseDn);
|
||||
final AccessIdRepresentationModel accessId =
|
||||
ldapTemplate.lookup(
|
||||
nameWithoutBaseDn, getLookUpGoupAttributesToReturn(), new GroupContextMapper());
|
||||
nameWithoutBaseDn, getLookUpGroupAttributesToReturn(), new GroupContextMapper());
|
||||
LOGGER.debug("Exit from searchGroupByDn. Retrieved the following group: {}", accessId);
|
||||
return accessId;
|
||||
}
|
||||
|
@ -299,7 +294,9 @@ public class LdapClient {
|
|||
|
||||
void isInitOrFail() {
|
||||
if (!active) {
|
||||
throw new SystemException(String.format(MISSING_CONFIGURATION_S, message));
|
||||
throw new SystemException(
|
||||
String.format(
|
||||
"LdapClient was called but is not active due to missing configuration: %s", message));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -314,7 +311,7 @@ public class LdapClient {
|
|||
return name.replaceAll("(?i)" + Pattern.quote("," + getBaseDn()), "");
|
||||
}
|
||||
|
||||
String[] getLookUpGoupAttributesToReturn() {
|
||||
String[] getLookUpGroupAttributesToReturn() {
|
||||
if (CN.equals(getGroupNameAttribute())) {
|
||||
return new String[] {CN};
|
||||
}
|
||||
|
@ -345,7 +342,7 @@ public class LdapClient {
|
|||
// optional settings
|
||||
.filter(p -> !p.equals(LdapSettings.TASKANA_LDAP_MAX_NUMBER_OF_RETURNED_ACCESS_IDS))
|
||||
.filter(p -> !p.equals(LdapSettings.TASKANA_LDAP_MIN_SEARCH_FOR_LENGTH))
|
||||
.filter(p -> Objects.isNull(p.getValueFromEnv(env)))
|
||||
.filter(p -> p.getValueFromEnv(env) == null)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package pro.taskana.common.rest.ldap;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.core.support.LdapContextSource;
|
||||
|
||||
|
@ -11,33 +11,36 @@ import org.springframework.ldap.core.support.LdapContextSource;
|
|||
@Configuration
|
||||
public class LdapConfiguration {
|
||||
|
||||
private final Environment env;
|
||||
@Value("${taskana.ldap.serverUrl:ldap://localhost:10389}")
|
||||
private String ldapServerUrl;
|
||||
@Value("${taskana.ldap.baseDn:OU=Test,O=TASKANA}")
|
||||
private String ldapBaseDn;
|
||||
@Value("${taskana.ldap.bindDn:uid=admin}")
|
||||
private String ldapBindDn;
|
||||
@Value("${taskana.ldap.bindPassword:secret}")
|
||||
private String ldapBindPassowrd;
|
||||
private final String ldapServerUrl;
|
||||
private final String ldapBaseDn;
|
||||
private final String ldapBindDn;
|
||||
private final String ldapBindPassword;
|
||||
|
||||
public LdapConfiguration(Environment env) {
|
||||
this.env = env;
|
||||
public LdapConfiguration(
|
||||
@Value("${taskana.ldap.serverUrl:ldap://localhost:10389}") String ldapServerUrl,
|
||||
@Value("${taskana.ldap.baseDn:OU=Test,O=TASKANA}") String ldapBaseDn,
|
||||
@Value("${taskana.ldap.bindDn:uid=admin}") String ldapBindDn,
|
||||
@Value("${taskana.ldap.bindPassword:secret}") String ldapBindPassword) {
|
||||
this.ldapServerUrl = ldapServerUrl;
|
||||
this.ldapBaseDn = ldapBaseDn;
|
||||
this.ldapBindDn = ldapBindDn;
|
||||
this.ldapBindPassword = ldapBindPassword;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(LdapContextSource.class)
|
||||
public LdapContextSource ldapContextSource() {
|
||||
|
||||
LdapContextSource contextSource = new LdapContextSource();
|
||||
contextSource.setUrl(ldapServerUrl);
|
||||
contextSource.setBase(ldapBaseDn);
|
||||
contextSource.setUserDn(ldapBindDn);
|
||||
contextSource.setPassword(ldapBindPassowrd);
|
||||
contextSource.setPassword(ldapBindPassword);
|
||||
return contextSource;
|
||||
}
|
||||
|
||||
@Bean(name = "ldapTemplate")
|
||||
public LdapTemplate getActiveLdapTemplate() {
|
||||
return new LdapTemplate(ldapContextSource());
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(LdapTemplate.class)
|
||||
public LdapTemplate ldapTemplate(LdapContextSource ldapContextSource) {
|
||||
return new LdapTemplate(ldapContextSource);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package pro.taskana;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import pro.taskana.sampledata.SampleDataGenerator;
|
||||
|
||||
@SpringBootApplication
|
||||
@DependsOn("getTaskanaEngine") // wait for schema to be created BEFORE inserting test data
|
||||
public class TestConfiguration {
|
||||
|
||||
@Autowired
|
||||
public TestConfiguration(
|
||||
@Value("${taskana.schemaName:TASKANA}") String schemaName, DataSource dataSource) {
|
||||
new SampleDataGenerator(dataSource, schemaName).generateSampleData();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager txManager(DataSource dataSource) {
|
||||
return new DataSourceTransactionManager(dataSource);
|
||||
}
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
package pro.taskana.common.rest;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.sql.DataSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import pro.taskana.RestConfiguration;
|
||||
import pro.taskana.sampledata.SampleDataGenerator;
|
||||
|
||||
/** Example Application to create the documentation. */
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
@ComponentScan(basePackages = "pro.taskana")
|
||||
@Import({RestConfiguration.class})
|
||||
public class ExampleDocumentationApp {
|
||||
|
||||
@Value("${taskana.schemaName:TASKANA}")
|
||||
private String schemaName;
|
||||
|
||||
@Autowired private SampleDataGenerator sampleDataGenerator;
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ExampleDocumentationApp.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
@ConfigurationProperties(prefix = "datasource")
|
||||
public DataSourceProperties dataSourceProperties() {
|
||||
DataSourceProperties props = new DataSourceProperties();
|
||||
props.setUrl(
|
||||
"jdbc:h2:mem:taskana;IGNORECASE=TRUE;LOCK_MODE=0;INIT=CREATE SCHEMA IF NOT EXISTS "
|
||||
+ schemaName);
|
||||
return props;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource(DataSourceProperties properties) {
|
||||
return properties.initializeDataSourceBuilder().build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager txManager(DataSource dataSource) {
|
||||
return new DataSourceTransactionManager(dataSource);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@DependsOn("getTaskanaEngine") // generate sample data after schema was inserted
|
||||
public SampleDataGenerator generateSampleData(DataSource dataSource) {
|
||||
sampleDataGenerator = new SampleDataGenerator(dataSource, schemaName);
|
||||
return sampleDataGenerator;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
sampleDataGenerator.generateSampleData();
|
||||
}
|
||||
}
|
|
@ -12,16 +12,18 @@ import org.springframework.test.annotation.DirtiesContext.ClassMode;
|
|||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import pro.taskana.RestConfiguration;
|
||||
import pro.taskana.TestConfiguration;
|
||||
|
||||
/** Use this annotation to test with a spring context and a standardized configuration. */
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
// DirtiesContext is required to make the integration tests run with embedded LDAP.
|
||||
// Otherwise the LDAP server is not shut down correctly and will not come up again. (socket busy)
|
||||
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
|
||||
@Inherited
|
||||
@ActiveProfiles({"test"})
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(
|
||||
classes = RestConfiguration.class,
|
||||
classes = TestConfiguration.class,
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public @interface TaskanaSpringBootTest {}
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
package pro.taskana.common.rest;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import pro.taskana.RestConfiguration;
|
||||
import pro.taskana.TaskanaEngineConfiguration;
|
||||
import pro.taskana.common.rest.ldap.LdapConfiguration;
|
||||
|
||||
/** Configuration class for all rest tests. */
|
||||
@Import({RestConfiguration.class, LdapConfiguration.class})
|
||||
public class TestConfiguration {
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() {
|
||||
return TaskanaEngineConfiguration.createDefaultDataSource();
|
||||
}
|
||||
}
|
|
@ -101,10 +101,8 @@ class LdapClientTest {
|
|||
|
||||
@Test
|
||||
void testLdap_checkForMissingConfigurations() {
|
||||
// optional config fields
|
||||
// minSearchForLength, maxNumberOfReturnedAccessIds
|
||||
assertThat(new LdapClient().checkForMissingConfigurations())
|
||||
.hasSize(LdapSettings.values().length - 2);
|
||||
// optional config fields: minSearchForLength, maxNumberOfReturnedAccessIds
|
||||
assertThat(cut.checkForMissingConfigurations()).hasSize(LdapSettings.values().length - 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue