Revision d7aa17fe
Added by Katja Luther about 5 years ago
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/httpinvoker/BaseRemotingTest.java | ||
---|---|---|
16 | 16 |
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
17 | 17 |
import org.springframework.security.core.Authentication; |
18 | 18 |
import org.springframework.security.core.context.SecurityContextHolder; |
19 |
import org.springframework.security.core.context.SecurityContextImpl; |
|
20 | 19 |
import org.unitils.database.DatabaseUnitils; |
21 | 20 |
import org.unitils.database.annotations.Transactional; |
22 | 21 |
import org.unitils.database.util.TransactionMode; |
... | ... | |
27 | 26 |
import eu.etaxonomy.cdm.api.application.CdmDataChangeService; |
28 | 27 |
import eu.etaxonomy.cdm.api.cache.CdmServiceCacher; |
29 | 28 |
import eu.etaxonomy.cdm.cache.CdmRemoteCacheManager; |
29 |
import eu.etaxonomy.cdm.model.common.User; |
|
30 | 30 |
import eu.etaxonomy.taxeditor.remoting.cache.ConversationalTransientEntityCacher; |
31 | 31 |
import eu.etaxonomy.taxeditor.remoting.source.CdmPersistentRemoteSource; |
32 | 32 |
import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource; |
... | ... | |
67 | 67 |
user, |
68 | 68 |
password); |
69 | 69 |
} catch (Exception e) { |
70 |
System.err.println("user: " + user + " password: " + password); |
|
70 | 71 |
e.printStackTrace(); |
71 | 72 |
// Assert.fail("Server failed to start. Reason : " + e.getMessage()); |
72 | 73 |
} |
... | ... | |
111 | 112 |
//FIXME:Remoting the authentication code should be replaced by a method call which actually |
112 | 113 |
// does the authentication in the editor code so that the 'real' authentication can be tested |
113 | 114 |
SecurityContextHolder.clearContext(); |
114 |
SecurityContextImpl sc = new SecurityContextImpl(); |
|
115 |
Authentication token = new UsernamePasswordAuthenticationToken(username,password);
|
|
115 |
|
|
116 |
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password);
|
|
116 | 117 |
Authentication authentication = getRemoteApplicationController().getAuthenticationManager().authenticate(token); |
117 |
authentication = new UsernamePasswordAuthenticationToken(username,password, authentication.getAuthorities()); |
|
118 |
sc.setAuthentication(authentication); |
|
119 | 118 |
|
120 |
SecurityContextHolder.setContext(sc); |
|
119 |
|
|
120 |
User user = (User) authentication.getPrincipal(); |
|
121 |
/* circumventing problem with hibernate not refreshing the transient collection authorities in this case, |
|
122 |
* see http://dev.e-taxonomy.eu/trac/ticket/4053 */ |
|
123 |
user.initAuthorities(); |
|
124 |
authentication = new UsernamePasswordAuthenticationToken(user,password, authentication.getAuthorities()); |
|
125 |
SecurityContextHolder.getContext().setAuthentication(authentication); |
|
121 | 126 |
CdmApplicationState.setCurrentSecurityContext(SecurityContextHolder.getContext()); |
122 | 127 |
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
// SecurityContextHolder.clearContext(); |
|
133 |
// SecurityContextImpl sc = new SecurityContextImpl(); |
|
134 |
// Authentication token = new UsernamePasswordAuthenticationToken(username,password); |
|
135 |
// Authentication authentication = getRemoteApplicationController().getAuthenticationManager().authenticate(token); |
|
136 |
// |
|
137 |
// authentication = new UsernamePasswordAuthenticationToken(username,password, authentication.getAuthorities()); |
|
138 |
// sc.setAuthentication(authentication); |
|
139 |
// |
|
140 |
// SecurityContextHolder.setContext(sc); |
|
141 |
// CdmApplicationState.setCurrentSecurityContext(SecurityContextHolder.getContext()); |
|
142 |
|
|
123 | 143 |
} |
124 | 144 |
|
125 | 145 |
|
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/httpinvoker/RemotingSessionAwareTest.java | ||
---|---|---|
13 | 13 |
import org.apache.log4j.Logger; |
14 | 14 |
import org.junit.After; |
15 | 15 |
import org.junit.Before; |
16 |
import org.springframework.security.core.userdetails.UserDetails; |
|
16 | 17 |
import org.springframework.security.core.userdetails.UsernameNotFoundException; |
17 | 18 |
|
18 | 19 |
import eu.etaxonomy.cdm.api.application.CdmApplicationState; |
19 | 20 |
import eu.etaxonomy.cdm.api.service.IUserService; |
20 | 21 |
import eu.etaxonomy.cdm.model.common.Group; |
21 | 22 |
import eu.etaxonomy.cdm.model.common.User; |
22 |
import eu.etaxonomy.cdm.persistence.dto.MergeResult; |
|
23 | 23 |
import eu.etaxonomy.taxeditor.remoting.cache.ConversationalTransientEntityCacher; |
24 | 24 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySession; |
25 | 25 |
import eu.etaxonomy.taxeditor.session.MockSessionOwner; |
... | ... | |
53 | 53 |
sessionOwner.setCdmEntitySession(cdmEntitySession); |
54 | 54 |
cacher = getCacher(sessionOwner); |
55 | 55 |
|
56 |
User extraUser = null; |
|
56 |
UserDetails extraUser = null;
|
|
57 | 57 |
|
58 | 58 |
try { |
59 |
extraUser = (User) userService.loadUserByUsername(extraUsername);
|
|
59 |
extraUser = userService.loadUserByUsername(extraUsername); |
|
60 | 60 |
Group editorGroup = getRemoteApplicationController().getGroupService().find(editorGroupUuid); |
61 |
if (!extraUser.getGroups().contains(editorGroup)){ |
|
62 |
extraUser.getGroups().add(editorGroup); |
|
63 |
userService.merge(extraUser, true); |
|
61 |
if (!((User)extraUser).getGroups().contains(editorGroup)){ |
|
62 |
((User)extraUser).getGroups().add(editorGroup); |
|
63 |
userService.merge(((User)extraUser), true); |
|
64 |
|
|
64 | 65 |
} |
65 | 66 |
} catch (UsernameNotFoundException unfe) { |
66 |
User user = User.NewInstance(extraUsername, extraPassword); |
|
67 |
UserDetails user = User.NewInstance(extraUsername, extraPassword);
|
|
67 | 68 |
userService.createUser(user); |
69 |
user = userService.load(((User)user).getUuid()); |
|
68 | 70 |
Group editorGroup = getRemoteApplicationController().getGroupService().find(editorGroupUuid); |
69 |
user = userService.load(user.getUuid());
|
|
70 |
user.getGroups().add(editorGroup);
|
|
71 |
MergeResult<User> result = userService.merge(user, true); |
|
72 |
user = result.getMergedEntity(); |
|
71 |
((User)user).getGroups().add(editorGroup);
|
|
72 |
userService.merge(((User)user), true);
|
|
73 |
|
|
74 |
|
|
73 | 75 |
} |
74 | 76 |
|
75 | 77 |
|
... | ... | |
84 | 86 |
|
85 | 87 |
|
86 | 88 |
protected static void authenticateExtraUser() { |
89 |
|
|
87 | 90 |
authenticate(extraUsername, extraPassword); |
88 | 91 |
} |
89 | 92 |
|
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/service/ProgressMonitorServiceTest.java | ||
---|---|---|
18 | 18 |
import org.eclipse.core.runtime.SubMonitor; |
19 | 19 |
import org.junit.After; |
20 | 20 |
import org.junit.Assert; |
21 |
import org.junit.Ignore; |
|
22 | 21 |
import org.junit.Test; |
23 | 22 |
|
24 | 23 |
import eu.etaxonomy.cdm.api.application.CdmApplicationState; |
... | ... | |
69 | 68 |
} |
70 | 69 |
|
71 | 70 |
@Test |
72 |
@Ignore |
|
71 |
// @Ignore
|
|
73 | 72 |
public void testMonitLongRunningMethodByChangingUser() throws InterruptedException { |
74 | 73 |
|
75 | 74 |
IllegalStateException ise = new IllegalStateException("IllegalStateException"); |
76 | 75 |
|
77 | 76 |
UUID uuid = testService.monitLongRunningMethod(ise, null, 0); |
77 |
|
|
78 | 78 |
authenticateExtraUser(); |
79 | 79 |
IRemotingProgressMonitor monitor = progressMonitorService.getRemotingMonitor(uuid); |
80 | 80 |
Assert.assertNull(monitor); |
Also available in: Unified diff
fix test in ProgressMonitorServiceTest, extraUser needs to be in group editor