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 |
|
Also available in: Unified diff
fix test in ProgressMonitorServiceTest, extraUser needs to be in group editor