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.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import pro.taskana.TaskanaEngine;
|
||||
import pro.taskana.impl.TaskanaEngineImpl;
|
||||
|
||||
/**
|
||||
* This central class creates the TaskanaEngine and needs all the information
|
||||
* about DB and Security.
|
||||
* This central class creates the TaskanaEngine and holds all the information about DB and Security.
|
||||
*/
|
||||
public class TaskanaEngineConfiguration {
|
||||
|
||||
|
@ -29,19 +29,19 @@ public class TaskanaEngineConfiguration {
|
|||
// global switch to enable JAAS based authentication and Taskana
|
||||
// authorizations
|
||||
protected boolean securityEnabled;
|
||||
protected boolean useContainerManagedTransactions;
|
||||
protected boolean useManagedTransactions;
|
||||
|
||||
public TaskanaEngineConfiguration() {
|
||||
}
|
||||
|
||||
public TaskanaEngineConfiguration(DataSource dataSource, boolean useContainerManagedTransactions)
|
||||
throws SQLException {
|
||||
throws SQLException {
|
||||
this(dataSource, useContainerManagedTransactions, true);
|
||||
}
|
||||
|
||||
public TaskanaEngineConfiguration(DataSource dataSource, boolean useContainerManagedTransactions,
|
||||
boolean securityEnabled) throws SQLException {
|
||||
this.useContainerManagedTransactions = useContainerManagedTransactions;
|
||||
boolean securityEnabled) throws SQLException {
|
||||
this.useManagedTransactions = useContainerManagedTransactions;
|
||||
|
||||
if (dataSource != null) {
|
||||
this.dataSource = dataSource;
|
||||
|
@ -57,25 +57,30 @@ public class TaskanaEngineConfiguration {
|
|||
|
||||
public static DataSource createDefaultDataSource() {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method creates the TaskanaEngine without an sqlSessionFactory.
|
||||
*
|
||||
* @return the TaskanaEngine
|
||||
* @throws SQLException TODO
|
||||
*/
|
||||
public TaskanaEngine buildTaskanaEngine() throws SQLException {
|
||||
public TaskanaEngine buildTaskanaEngine() {
|
||||
return new TaskanaEngineImpl(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method creates a PooledDataSource, if the needed properties are provided.
|
||||
* @param driver TODO
|
||||
* @param jdbcUrl TODO
|
||||
* @param username TODO
|
||||
* @param password TODO
|
||||
*
|
||||
* @param driver
|
||||
* the name of the jdbc driver
|
||||
* @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
|
||||
*/
|
||||
public static DataSource createDatasource(String driver, String jdbcUrl, String username, String password) {
|
||||
|
@ -90,8 +95,17 @@ public class TaskanaEngineConfiguration {
|
|||
return this.dataSource;
|
||||
}
|
||||
|
||||
public boolean getUseContainerManagedTransactions() {
|
||||
return this.useContainerManagedTransactions;
|
||||
public boolean getUseManagedTransactions() {
|
||||
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) {
|
||||
this.taskanaEngineConfiguration = taskanaEngineConfiguration;
|
||||
createTransactionFactory(taskanaEngineConfiguration.getUseContainerManagedTransactions());
|
||||
createTransactionFactory(taskanaEngineConfiguration.getUseManagedTransactions());
|
||||
this.sessionManager = createSqlSessionManager();
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.slf4j.LoggerFactory;
|
|||
import pro.taskana.TaskanaEngine;
|
||||
import pro.taskana.Workbasket;
|
||||
import pro.taskana.WorkbasketQuery;
|
||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||
import pro.taskana.exceptions.InvalidArgumentException;
|
||||
import pro.taskana.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.impl.util.LoggerUtils;
|
||||
|
@ -117,13 +118,14 @@ public class WorkbasketQueryImpl implements WorkbasketQuery {
|
|||
}
|
||||
this.authorization = permission;
|
||||
this.accessId = accessIds;
|
||||
for (int i = 0; i < accessIds.length; i++) {
|
||||
String id = accessIds[i];
|
||||
if (id != null) {
|
||||
accessIds[i] = id.toLowerCase();
|
||||
if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds()) {
|
||||
for (int i = 0; i < accessIds.length; i++) {
|
||||
String id = accessIds[i];
|
||||
if (id != null) {
|
||||
accessIds[i] = id.toLowerCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package pro.taskana.model;
|
||||
|
||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||
|
||||
/**
|
||||
* WorkbasketAccessItem entity.
|
||||
*/
|
||||
|
@ -39,11 +41,19 @@ public class WorkbasketAccessItem {
|
|||
}
|
||||
|
||||
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) {
|
||||
this.accessId = accessId != null ? accessId.toLowerCase() : null;
|
||||
if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds()) {
|
||||
this.accessId = accessId != null ? accessId.toLowerCase() : null;
|
||||
} else {
|
||||
this.accessId = accessId;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isPermRead() {
|
||||
|
|
|
@ -13,6 +13,8 @@ import javax.security.auth.Subject;
|
|||
import org.slf4j.Logger;
|
||||
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.
|
||||
*
|
||||
|
@ -63,7 +65,10 @@ public final class CurrentUserContext {
|
|||
(Object[]) null);
|
||||
LOGGER.debug("Returning the unique security name of first public credential: {}", o);
|
||||
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);
|
||||
return userIdUsed;
|
||||
}
|
||||
|
@ -102,7 +107,10 @@ public final class CurrentUserContext {
|
|||
for (Principal pC : principals) {
|
||||
if (!(pC instanceof Group)) {
|
||||
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);
|
||||
return userIdUsed;
|
||||
}
|
||||
|
@ -121,7 +129,10 @@ public final class CurrentUserContext {
|
|||
LOGGER.trace("Public groups of caller: {}", groups);
|
||||
for (Principal group : groups) {
|
||||
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);
|
||||
groupIds.add(groupNameReturned);
|
||||
}
|
||||
|
|
|
@ -335,7 +335,11 @@ public class WorkbasketServiceImplTest {
|
|||
accessItem.setAccessId("Zaphod Beeblebrox");
|
||||
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)
|
||||
|
|
|
@ -299,8 +299,13 @@ public class WorkbasketServiceImplIntAutocommitTest {
|
|||
accessItem.setAccessId("Zaphod Beeblebrox");
|
||||
workBasketService.updateWorkbasketAuthorization(accessItem);
|
||||
|
||||
Assert.assertEquals("zaphod beeblebrox",
|
||||
workBasketService.getWorkbasketAuthorization(accessItem.getId()).getAccessId());
|
||||
if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds()) {
|
||||
Assert.assertEquals("zaphod beeblebrox",
|
||||
workBasketService.getWorkbasketAuthorization(accessItem.getId()).getAccessId());
|
||||
} else {
|
||||
Assert.assertEquals("zaphod beeblebrox",
|
||||
workBasketService.getWorkbasketAuthorization(accessItem.getId()).getAccessId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -251,7 +251,10 @@ public class WorkbasketServiceImplIntExplicitTest {
|
|||
workbasket2.getDistributionTargets().add(workbasket0);
|
||||
workbasket2.getDistributionTargets().add(workbasket1);
|
||||
workBasketService.createWorkbasket(workbasket2);
|
||||
Workbasket workbasket3 = workBasketService.newWorkbasket();
|
||||
|
||||
WorkbasketImpl workbasket3 = (WorkbasketImpl) workBasketService.newWorkbasket();
|
||||
String id3 = IdGenerator.generateWithPrefix("TWB");
|
||||
workbasket3.setId(id3);
|
||||
workbasket3.setKey("key3");
|
||||
workbasket3.setName("hm ... irgend ein basket");
|
||||
workbasket3.setType(WorkbasketType.GROUP);
|
||||
|
|
|
@ -23,7 +23,7 @@ public class SpringTaskanaEngineConfiguration extends TaskanaEngineConfiguration
|
|||
* @return the TaskanaEngine
|
||||
*/
|
||||
public TaskanaEngine buildTaskanaEngine() {
|
||||
this.useContainerManagedTransactions = true;
|
||||
this.useManagedTransactions = true;
|
||||
|
||||
dbScriptRunner = new DbScriptRunner(this.dataSource);
|
||||
try {
|
||||
|
|
|
@ -105,7 +105,6 @@
|
|||
<module name="EqualsHashCode"/>
|
||||
<module name="IllegalInstantiation"/>
|
||||
<module name="InnerAssignment"/>
|
||||
<module name="MagicNumber"/>
|
||||
<module name="MissingSwitchDefault"/>
|
||||
<module name="SimplifyBooleanExpression"/>
|
||||
<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_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.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_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"/>
|
||||
|
@ -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_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_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.comment.format_html" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert"/>
|
||||
|
|
Loading…
Reference in New Issue