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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,4 +34,5 @@ public class UserDetailsServiceImpl implements UserDetailsService {
|
||||
public void setUserRepository(UserRepository userRepository) {
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,4 +36,5 @@ public interface MultiAnnotationService {
|
||||
|
||||
@Secured("ROLE_A")
|
||||
void securedRoleAMethod();
|
||||
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ package org.springframework.security.integration.multiannotation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Luke Taylor
|
||||
*/
|
||||
public interface PreAuthorizeService {
|
||||
|
||||
@PreAuthorize("hasRole('ROLE_A')")
|
||||
void preAuthorizedMethod();
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ package org.springframework.security.integration.multiannotation;
|
||||
* @author Luke Taylor
|
||||
*/
|
||||
public class PreAuthorizeServiceImpl implements PreAuthorizeService {
|
||||
|
||||
public void preAuthorizedMethod() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,10 +18,11 @@ package org.springframework.security.integration.multiannotation;
|
||||
import org.springframework.security.access.annotation.Secured;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Luke Taylor
|
||||
*/
|
||||
public interface SecuredService {
|
||||
|
||||
@Secured("ROLE_A")
|
||||
void securedMethod();
|
||||
|
||||
}
|
||||
|
||||
@@ -16,10 +16,11 @@
|
||||
package org.springframework.security.integration.multiannotation;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Luke Taylor
|
||||
*/
|
||||
public class SecuredServiceImpl implements SecuredService {
|
||||
|
||||
public void securedMethod() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,12 +21,11 @@ import org.springframework.security.access.prepost.PostInvocationAttribute;
|
||||
import org.springframework.security.access.prepost.PostInvocationAuthorizationAdvice;
|
||||
import org.springframework.security.core.Authentication;
|
||||
|
||||
public class PythonInterpreterPostInvocationAdvice implements
|
||||
PostInvocationAuthorizationAdvice {
|
||||
public class PythonInterpreterPostInvocationAdvice implements PostInvocationAuthorizationAdvice {
|
||||
|
||||
public Object after(Authentication authentication, MethodInvocation mi,
|
||||
PostInvocationAttribute pia, Object returnedObject)
|
||||
throws AccessDeniedException {
|
||||
public Object after(Authentication authentication, MethodInvocation mi, PostInvocationAttribute pia,
|
||||
Object returnedObject) throws AccessDeniedException {
|
||||
return returnedObject;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,12 +33,11 @@ import org.springframework.security.access.prepost.PreInvocationAuthorizationAdv
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
public class PythonInterpreterPreInvocationAdvice implements
|
||||
PreInvocationAuthorizationAdvice {
|
||||
public class PythonInterpreterPreInvocationAdvice implements PreInvocationAuthorizationAdvice {
|
||||
|
||||
private final ParameterNameDiscoverer parameterNameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
|
||||
|
||||
public boolean before(Authentication authentication, MethodInvocation mi,
|
||||
PreInvocationAttribute preAttr) {
|
||||
public boolean before(Authentication authentication, MethodInvocation mi, PreInvocationAttribute preAttr) {
|
||||
PythonInterpreterPreInvocationAttribute pythonAttr = (PythonInterpreterPreInvocationAttribute) preAttr;
|
||||
String script = pythonAttr.getScript();
|
||||
|
||||
@@ -46,8 +45,7 @@ public class PythonInterpreterPreInvocationAdvice implements
|
||||
python.set("authentication", authentication);
|
||||
python.set("args", createArgumentMap(mi));
|
||||
python.set("method", mi.getMethod().getName());
|
||||
Resource scriptResource = new PathMatchingResourcePatternResolver()
|
||||
.getResource(script);
|
||||
Resource scriptResource = new PathMatchingResourcePatternResolver().getResource(script);
|
||||
|
||||
try {
|
||||
python.execfile(scriptResource.getInputStream());
|
||||
@@ -68,8 +66,7 @@ public class PythonInterpreterPreInvocationAdvice implements
|
||||
private Map<String, Object> createArgumentMap(MethodInvocation mi) {
|
||||
Object[] args = mi.getArguments();
|
||||
Object targetObject = mi.getThis();
|
||||
Method method = ClassUtils.getMostSpecificMethod(mi.getMethod(),
|
||||
targetObject.getClass());
|
||||
Method method = ClassUtils.getMostSpecificMethod(mi.getMethod(), targetObject.getClass());
|
||||
String[] paramNames = parameterNameDiscoverer.getParameterNames(method);
|
||||
|
||||
Map<String, Object> argMap = new HashMap<>();
|
||||
@@ -79,4 +76,5 @@ public class PythonInterpreterPreInvocationAdvice implements
|
||||
|
||||
return argMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.security.integration.python;
|
||||
import org.springframework.security.access.prepost.PreInvocationAttribute;
|
||||
|
||||
public class PythonInterpreterPreInvocationAttribute implements PreInvocationAttribute {
|
||||
|
||||
private final String script;
|
||||
|
||||
PythonInterpreterPreInvocationAttribute(String script) {
|
||||
@@ -31,4 +32,5 @@ public class PythonInterpreterPreInvocationAttribute implements PreInvocationAtt
|
||||
public String getScript() {
|
||||
return script;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,20 +20,20 @@ import org.springframework.security.access.prepost.PostInvocationAttribute;
|
||||
import org.springframework.security.access.prepost.PreInvocationAttribute;
|
||||
import org.springframework.security.access.prepost.PrePostInvocationAttributeFactory;
|
||||
|
||||
public class PythonInterpreterPrePostInvocationAttributeFactory implements
|
||||
PrePostInvocationAttributeFactory {
|
||||
public class PythonInterpreterPrePostInvocationAttributeFactory implements PrePostInvocationAttributeFactory {
|
||||
|
||||
public PythonInterpreterPrePostInvocationAttributeFactory() {
|
||||
PythonInterpreter.initialize(System.getProperties(), null, new String[] {});
|
||||
}
|
||||
|
||||
public PreInvocationAttribute createPreInvocationAttribute(String preFilterAttribute,
|
||||
String filterObject, String preAuthorizeAttribute) {
|
||||
public PreInvocationAttribute createPreInvocationAttribute(String preFilterAttribute, String filterObject,
|
||||
String preAuthorizeAttribute) {
|
||||
return new PythonInterpreterPreInvocationAttribute(preAuthorizeAttribute);
|
||||
}
|
||||
|
||||
public PostInvocationAttribute createPostInvocationAttribute(
|
||||
String postFilterAttribute, String postAuthorizeAttribute) {
|
||||
public PostInvocationAttribute createPostInvocationAttribute(String postFilterAttribute,
|
||||
String postAuthorizeAttribute) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user