TSK-59 ACCESS_ID should always be treated as lowercase - add taskanaEngineConfiguration.getUseContainerManagedTransactions
This commit is contained in:
parent
1952807123
commit
00340044e2
|
|
@ -7,12 +7,12 @@ import javax.sql.DataSource;
|
||||||
import org.apache.ibatis.datasource.pooled.PooledDataSource;
|
import org.apache.ibatis.datasource.pooled.PooledDataSource;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import pro.taskana.TaskanaEngine;
|
import pro.taskana.TaskanaEngine;
|
||||||
import pro.taskana.impl.TaskanaEngineImpl;
|
import pro.taskana.impl.TaskanaEngineImpl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This central class creates the TaskanaEngine and needs all the information
|
* This central class creates the TaskanaEngine and holds all the information about DB and Security.
|
||||||
* about DB and Security.
|
|
||||||
*/
|
*/
|
||||||
public class TaskanaEngineConfiguration {
|
public class TaskanaEngineConfiguration {
|
||||||
|
|
||||||
|
|
@ -29,19 +29,19 @@ public class TaskanaEngineConfiguration {
|
||||||
// global switch to enable JAAS based authentication and Taskana
|
// global switch to enable JAAS based authentication and Taskana
|
||||||
// authorizations
|
// authorizations
|
||||||
protected boolean securityEnabled;
|
protected boolean securityEnabled;
|
||||||
protected boolean useContainerManagedTransactions;
|
protected boolean useManagedTransactions;
|
||||||
|
|
||||||
public TaskanaEngineConfiguration() {
|
public TaskanaEngineConfiguration() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public TaskanaEngineConfiguration(DataSource dataSource, boolean useContainerManagedTransactions)
|
public TaskanaEngineConfiguration(DataSource dataSource, boolean useContainerManagedTransactions)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
this(dataSource, useContainerManagedTransactions, true);
|
this(dataSource, useContainerManagedTransactions, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TaskanaEngineConfiguration(DataSource dataSource, boolean useContainerManagedTransactions,
|
public TaskanaEngineConfiguration(DataSource dataSource, boolean useContainerManagedTransactions,
|
||||||
boolean securityEnabled) throws SQLException {
|
boolean securityEnabled) throws SQLException {
|
||||||
this.useContainerManagedTransactions = useContainerManagedTransactions;
|
this.useManagedTransactions = useContainerManagedTransactions;
|
||||||
|
|
||||||
if (dataSource != null) {
|
if (dataSource != null) {
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
|
|
@ -57,25 +57,30 @@ public class TaskanaEngineConfiguration {
|
||||||
|
|
||||||
public static DataSource createDefaultDataSource() {
|
public static DataSource createDefaultDataSource() {
|
||||||
LOGGER.warn("No datasource is provided. A inmemory db is used: "
|
LOGGER.warn("No datasource is provided. A inmemory db is used: "
|
||||||
+ "'org.h2.Driver', 'jdbc:h2:mem:taskana', 'sa', 'sa'");
|
+ "'org.h2.Driver', 'jdbc:h2:mem:taskana', 'sa', 'sa'");
|
||||||
return createDatasource(H2_DRIVER, JDBC_H2_MEM_TASKANA, USER_NAME, USER_PASSWORD);
|
return createDatasource(H2_DRIVER, JDBC_H2_MEM_TASKANA, USER_NAME, USER_PASSWORD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method creates the TaskanaEngine without an sqlSessionFactory.
|
* This method creates the TaskanaEngine without an sqlSessionFactory.
|
||||||
|
*
|
||||||
* @return the TaskanaEngine
|
* @return the TaskanaEngine
|
||||||
* @throws SQLException TODO
|
|
||||||
*/
|
*/
|
||||||
public TaskanaEngine buildTaskanaEngine() throws SQLException {
|
public TaskanaEngine buildTaskanaEngine() {
|
||||||
return new TaskanaEngineImpl(this);
|
return new TaskanaEngineImpl(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method creates a PooledDataSource, if the needed properties are provided.
|
* This method creates a PooledDataSource, if the needed properties are provided.
|
||||||
* @param driver TODO
|
*
|
||||||
* @param jdbcUrl TODO
|
* @param driver
|
||||||
* @param username TODO
|
* the name of the jdbc driver
|
||||||
* @param password TODO
|
* @param jdbcUrl
|
||||||
|
* the url to which the jdbc driver connects
|
||||||
|
* @param username
|
||||||
|
* the user name for database access
|
||||||
|
* @param password
|
||||||
|
* the password for database access
|
||||||
* @return DataSource
|
* @return DataSource
|
||||||
*/
|
*/
|
||||||
public static DataSource createDatasource(String driver, String jdbcUrl, String username, String password) {
|
public static DataSource createDatasource(String driver, String jdbcUrl, String username, String password) {
|
||||||
|
|
@ -90,8 +95,17 @@ public class TaskanaEngineConfiguration {
|
||||||
return this.dataSource;
|
return this.dataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getUseContainerManagedTransactions() {
|
public boolean getUseManagedTransactions() {
|
||||||
return this.useContainerManagedTransactions;
|
return this.useManagedTransactions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to determine whether all access ids (user Id and group ids) should be used in lower case.
|
||||||
|
*
|
||||||
|
* @return true if all access ids should be used in lower case, false otherwise
|
||||||
|
*/
|
||||||
|
public static boolean shouldUseLowerCaseForAccessIds() {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ public class TaskanaEngineImpl implements TaskanaEngine {
|
||||||
|
|
||||||
public TaskanaEngineImpl(TaskanaEngineConfiguration taskanaEngineConfiguration) {
|
public TaskanaEngineImpl(TaskanaEngineConfiguration taskanaEngineConfiguration) {
|
||||||
this.taskanaEngineConfiguration = taskanaEngineConfiguration;
|
this.taskanaEngineConfiguration = taskanaEngineConfiguration;
|
||||||
createTransactionFactory(taskanaEngineConfiguration.getUseContainerManagedTransactions());
|
createTransactionFactory(taskanaEngineConfiguration.getUseManagedTransactions());
|
||||||
this.sessionManager = createSqlSessionManager();
|
this.sessionManager = createSqlSessionManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import org.slf4j.LoggerFactory;
|
||||||
import pro.taskana.TaskanaEngine;
|
import pro.taskana.TaskanaEngine;
|
||||||
import pro.taskana.Workbasket;
|
import pro.taskana.Workbasket;
|
||||||
import pro.taskana.WorkbasketQuery;
|
import pro.taskana.WorkbasketQuery;
|
||||||
|
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||||
import pro.taskana.exceptions.InvalidArgumentException;
|
import pro.taskana.exceptions.InvalidArgumentException;
|
||||||
import pro.taskana.exceptions.NotAuthorizedException;
|
import pro.taskana.exceptions.NotAuthorizedException;
|
||||||
import pro.taskana.impl.util.LoggerUtils;
|
import pro.taskana.impl.util.LoggerUtils;
|
||||||
|
|
@ -117,13 +118,14 @@ public class WorkbasketQueryImpl implements WorkbasketQuery {
|
||||||
}
|
}
|
||||||
this.authorization = permission;
|
this.authorization = permission;
|
||||||
this.accessId = accessIds;
|
this.accessId = accessIds;
|
||||||
for (int i = 0; i < accessIds.length; i++) {
|
if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds()) {
|
||||||
String id = accessIds[i];
|
for (int i = 0; i < accessIds.length; i++) {
|
||||||
if (id != null) {
|
String id = accessIds[i];
|
||||||
accessIds[i] = id.toLowerCase();
|
if (id != null) {
|
||||||
|
accessIds[i] = id.toLowerCase();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package pro.taskana.model;
|
package pro.taskana.model;
|
||||||
|
|
||||||
|
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WorkbasketAccessItem entity.
|
* WorkbasketAccessItem entity.
|
||||||
*/
|
*/
|
||||||
|
|
@ -39,11 +41,19 @@ public class WorkbasketAccessItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAccessId() {
|
public String getAccessId() {
|
||||||
return accessId != null ? accessId.toLowerCase() : null;
|
if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds()) {
|
||||||
|
return accessId != null ? accessId.toLowerCase() : null;
|
||||||
|
} else {
|
||||||
|
return accessId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAccessId(String accessId) {
|
public void setAccessId(String accessId) {
|
||||||
this.accessId = accessId != null ? accessId.toLowerCase() : null;
|
if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds()) {
|
||||||
|
this.accessId = accessId != null ? accessId.toLowerCase() : null;
|
||||||
|
} else {
|
||||||
|
this.accessId = accessId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPermRead() {
|
public boolean isPermRead() {
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ import javax.security.auth.Subject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides the context information about the current (calling) user. The context is gathered from the JAAS subject.
|
* Provides the context information about the current (calling) user. The context is gathered from the JAAS subject.
|
||||||
*
|
*
|
||||||
|
|
@ -63,7 +65,10 @@ public final class CurrentUserContext {
|
||||||
(Object[]) null);
|
(Object[]) null);
|
||||||
LOGGER.debug("Returning the unique security name of first public credential: {}", o);
|
LOGGER.debug("Returning the unique security name of first public credential: {}", o);
|
||||||
String userIdFound = o.toString();
|
String userIdFound = o.toString();
|
||||||
String userIdUsed = userIdFound != null ? userIdFound.toLowerCase() : null;
|
String userIdUsed = userIdFound;
|
||||||
|
if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds() && userIdFound != null) {
|
||||||
|
userIdUsed = userIdFound.toLowerCase();
|
||||||
|
}
|
||||||
LOGGER.trace("Found User id {}. Returning User id {} ", userIdFound, userIdUsed);
|
LOGGER.trace("Found User id {}. Returning User id {} ", userIdFound, userIdUsed);
|
||||||
return userIdUsed;
|
return userIdUsed;
|
||||||
}
|
}
|
||||||
|
|
@ -102,7 +107,10 @@ public final class CurrentUserContext {
|
||||||
for (Principal pC : principals) {
|
for (Principal pC : principals) {
|
||||||
if (!(pC instanceof Group)) {
|
if (!(pC instanceof Group)) {
|
||||||
String userIdFound = pC.getName();
|
String userIdFound = pC.getName();
|
||||||
String userIdUsed = userIdFound != null ? userIdFound.toLowerCase() : null;
|
String userIdUsed = userIdFound;
|
||||||
|
if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds() && userIdFound != null) {
|
||||||
|
userIdUsed = userIdFound.toLowerCase();
|
||||||
|
}
|
||||||
LOGGER.trace("Found User id {}. Returning User id {} ", userIdFound, userIdUsed);
|
LOGGER.trace("Found User id {}. Returning User id {} ", userIdFound, userIdUsed);
|
||||||
return userIdUsed;
|
return userIdUsed;
|
||||||
}
|
}
|
||||||
|
|
@ -121,7 +129,10 @@ public final class CurrentUserContext {
|
||||||
LOGGER.trace("Public groups of caller: {}", groups);
|
LOGGER.trace("Public groups of caller: {}", groups);
|
||||||
for (Principal group : groups) {
|
for (Principal group : groups) {
|
||||||
String groupNameFound = group.getName();
|
String groupNameFound = group.getName();
|
||||||
String groupNameReturned = groupNameFound != null ? groupNameFound.toLowerCase() : null;
|
String groupNameReturned = groupNameFound;
|
||||||
|
if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds() && groupNameFound != null) {
|
||||||
|
groupNameReturned = groupNameFound.toLowerCase();
|
||||||
|
}
|
||||||
LOGGER.trace("Found group id {}. Returning group Id: {}", groupNameFound, groupNameReturned);
|
LOGGER.trace("Found group id {}. Returning group Id: {}", groupNameFound, groupNameReturned);
|
||||||
groupIds.add(groupNameReturned);
|
groupIds.add(groupNameReturned);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -335,7 +335,11 @@ public class WorkbasketServiceImplTest {
|
||||||
accessItem.setAccessId("Zaphod Beeblebrox");
|
accessItem.setAccessId("Zaphod Beeblebrox");
|
||||||
workbasketServiceImpl.updateWorkbasketAuthorization(accessItem);
|
workbasketServiceImpl.updateWorkbasketAuthorization(accessItem);
|
||||||
|
|
||||||
Assert.assertEquals("zaphod beeblebrox", accessItem.getAccessId());
|
if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds()) {
|
||||||
|
Assert.assertEquals("zaphod beeblebrox", accessItem.getAccessId());
|
||||||
|
} else {
|
||||||
|
Assert.assertEquals("Zaphod Beeblebrox", accessItem.getAccessId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NotAuthorizedException.class)
|
@Test(expected = NotAuthorizedException.class)
|
||||||
|
|
|
||||||
|
|
@ -299,8 +299,13 @@ public class WorkbasketServiceImplIntAutocommitTest {
|
||||||
accessItem.setAccessId("Zaphod Beeblebrox");
|
accessItem.setAccessId("Zaphod Beeblebrox");
|
||||||
workBasketService.updateWorkbasketAuthorization(accessItem);
|
workBasketService.updateWorkbasketAuthorization(accessItem);
|
||||||
|
|
||||||
Assert.assertEquals("zaphod beeblebrox",
|
if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds()) {
|
||||||
workBasketService.getWorkbasketAuthorization(accessItem.getId()).getAccessId());
|
Assert.assertEquals("zaphod beeblebrox",
|
||||||
|
workBasketService.getWorkbasketAuthorization(accessItem.getId()).getAccessId());
|
||||||
|
} else {
|
||||||
|
Assert.assertEquals("zaphod beeblebrox",
|
||||||
|
workBasketService.getWorkbasketAuthorization(accessItem.getId()).getAccessId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -251,7 +251,10 @@ public class WorkbasketServiceImplIntExplicitTest {
|
||||||
workbasket2.getDistributionTargets().add(workbasket0);
|
workbasket2.getDistributionTargets().add(workbasket0);
|
||||||
workbasket2.getDistributionTargets().add(workbasket1);
|
workbasket2.getDistributionTargets().add(workbasket1);
|
||||||
workBasketService.createWorkbasket(workbasket2);
|
workBasketService.createWorkbasket(workbasket2);
|
||||||
Workbasket workbasket3 = workBasketService.newWorkbasket();
|
|
||||||
|
WorkbasketImpl workbasket3 = (WorkbasketImpl) workBasketService.newWorkbasket();
|
||||||
|
String id3 = IdGenerator.generateWithPrefix("TWB");
|
||||||
|
workbasket3.setId(id3);
|
||||||
workbasket3.setKey("key3");
|
workbasket3.setKey("key3");
|
||||||
workbasket3.setName("hm ... irgend ein basket");
|
workbasket3.setName("hm ... irgend ein basket");
|
||||||
workbasket3.setType(WorkbasketType.GROUP);
|
workbasket3.setType(WorkbasketType.GROUP);
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ public class SpringTaskanaEngineConfiguration extends TaskanaEngineConfiguration
|
||||||
* @return the TaskanaEngine
|
* @return the TaskanaEngine
|
||||||
*/
|
*/
|
||||||
public TaskanaEngine buildTaskanaEngine() {
|
public TaskanaEngine buildTaskanaEngine() {
|
||||||
this.useContainerManagedTransactions = true;
|
this.useManagedTransactions = true;
|
||||||
|
|
||||||
dbScriptRunner = new DbScriptRunner(this.dataSource);
|
dbScriptRunner = new DbScriptRunner(this.dataSource);
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,6 @@
|
||||||
<module name="EqualsHashCode"/>
|
<module name="EqualsHashCode"/>
|
||||||
<module name="IllegalInstantiation"/>
|
<module name="IllegalInstantiation"/>
|
||||||
<module name="InnerAssignment"/>
|
<module name="InnerAssignment"/>
|
||||||
<module name="MagicNumber"/>
|
|
||||||
<module name="MissingSwitchDefault"/>
|
<module name="MissingSwitchDefault"/>
|
||||||
<module name="SimplifyBooleanExpression"/>
|
<module name="SimplifyBooleanExpression"/>
|
||||||
<module name="SimplifyBooleanReturn"/>
|
<module name="SimplifyBooleanReturn"/>
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@
|
||||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block" value="insert"/>
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block" value="insert"/>
|
||||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/>
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/>
|
||||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="1"/>
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="1"/>
|
||||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="insert"/>
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="do not insert"/>
|
||||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/>
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/>
|
||||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/>
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/>
|
||||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/>
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/>
|
||||||
|
|
@ -205,7 +205,7 @@
|
||||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/>
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/>
|
||||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/>
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/>
|
||||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation" value="do not insert"/>
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation" value="do not insert"/>
|
||||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="insert"/>
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="do not insert"/>
|
||||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/>
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/>
|
||||||
<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="true"/>
|
<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="true"/>
|
||||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert"/>
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert"/>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue