Skip to content

Commit 0034004

Browse files
BerndBreierholgerhagen
authored andcommitted
TSK-59 ACCESS_ID should always be treated as lowercase - add taskanaEngineConfiguration.getUseContainerManagedTransactions
1 parent 1952807 commit 0034004

File tree

11 files changed

+82
-34
lines changed

11 files changed

+82
-34
lines changed

lib/taskana-core/src/main/java/pro/taskana/configuration/TaskanaEngineConfiguration.java

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
import org.apache.ibatis.datasource.pooled.PooledDataSource;
88
import org.slf4j.Logger;
99
import org.slf4j.LoggerFactory;
10+
1011
import pro.taskana.TaskanaEngine;
1112
import pro.taskana.impl.TaskanaEngineImpl;
1213

1314
/**
14-
* This central class creates the TaskanaEngine and needs all the information
15-
* about DB and Security.
15+
* This central class creates the TaskanaEngine and holds all the information about DB and Security.
1616
*/
1717
public class TaskanaEngineConfiguration {
1818

@@ -29,19 +29,19 @@ public class TaskanaEngineConfiguration {
2929
// global switch to enable JAAS based authentication and Taskana
3030
// authorizations
3131
protected boolean securityEnabled;
32-
protected boolean useContainerManagedTransactions;
32+
protected boolean useManagedTransactions;
3333

3434
public TaskanaEngineConfiguration() {
3535
}
3636

3737
public TaskanaEngineConfiguration(DataSource dataSource, boolean useContainerManagedTransactions)
38-
throws SQLException {
38+
throws SQLException {
3939
this(dataSource, useContainerManagedTransactions, true);
4040
}
4141

4242
public TaskanaEngineConfiguration(DataSource dataSource, boolean useContainerManagedTransactions,
43-
boolean securityEnabled) throws SQLException {
44-
this.useContainerManagedTransactions = useContainerManagedTransactions;
43+
boolean securityEnabled) throws SQLException {
44+
this.useManagedTransactions = useContainerManagedTransactions;
4545

4646
if (dataSource != null) {
4747
this.dataSource = dataSource;
@@ -57,25 +57,30 @@ public TaskanaEngineConfiguration(DataSource dataSource, boolean useContainerMan
5757

5858
public static DataSource createDefaultDataSource() {
5959
LOGGER.warn("No datasource is provided. A inmemory db is used: "
60-
+ "'org.h2.Driver', 'jdbc:h2:mem:taskana', 'sa', 'sa'");
60+
+ "'org.h2.Driver', 'jdbc:h2:mem:taskana', 'sa', 'sa'");
6161
return createDatasource(H2_DRIVER, JDBC_H2_MEM_TASKANA, USER_NAME, USER_PASSWORD);
6262
}
6363

6464
/**
6565
* This method creates the TaskanaEngine without an sqlSessionFactory.
66+
*
6667
* @return the TaskanaEngine
67-
* @throws SQLException TODO
6868
*/
69-
public TaskanaEngine buildTaskanaEngine() throws SQLException {
69+
public TaskanaEngine buildTaskanaEngine() {
7070
return new TaskanaEngineImpl(this);
7171
}
7272

7373
/**
7474
* This method creates a PooledDataSource, if the needed properties are provided.
75-
* @param driver TODO
76-
* @param jdbcUrl TODO
77-
* @param username TODO
78-
* @param password TODO
75+
*
76+
* @param driver
77+
* the name of the jdbc driver
78+
* @param jdbcUrl
79+
* the url to which the jdbc driver connects
80+
* @param username
81+
* the user name for database access
82+
* @param password
83+
* the password for database access
7984
* @return DataSource
8085
*/
8186
public static DataSource createDatasource(String driver, String jdbcUrl, String username, String password) {
@@ -90,8 +95,17 @@ public DataSource getDatasource() {
9095
return this.dataSource;
9196
}
9297

93-
public boolean getUseContainerManagedTransactions() {
94-
return this.useContainerManagedTransactions;
98+
public boolean getUseManagedTransactions() {
99+
return this.useManagedTransactions;
100+
}
101+
102+
/**
103+
* Helper method to determine whether all access ids (user Id and group ids) should be used in lower case.
104+
*
105+
* @return true if all access ids should be used in lower case, false otherwise
106+
*/
107+
public static boolean shouldUseLowerCaseForAccessIds() {
108+
return true;
95109
}
96110

97111
}

lib/taskana-core/src/main/java/pro/taskana/impl/TaskanaEngineImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class TaskanaEngineImpl implements TaskanaEngine {
5757

5858
public TaskanaEngineImpl(TaskanaEngineConfiguration taskanaEngineConfiguration) {
5959
this.taskanaEngineConfiguration = taskanaEngineConfiguration;
60-
createTransactionFactory(taskanaEngineConfiguration.getUseContainerManagedTransactions());
60+
createTransactionFactory(taskanaEngineConfiguration.getUseManagedTransactions());
6161
this.sessionManager = createSqlSessionManager();
6262
}
6363

lib/taskana-core/src/main/java/pro/taskana/impl/WorkbasketQueryImpl.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import pro.taskana.TaskanaEngine;
1212
import pro.taskana.Workbasket;
1313
import pro.taskana.WorkbasketQuery;
14+
import pro.taskana.configuration.TaskanaEngineConfiguration;
1415
import pro.taskana.exceptions.InvalidArgumentException;
1516
import pro.taskana.exceptions.NotAuthorizedException;
1617
import pro.taskana.impl.util.LoggerUtils;
@@ -117,13 +118,14 @@ public WorkbasketQuery access(WorkbasketAuthorization permission, String... acce
117118
}
118119
this.authorization = permission;
119120
this.accessId = accessIds;
120-
for (int i = 0; i < accessIds.length; i++) {
121-
String id = accessIds[i];
122-
if (id != null) {
123-
accessIds[i] = id.toLowerCase();
121+
if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds()) {
122+
for (int i = 0; i < accessIds.length; i++) {
123+
String id = accessIds[i];
124+
if (id != null) {
125+
accessIds[i] = id.toLowerCase();
126+
}
124127
}
125128
}
126-
127129
return this;
128130
}
129131

lib/taskana-core/src/main/java/pro/taskana/model/WorkbasketAccessItem.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package pro.taskana.model;
22

3+
import pro.taskana.configuration.TaskanaEngineConfiguration;
4+
35
/**
46
* WorkbasketAccessItem entity.
57
*/
@@ -39,11 +41,19 @@ public void setWorkbasketKey(String workbasketKey) {
3941
}
4042

4143
public String getAccessId() {
42-
return accessId != null ? accessId.toLowerCase() : null;
44+
if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds()) {
45+
return accessId != null ? accessId.toLowerCase() : null;
46+
} else {
47+
return accessId;
48+
}
4349
}
4450

4551
public void setAccessId(String accessId) {
46-
this.accessId = accessId != null ? accessId.toLowerCase() : null;
52+
if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds()) {
53+
this.accessId = accessId != null ? accessId.toLowerCase() : null;
54+
} else {
55+
this.accessId = accessId;
56+
}
4757
}
4858

4959
public boolean isPermRead() {

lib/taskana-core/src/main/java/pro/taskana/security/CurrentUserContext.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import org.slf4j.Logger;
1414
import org.slf4j.LoggerFactory;
1515

16+
import pro.taskana.configuration.TaskanaEngineConfiguration;
17+
1618
/**
1719
* Provides the context information about the current (calling) user. The context is gathered from the JAAS subject.
1820
*
@@ -63,7 +65,10 @@ private static String getUseridFromWSSubject() {
6365
(Object[]) null);
6466
LOGGER.debug("Returning the unique security name of first public credential: {}", o);
6567
String userIdFound = o.toString();
66-
String userIdUsed = userIdFound != null ? userIdFound.toLowerCase() : null;
68+
String userIdUsed = userIdFound;
69+
if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds() && userIdFound != null) {
70+
userIdUsed = userIdFound.toLowerCase();
71+
}
6772
LOGGER.trace("Found User id {}. Returning User id {} ", userIdFound, userIdUsed);
6873
return userIdUsed;
6974
}
@@ -102,7 +107,10 @@ private static String getUseridFromJAASSubject() {
102107
for (Principal pC : principals) {
103108
if (!(pC instanceof Group)) {
104109
String userIdFound = pC.getName();
105-
String userIdUsed = userIdFound != null ? userIdFound.toLowerCase() : null;
110+
String userIdUsed = userIdFound;
111+
if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds() && userIdFound != null) {
112+
userIdUsed = userIdFound.toLowerCase();
113+
}
106114
LOGGER.trace("Found User id {}. Returning User id {} ", userIdFound, userIdUsed);
107115
return userIdUsed;
108116
}
@@ -121,7 +129,10 @@ public static List<String> getGroupIds() {
121129
LOGGER.trace("Public groups of caller: {}", groups);
122130
for (Principal group : groups) {
123131
String groupNameFound = group.getName();
124-
String groupNameReturned = groupNameFound != null ? groupNameFound.toLowerCase() : null;
132+
String groupNameReturned = groupNameFound;
133+
if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds() && groupNameFound != null) {
134+
groupNameReturned = groupNameFound.toLowerCase();
135+
}
125136
LOGGER.trace("Found group id {}. Returning group Id: {}", groupNameFound, groupNameReturned);
126137
groupIds.add(groupNameReturned);
127138
}

lib/taskana-core/src/test/java/pro/taskana/impl/WorkbasketServiceImplTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,11 @@ public void should_ReturnWorkbasketAuthorization_when_WorkbasketAccessItemIsUpda
335335
accessItem.setAccessId("Zaphod Beeblebrox");
336336
workbasketServiceImpl.updateWorkbasketAuthorization(accessItem);
337337

338-
Assert.assertEquals("zaphod beeblebrox", accessItem.getAccessId());
338+
if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds()) {
339+
Assert.assertEquals("zaphod beeblebrox", accessItem.getAccessId());
340+
} else {
341+
Assert.assertEquals("Zaphod Beeblebrox", accessItem.getAccessId());
342+
}
339343
}
340344

341345
@Test(expected = NotAuthorizedException.class)

lib/taskana-core/src/test/java/pro/taskana/impl/integration/WorkbasketServiceImplIntAutocommitTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,13 @@ public void testUpdateWorkbasketAccessUser() throws NotAuthorizedException {
299299
accessItem.setAccessId("Zaphod Beeblebrox");
300300
workBasketService.updateWorkbasketAuthorization(accessItem);
301301

302-
Assert.assertEquals("zaphod beeblebrox",
303-
workBasketService.getWorkbasketAuthorization(accessItem.getId()).getAccessId());
302+
if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds()) {
303+
Assert.assertEquals("zaphod beeblebrox",
304+
workBasketService.getWorkbasketAuthorization(accessItem.getId()).getAccessId());
305+
} else {
306+
Assert.assertEquals("zaphod beeblebrox",
307+
workBasketService.getWorkbasketAuthorization(accessItem.getId()).getAccessId());
308+
}
304309
}
305310

306311
@Test

lib/taskana-core/src/test/java/pro/taskana/impl/integration/WorkbasketServiceImplIntExplicitTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,10 @@ public void testUpdateWorkbasket() throws Exception {
251251
workbasket2.getDistributionTargets().add(workbasket0);
252252
workbasket2.getDistributionTargets().add(workbasket1);
253253
workBasketService.createWorkbasket(workbasket2);
254-
Workbasket workbasket3 = workBasketService.newWorkbasket();
254+
255+
WorkbasketImpl workbasket3 = (WorkbasketImpl) workBasketService.newWorkbasket();
256+
String id3 = IdGenerator.generateWithPrefix("TWB");
257+
workbasket3.setId(id3);
255258
workbasket3.setKey("key3");
256259
workbasket3.setName("hm ... irgend ein basket");
257260
workbasket3.setType(WorkbasketType.GROUP);

lib/taskana-spring/src/main/java/pro/taskana/configuration/SpringTaskanaEngineConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class SpringTaskanaEngineConfiguration extends TaskanaEngineConfiguration
2323
* @return the TaskanaEngine
2424
*/
2525
public TaskanaEngine buildTaskanaEngine() {
26-
this.useContainerManagedTransactions = true;
26+
this.useManagedTransactions = true;
2727

2828
dbScriptRunner = new DbScriptRunner(this.dataSource);
2929
try {

qa/checkstyle/checkstyle.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@
105105
<module name="EqualsHashCode"/>
106106
<module name="IllegalInstantiation"/>
107107
<module name="InnerAssignment"/>
108-
<module name="MagicNumber"/>
109108
<module name="MissingSwitchDefault"/>
110109
<module name="SimplifyBooleanExpression"/>
111110
<module name="SimplifyBooleanReturn"/>

qa/eclipseFormatter/taskana_formatter.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block" value="insert"/>
5353
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/>
5454
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="1"/>
55-
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="insert"/>
55+
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="do not insert"/>
5656
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/>
5757
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/>
5858
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/>
@@ -205,7 +205,7 @@
205205
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/>
206206
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/>
207207
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation" value="do not insert"/>
208-
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="insert"/>
208+
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="do not insert"/>
209209
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/>
210210
<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="true"/>
211211
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert"/>

0 commit comments

Comments
 (0)