Reformat code using spring-javaformat
Run `./gradlew format` to reformat all java files. Issue gh-8945
This commit is contained in:
@@ -65,10 +65,9 @@ public class HttpNamespaceWithMultipleInterceptorsTests {
|
||||
|
||||
public HttpSession createAuthenticatedSession(String... roles) {
|
||||
MockHttpSession session = new MockHttpSession();
|
||||
SecurityContextHolder.getContext().setAuthentication(
|
||||
new TestingAuthenticationToken("bob", "bobspassword", roles));
|
||||
session.setAttribute(
|
||||
HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
|
||||
SecurityContextHolder.getContext()
|
||||
.setAuthentication(new TestingAuthenticationToken("bob", "bobspassword", roles));
|
||||
session.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
|
||||
SecurityContextHolder.getContext());
|
||||
SecurityContextHolder.clearContext();
|
||||
return session;
|
||||
|
||||
@@ -42,8 +42,7 @@ public class HttpPathParameterStrippingTests {
|
||||
private FilterChainProxy fcp;
|
||||
|
||||
@Test(expected = RequestRejectedException.class)
|
||||
public void securedFilterChainCannotBeBypassedByAddingPathParameters()
|
||||
throws Exception {
|
||||
public void securedFilterChainCannotBeBypassedByAddingPathParameters() throws Exception {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setPathInfo("/secured;x=y/admin.html");
|
||||
request.setSession(createAuthenticatedSession("ROLE_USER"));
|
||||
@@ -60,7 +59,6 @@ public class HttpPathParameterStrippingTests {
|
||||
fcp.doFilter(request, response, new MockFilterChain());
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = RequestRejectedException.class)
|
||||
public void adminFilePatternCannotBeBypassedByAddingPathParametersWithPathInfo() throws Exception {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
@@ -74,10 +72,9 @@ public class HttpPathParameterStrippingTests {
|
||||
|
||||
public HttpSession createAuthenticatedSession(String... roles) {
|
||||
MockHttpSession session = new MockHttpSession();
|
||||
SecurityContextHolder.getContext().setAuthentication(
|
||||
new TestingAuthenticationToken("bob", "bobspassword", roles));
|
||||
session.setAttribute(
|
||||
HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
|
||||
SecurityContextHolder.getContext()
|
||||
.setAuthentication(new TestingAuthenticationToken("bob", "bobspassword", roles));
|
||||
session.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
|
||||
SecurityContextHolder.getContext());
|
||||
SecurityContextHolder.clearContext();
|
||||
return session;
|
||||
|
||||
@@ -35,15 +35,17 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@ContextConfiguration(locations = { "/multi-sec-annotation-app-context.xml" })
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class MultiAnnotationTests {
|
||||
private final TestingAuthenticationToken joe_a = new TestingAuthenticationToken(
|
||||
"joe", "pass", "ROLE_A");
|
||||
private final TestingAuthenticationToken joe_b = new TestingAuthenticationToken(
|
||||
"joe", "pass", "ROLE_B");
|
||||
|
||||
private final TestingAuthenticationToken joe_a = new TestingAuthenticationToken("joe", "pass", "ROLE_A");
|
||||
|
||||
private final TestingAuthenticationToken joe_b = new TestingAuthenticationToken("joe", "pass", "ROLE_B");
|
||||
|
||||
@Autowired
|
||||
MultiAnnotationService service;
|
||||
|
||||
@Autowired
|
||||
PreAuthorizeService preService;
|
||||
|
||||
@Autowired
|
||||
SecuredService secService;
|
||||
|
||||
@@ -100,4 +102,5 @@ public class MultiAnnotationTests {
|
||||
SecurityContextHolder.getContext().setAuthentication(joe_b);
|
||||
secService.securedMethod();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,4 +35,5 @@ public class SEC933ApplicationContextTests {
|
||||
public void testSimpleApplicationContextBootstrap() {
|
||||
assertThat(userDetailsService).isNotNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,14 +32,17 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@ContextConfiguration(locations = { "/sec-936-app-context.xml" })
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class SEC936ApplicationContextTests {
|
||||
|
||||
@Autowired
|
||||
/** SessionRegistry is used as the test service interface (nothing to do with the test) */
|
||||
/**
|
||||
* SessionRegistry is used as the test service interface (nothing to do with the test)
|
||||
*/
|
||||
private SessionRegistry sessionRegistry;
|
||||
|
||||
@Test(expected = AccessDeniedException.class)
|
||||
public void securityInterceptorHandlesCallWithNoTargetObject() {
|
||||
SecurityContextHolder.getContext().setAuthentication(
|
||||
new UsernamePasswordAuthenticationToken("bob", "bobspassword"));
|
||||
SecurityContextHolder.getContext()
|
||||
.setAuthentication(new UsernamePasswordAuthenticationToken("bob", "bobspassword"));
|
||||
sessionRegistry.getAllPrincipals();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,4 +19,5 @@ public class StubUserRepository implements UserRepository {
|
||||
|
||||
public void doSomething() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,11 +32,12 @@ public class PythonInterpreterBasedSecurityTests {
|
||||
|
||||
@Test
|
||||
public void serviceMethod() {
|
||||
SecurityContextHolder.getContext().setAuthentication(
|
||||
new UsernamePasswordAuthenticationToken("bob", "bobspassword"));
|
||||
SecurityContextHolder.getContext()
|
||||
.setAuthentication(new UsernamePasswordAuthenticationToken("bob", "bobspassword"));
|
||||
|
||||
// for (int i=0; i < 1000; i++) {
|
||||
service.someMethod();
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,20 +37,23 @@ import javax.servlet.http.HttpSession;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Luke Taylor
|
||||
* @since 2.0
|
||||
*/
|
||||
@ContextConfiguration(locations = { "/filter-chain-performance-app-context.xml" })
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class FilterChainPerformanceTests {
|
||||
|
||||
// Adjust as required
|
||||
private static final int N_INVOCATIONS = 1; // 1000
|
||||
|
||||
private static final int N_AUTHORITIES = 2; // 200
|
||||
|
||||
private static StopWatch sw = new StopWatch("Filter Chain Performance Tests");
|
||||
|
||||
private final UsernamePasswordAuthenticationToken user = new UsernamePasswordAuthenticationToken(
|
||||
"bob", "bobspassword", createRoles(N_AUTHORITIES));
|
||||
private final UsernamePasswordAuthenticationToken user = new UsernamePasswordAuthenticationToken("bob",
|
||||
"bobspassword", createRoles(N_AUTHORITIES));
|
||||
|
||||
private HttpSession session;
|
||||
|
||||
@Autowired
|
||||
@@ -65,8 +68,7 @@ public class FilterChainPerformanceTests {
|
||||
public void createAuthenticatedSession() {
|
||||
session = new MockHttpSession();
|
||||
SecurityContextHolder.getContext().setAuthentication(user);
|
||||
session.setAttribute(
|
||||
HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
|
||||
session.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
|
||||
SecurityContextHolder.getContext());
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
@@ -121,10 +123,8 @@ public class FilterChainPerformanceTests {
|
||||
for (int user = 0; user < N_AUTHORITIES / 10; user++) {
|
||||
int nAuthorities = user == 0 ? 1 : user * 10;
|
||||
SecurityContextHolder.getContext().setAuthentication(
|
||||
new UsernamePasswordAuthenticationToken("bob", "bobspassword",
|
||||
createRoles(nAuthorities)));
|
||||
session.setAttribute(
|
||||
HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
|
||||
new UsernamePasswordAuthenticationToken("bob", "bobspassword", createRoles(nAuthorities)));
|
||||
session.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
|
||||
SecurityContextHolder.getContext());
|
||||
SecurityContextHolder.clearContext();
|
||||
sw.start(nAuthorities + " authorities");
|
||||
@@ -146,4 +146,5 @@ public class FilterChainPerformanceTests {
|
||||
|
||||
return Arrays.asList(roles);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -51,8 +51,7 @@ public class ProtectPointcutPerformanceTests implements ApplicationContextAware
|
||||
sw.start();
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
try {
|
||||
SessionRegistry reg = (SessionRegistry) ctx.getBean(
|
||||
"sessionRegistryPrototype");
|
||||
SessionRegistry reg = (SessionRegistry) ctx.getBean("sessionRegistryPrototype");
|
||||
reg.getAllPrincipals();
|
||||
fail("Expected AuthenticationCredentialsNotFoundException");
|
||||
}
|
||||
@@ -64,8 +63,8 @@ public class ProtectPointcutPerformanceTests implements ApplicationContextAware
|
||||
|
||||
}
|
||||
|
||||
public void setApplicationContext(ApplicationContext applicationContext)
|
||||
throws BeansException {
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
ctx = applicationContext;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user