Apply Checkstyle WhitespaceAfterCheck module
This commit is contained in:
parent
523332d51f
commit
b6895e6359
|
@ -495,7 +495,7 @@ public class AclImplTests {
|
|||
assertThat(acl.isSidLoaded(Arrays.asList(new GrantedAuthoritySid("ROLE_IGNORED"),
|
||||
new PrincipalSid("ben"))))
|
||||
.isTrue();
|
||||
assertThat(acl.isSidLoaded(Arrays.asList((Sid)new GrantedAuthoritySid(
|
||||
assertThat(acl.isSidLoaded(Arrays.asList((Sid) new GrantedAuthoritySid(
|
||||
"ROLE_IGNORED"))))
|
||||
.isTrue();
|
||||
assertThat(acl.isSidLoaded(BEN)).isTrue();
|
||||
|
@ -507,7 +507,7 @@ public class AclImplTests {
|
|||
assertThat(acl.isSidLoaded(Arrays.asList((Sid) new GrantedAuthoritySid(
|
||||
"ROLE_GENERAL"), new GrantedAuthoritySid("ROLE_IGNORED"))))
|
||||
.isFalse();
|
||||
assertThat(acl.isSidLoaded(Arrays.asList((Sid)new GrantedAuthoritySid(
|
||||
assertThat(acl.isSidLoaded(Arrays.asList((Sid) new GrantedAuthoritySid(
|
||||
"ROLE_IGNORED"), new GrantedAuthoritySid("ROLE_GENERAL"))))
|
||||
.isFalse();
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ public class CasAuthenticationTokenMixinTests {
|
|||
@Test
|
||||
public void deserializeCasAuthenticationTestAfterEraseCredentialInvoked() throws Exception {
|
||||
CasAuthenticationToken token = mapper.readValue(CAS_TOKEN_CLEARED_JSON, CasAuthenticationToken.class);
|
||||
assertThat(((UserDetails)token.getPrincipal()).getPassword()).isNull();
|
||||
assertThat(((UserDetails) token.getPrincipal()).getPassword()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -64,7 +64,7 @@ public class LdapAuthenticationProviderConfigurer<B extends ProviderManagerBuild
|
|||
private String groupSearchFilter = "(uniqueMember={0})";
|
||||
private String rolePrefix = "ROLE_";
|
||||
private String userSearchBase = ""; // only for search
|
||||
private String userSearchFilter = null;// "uid={0}"; // only for search
|
||||
private String userSearchFilter = null; // "uid={0}"; // only for search
|
||||
private String[] userDnPatterns;
|
||||
private BaseLdapPathContextSource contextSource;
|
||||
private ContextSourceBuilder contextSourceBuilder = new ContextSourceBuilder();
|
||||
|
|
|
@ -50,7 +50,7 @@ class MethodSecurityMetadataSourceAdvisorRegistrar implements
|
|||
advisor.addConstructorArgReference("methodSecurityMetadataSource");
|
||||
advisor.addConstructorArgValue("methodSecurityMetadataSource");
|
||||
|
||||
MultiValueMap<String,Object> attributes = importingClassMetadata.getAllAnnotationAttributes(EnableGlobalMethodSecurity.class.getName());
|
||||
MultiValueMap<String, Object> attributes = importingClassMetadata.getAllAnnotationAttributes(EnableGlobalMethodSecurity.class.getName());
|
||||
Integer order = (Integer) attributes.getFirst("order");
|
||||
if(order != null) {
|
||||
advisor.addPropertyValue("order", order);
|
||||
|
@ -59,4 +59,4 @@ class MethodSecurityMetadataSourceAdvisorRegistrar implements
|
|||
registry.registerBeanDefinition("metaDataSourceAdvisor",
|
||||
advisor.getBeanDefinition());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -201,7 +201,7 @@ public final class JeeConfigurer<H extends HttpSecurityBuilder<H>> extends
|
|||
// @formatter:off
|
||||
http
|
||||
.authenticationProvider(authenticationProvider)
|
||||
.setSharedObject(AuthenticationEntryPoint.class,new Http403ForbiddenEntryPoint());
|
||||
.setSharedObject(AuthenticationEntryPoint.class, new Http403ForbiddenEntryPoint());
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
|
@ -259,4 +259,4 @@ public final class JeeConfigurer<H extends HttpSecurityBuilder<H>> extends
|
|||
detailsSource = postProcess(detailsSource);
|
||||
return detailsSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -163,7 +163,7 @@ public final class X509Configurer<H extends HttpSecurityBuilder<H>> extends
|
|||
|
||||
http
|
||||
.authenticationProvider(authenticationProvider)
|
||||
.setSharedObject(AuthenticationEntryPoint.class,new Http403ForbiddenEntryPoint());
|
||||
.setSharedObject(AuthenticationEntryPoint.class, new Http403ForbiddenEntryPoint());
|
||||
}
|
||||
// @formatter:on
|
||||
|
||||
|
@ -201,4 +201,4 @@ public final class X509Configurer<H extends HttpSecurityBuilder<H>> extends
|
|||
return authenticationUserDetailsService;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ public class UserDetailsResourceFactoryBean implements ResourceLoaderAware, Fact
|
|||
|
||||
@Override
|
||||
public void setResourceLoader(ResourceLoader resourceLoader) {
|
||||
Assert.notNull(resourceLoader,"resourceLoader cannot be null");
|
||||
Assert.notNull(resourceLoader, "resourceLoader cannot be null");
|
||||
this.resourceLoader = resourceLoader;
|
||||
}
|
||||
|
||||
|
|
|
@ -836,7 +836,7 @@ final class AuthenticationConfigBuilder {
|
|||
}
|
||||
|
||||
private static class CsrfTokenHiddenInputFunction implements
|
||||
Function<HttpServletRequest,Map<String,String>> {
|
||||
Function<HttpServletRequest, Map<String, String>> {
|
||||
|
||||
@Override
|
||||
public Map<String, String> apply(HttpServletRequest request) {
|
||||
|
|
|
@ -261,7 +261,7 @@ public class ServerHttpSecurity {
|
|||
List<WebFilter> sortedWebFilters = new ArrayList<>();
|
||||
this.webFilters.forEach( f -> {
|
||||
if(f instanceof OrderedWebFilter) {
|
||||
f = ((OrderedWebFilter)f).webFilter;
|
||||
f = ((OrderedWebFilter) f).webFilter;
|
||||
}
|
||||
sortedWebFilters.add(f);
|
||||
});
|
||||
|
@ -354,11 +354,11 @@ public class ServerHttpSecurity {
|
|||
public final class Access {
|
||||
|
||||
public AuthorizeExchangeSpec permitAll() {
|
||||
return access( (a,e) -> Mono.just(new AuthorizationDecision(true)));
|
||||
return access( (a, e) -> Mono.just(new AuthorizationDecision(true)));
|
||||
}
|
||||
|
||||
public AuthorizeExchangeSpec denyAll() {
|
||||
return access( (a,e) -> Mono.just(new AuthorizationDecision(false)));
|
||||
return access( (a, e) -> Mono.just(new AuthorizationDecision(false)));
|
||||
}
|
||||
|
||||
public AuthorizeExchangeSpec hasRole(String role) {
|
||||
|
|
|
@ -26,7 +26,7 @@ public class DisableUseExpressionsConfig extends BaseWebConfig {
|
|||
// This config is also on UrlAuthorizationConfigurer javadoc
|
||||
http
|
||||
.apply(new UrlAuthorizationConfigurer<HttpSecurity>(getApplicationContext())).getRegistry()
|
||||
.antMatchers("/users**","/sessions/**").hasRole("USER")
|
||||
.antMatchers("/users**", "/sessions/**").hasRole("USER")
|
||||
.antMatchers("/signup").hasRole("ANONYMOUS")
|
||||
.anyRequest().hasRole("USER");
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ public class ExpressionUrlAuthorizationConfigurerConfigs {
|
|||
.expressionHandler(handler)
|
||||
.accessDecisionManager(adm)
|
||||
.filterSecurityInterceptorOncePerRequest(true)
|
||||
.antMatchers("/a","/b").hasRole("ADMIN")
|
||||
.antMatchers("/a", "/b").hasRole("ADMIN")
|
||||
.anyRequest().permitAll()
|
||||
.and()
|
||||
.formLogin();
|
||||
|
|
|
@ -47,8 +47,8 @@ public class EnableReactiveMethodSecurityTests {
|
|||
ReactiveMessageService delegate;
|
||||
TestPublisher<String> result = TestPublisher.create();
|
||||
|
||||
Context withAdmin = ReactiveSecurityContextHolder.withAuthentication(new TestingAuthenticationToken("admin","password","ROLE_USER", "ROLE_ADMIN"));
|
||||
Context withUser = ReactiveSecurityContextHolder.withAuthentication(new TestingAuthenticationToken("user","password","ROLE_USER"));
|
||||
Context withAdmin = ReactiveSecurityContextHolder.withAuthentication(new TestingAuthenticationToken("admin", "password", "ROLE_USER", "ROLE_ADMIN"));
|
||||
Context withUser = ReactiveSecurityContextHolder.withAuthentication(new TestingAuthenticationToken("user", "password", "ROLE_USER"));
|
||||
|
||||
@After
|
||||
public void cleanup() {
|
||||
|
|
|
@ -70,7 +70,7 @@ public class HttpSecurityHeadersTests {
|
|||
public void headerWhenSpringMvcResourceThenCacheRelatedHeadersReset() throws Exception {
|
||||
mockMvc.perform(get("/resources/file.js"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(header().string(HttpHeaders.CACHE_CONTROL,"max-age=12345"))
|
||||
.andExpect(header().string(HttpHeaders.CACHE_CONTROL, "max-age=12345"))
|
||||
.andExpect(header().string(HttpHeaders.PRAGMA, ""))
|
||||
.andExpect(header().string(HttpHeaders.EXPIRES, ""));
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ public class HttpSecurityHeadersTests {
|
|||
@Test
|
||||
public void headerWhenNotSpringResourceThenCacheRelatedHeadersSet() throws Exception {
|
||||
mockMvc.perform(get("/notresource"))
|
||||
.andExpect(header().string(HttpHeaders.CACHE_CONTROL,"no-cache, no-store, max-age=0, must-revalidate"))
|
||||
.andExpect(header().string(HttpHeaders.CACHE_CONTROL, "no-cache, no-store, max-age=0, must-revalidate"))
|
||||
.andExpect(header().string(HttpHeaders.PRAGMA, "no-cache"))
|
||||
.andExpect(header().string(HttpHeaders.EXPIRES, "0"));
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ public class WebSecurityConfigurerAdapterPowermockTests {
|
|||
}
|
||||
}
|
||||
|
||||
static class DefaultConfigurer extends AbstractHttpConfigurer<DefaultConfigurer,HttpSecurity> {
|
||||
static class DefaultConfigurer extends AbstractHttpConfigurer<DefaultConfigurer, HttpSecurity> {
|
||||
boolean init;
|
||||
boolean configure;
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ public class HttpSecurityLogoutTests {
|
|||
loadConfig(ClearAuthenticationFalseConfig.class);
|
||||
|
||||
SecurityContext currentContext = SecurityContextHolder.createEmptyContext();
|
||||
currentContext.setAuthentication(new TestingAuthenticationToken("user", "password","ROLE_USER"));
|
||||
currentContext.setAuthentication(new TestingAuthenticationToken("user", "password", "ROLE_USER"));
|
||||
|
||||
request.getSession().setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, currentContext);
|
||||
request.setMethod("POST");
|
||||
|
|
|
@ -134,7 +134,7 @@ public class EnableWebFluxSecurityTests {
|
|||
.switchIfEmpty(chain.filter(exchange))
|
||||
.flatMap(e -> chain.filter(exchange)),
|
||||
this.springSecurityFilterChain,
|
||||
(exchange,chain) ->
|
||||
(exchange, chain) ->
|
||||
ReactiveSecurityContextHolder.getContext()
|
||||
.map(SecurityContext::getAuthentication)
|
||||
.flatMap( principal -> exchange.getResponse()
|
||||
|
@ -154,7 +154,7 @@ public class EnableWebFluxSecurityTests {
|
|||
this.spring.register(Config.class).autowire();
|
||||
WebTestClient client = WebTestClientBuilder.bindToWebFilters(
|
||||
this.springSecurityFilterChain,
|
||||
(exchange,chain) ->
|
||||
(exchange, chain) ->
|
||||
ReactiveSecurityContextHolder.getContext()
|
||||
.map(SecurityContext::getAuthentication)
|
||||
.flatMap( principal -> exchange.getResponse()
|
||||
|
@ -166,7 +166,7 @@ public class EnableWebFluxSecurityTests {
|
|||
client
|
||||
.get()
|
||||
.uri("/")
|
||||
.attributes(basicAuthenticationCredentials("user","password"))
|
||||
.attributes(basicAuthenticationCredentials("user", "password"))
|
||||
.exchange()
|
||||
.expectStatus().isOk()
|
||||
.expectBody(String.class).consumeWith( result -> assertThat(result.getResponseBody()).isEqualTo("user"));
|
||||
|
@ -191,7 +191,7 @@ public class EnableWebFluxSecurityTests {
|
|||
this.spring.register(CustomPasswordEncoderConfig.class).autowire();
|
||||
WebTestClient client = WebTestClientBuilder.bindToWebFilters(
|
||||
this.springSecurityFilterChain,
|
||||
(exchange,chain) ->
|
||||
(exchange, chain) ->
|
||||
ReactiveSecurityContextHolder.getContext()
|
||||
.map(SecurityContext::getAuthentication)
|
||||
.flatMap( principal -> exchange.getResponse()
|
||||
|
@ -203,7 +203,7 @@ public class EnableWebFluxSecurityTests {
|
|||
client
|
||||
.get()
|
||||
.uri("/")
|
||||
.attributes(basicAuthenticationCredentials("user","password"))
|
||||
.attributes(basicAuthenticationCredentials("user", "password"))
|
||||
.exchange()
|
||||
.expectStatus().isOk()
|
||||
.expectBody(String.class).consumeWith( result -> assertThat(result.getResponseBody()).isEqualTo("user"));
|
||||
|
@ -231,7 +231,7 @@ public class EnableWebFluxSecurityTests {
|
|||
this.spring.register(Config.class).autowire();
|
||||
WebTestClient client = WebTestClientBuilder.bindToWebFilters(
|
||||
this.springSecurityFilterChain,
|
||||
(exchange,chain) ->
|
||||
(exchange, chain) ->
|
||||
Mono.subscriberContext()
|
||||
.flatMap( c -> c.<Mono<Principal>>get(Authentication.class))
|
||||
.flatMap( principal -> exchange.getResponse()
|
||||
|
|
|
@ -91,7 +91,7 @@ public class JdbcUserServiceBeanDefinitionParserTests {
|
|||
+ "'/>" + DATA_SOURCE);
|
||||
JdbcUserDetailsManager mgr = (JdbcUserDetailsManager) appContext
|
||||
.getBean("myUserService");
|
||||
assertThat(FieldUtils.getFieldValue(mgr,"usersByUsernameQuery")).isEqualTo(userQuery);
|
||||
assertThat(FieldUtils.getFieldValue(mgr, "usersByUsernameQuery")).isEqualTo(userQuery);
|
||||
assertThat(FieldUtils.getFieldValue(mgr, "authoritiesByUsernameQuery")).isEqualTo(authoritiesQuery);
|
||||
assertThat(mgr.loadUserByUsername("rod") != null).isTrue();
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ public class HttpInterceptUrlTests {
|
|||
}
|
||||
|
||||
private void loadConfig(String... configLocations) {
|
||||
for(int i=0;i<configLocations.length;i++) {
|
||||
for(int i=0; i<configLocations.length; i++) {
|
||||
configLocations[i] = getClass().getName().replaceAll("\\.", "/") + "-" + configLocations[i];
|
||||
}
|
||||
XmlWebApplicationContext context = new XmlWebApplicationContext();
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.springframework.security.web.DefaultSecurityFilterChain;
|
|||
* @author Rob Winch
|
||||
*
|
||||
*/
|
||||
public class CustomConfigurer extends SecurityConfigurerAdapter<DefaultSecurityFilterChain,HttpSecurity> {
|
||||
public class CustomConfigurer extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {
|
||||
|
||||
@Value("${permitAllPattern}")
|
||||
private String permitAllPattern;
|
||||
|
@ -64,4 +64,4 @@ public class CustomConfigurer extends SecurityConfigurerAdapter<DefaultSecurityF
|
|||
public static CustomConfigurer customConfigurer() {
|
||||
return new CustomConfigurer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,7 +134,7 @@ public class HeaderSpecTests {
|
|||
.exchange()
|
||||
.returnResult(String.class);
|
||||
|
||||
Map<String,List<String>> responseHeaders = response.getResponseHeaders();
|
||||
Map<String, List<String>> responseHeaders = response.getResponseHeaders();
|
||||
this.ignoredHeaderNames.stream().forEach(responseHeaders::remove);
|
||||
|
||||
assertThat(responseHeaders).describedAs(response.toString()).isEqualTo(
|
||||
|
|
|
@ -85,8 +85,8 @@ final class HtmlUnitWebTestClient {
|
|||
return request.body(BodyInserters.fromObject(requestBody));
|
||||
}
|
||||
|
||||
private MultiValueMap<String,String> formData(List<NameValuePair> params) {
|
||||
MultiValueMap<String,String> result = new LinkedMultiValueMap<>(params.size());
|
||||
private MultiValueMap<String, String> formData(List<NameValuePair> params) {
|
||||
MultiValueMap<String, String> result = new LinkedMultiValueMap<>(params.size());
|
||||
params.forEach( pair -> result.add(pair.getName(), pair.getValue()));
|
||||
return result;
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ final class HtmlUnitWebTestClient {
|
|||
}
|
||||
|
||||
private void headers(WebTestClient.RequestBodySpec request, WebRequest webRequest) {
|
||||
webRequest.getAdditionalHeaders().forEach( (name,value) -> request.header(name, value));
|
||||
webRequest.getAdditionalHeaders().forEach( (name, value) -> request.header(name, value));
|
||||
}
|
||||
|
||||
private HttpMethod httpMethod(WebRequest webRequest) {
|
||||
|
@ -191,8 +191,8 @@ final class HtmlUnitWebTestClient {
|
|||
}).build();
|
||||
}
|
||||
|
||||
private MultiValueMap<String,String> clientCookies() {
|
||||
MultiValueMap<String,String> result = new LinkedMultiValueMap<>(this.cookies.size());
|
||||
private MultiValueMap<String, String> clientCookies() {
|
||||
MultiValueMap<String, String> result = new LinkedMultiValueMap<>(this.cookies.size());
|
||||
this.cookies.values().forEach( cookie ->
|
||||
result.add(cookie.getName(), cookie.getValue())
|
||||
);
|
||||
|
|
|
@ -47,7 +47,7 @@ public class ReactiveSecurityContextHolder {
|
|||
* @return Return a {@code Mono<Void>} which only replays complete and error signals
|
||||
* from clearing the context.
|
||||
*/
|
||||
public static Function<Context,Context> clearContext() {
|
||||
public static Function<Context, Context> clearContext() {
|
||||
return context -> context.delete(SECURITY_CONTEXT_KEY);
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ public class SessionRegistryImpl implements SessionRegistry,
|
|||
this.sessionIds = new ConcurrentHashMap<String, SessionInformation>();
|
||||
}
|
||||
|
||||
public SessionRegistryImpl(ConcurrentMap<Object, Set<String>> principals,Map<String, SessionInformation> sessionIds) {
|
||||
public SessionRegistryImpl(ConcurrentMap<Object, Set<String>> principals, Map<String, SessionInformation> sessionIds) {
|
||||
this.principals=principals;
|
||||
this.sessionIds=sessionIds;
|
||||
}
|
||||
|
|
|
@ -31,9 +31,9 @@ import reactor.core.publisher.Mono;
|
|||
* @since 5.0
|
||||
*/
|
||||
public class MapReactiveUserDetailsService implements ReactiveUserDetailsService {
|
||||
private final Map<String,UserDetails> users;
|
||||
private final Map<String, UserDetails> users;
|
||||
|
||||
public MapReactiveUserDetailsService(Map<String,UserDetails> users) {
|
||||
public MapReactiveUserDetailsService(Map<String, UserDetails> users) {
|
||||
this.users = users;
|
||||
}
|
||||
|
||||
|
|
|
@ -293,7 +293,7 @@ public class User implements UserDetails, CredentialsContainer {
|
|||
private boolean accountLocked;
|
||||
private boolean credentialsExpired;
|
||||
private boolean disabled;
|
||||
private Function<String,String> passwordEncoder = password -> password;
|
||||
private Function<String, String> passwordEncoder = password -> password;
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
|
@ -335,7 +335,7 @@ public class User implements UserDetails, CredentialsContainer {
|
|||
* @return the {@link UserBuilder} for method chaining (i.e. to populate
|
||||
* additional attributes for this user)
|
||||
*/
|
||||
public UserBuilder passwordEncoder(Function<String,String> encoder) {
|
||||
public UserBuilder passwordEncoder(Function<String, String> encoder) {
|
||||
Assert.notNull(encoder, "encoder cannot be null");
|
||||
this.passwordEncoder = encoder;
|
||||
return this;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -248,7 +248,7 @@ public class SecuredAnnotationSecurityMetadataSourceTests {
|
|||
class CustomAnnotatedServiceImpl implements CustomAnnotatedService {
|
||||
}
|
||||
|
||||
enum SecurityEnum implements ConfigAttribute,GrantedAuthority {
|
||||
enum SecurityEnum implements ConfigAttribute, GrantedAuthority {
|
||||
ADMIN, USER;
|
||||
|
||||
public String getAttribute() {
|
||||
|
|
|
@ -88,7 +88,7 @@ public class MethodExpressionVoterTests {
|
|||
am.vote(joe, mi, createAttributes(new PreInvocationExpressionAttribute(
|
||||
"(filterObject == 'joe' or filterObject == 'sam')", "collection",
|
||||
"permitAll")));
|
||||
assertThat(arg).containsExactly("joe","sam");
|
||||
assertThat(arg).containsExactly("joe", "sam");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
|
|
|
@ -85,8 +85,8 @@ public class SpringSecurityCoreVersionTests {
|
|||
String version = "1";
|
||||
spy(SpringSecurityCoreVersion.class);
|
||||
spy(SpringVersion.class);
|
||||
doReturn(version).when(SpringSecurityCoreVersion.class,"getVersion");
|
||||
doReturn(version).when(SpringVersion.class,"getVersion");
|
||||
doReturn(version).when(SpringSecurityCoreVersion.class, "getVersion");
|
||||
doReturn(version).when(SpringVersion.class, "getVersion");
|
||||
|
||||
performChecks();
|
||||
|
||||
|
@ -97,8 +97,8 @@ public class SpringSecurityCoreVersionTests {
|
|||
public void noLoggingIfSpringVersionNull() throws Exception {
|
||||
spy(SpringSecurityCoreVersion.class);
|
||||
spy(SpringVersion.class);
|
||||
doReturn("1").when(SpringSecurityCoreVersion.class,"getVersion");
|
||||
doReturn(null).when(SpringVersion.class,"getVersion");
|
||||
doReturn("1").when(SpringSecurityCoreVersion.class, "getVersion");
|
||||
doReturn(null).when(SpringVersion.class, "getVersion");
|
||||
|
||||
performChecks();
|
||||
|
||||
|
@ -109,8 +109,8 @@ public class SpringSecurityCoreVersionTests {
|
|||
public void warnIfSpringVersionTooSmall() throws Exception {
|
||||
spy(SpringSecurityCoreVersion.class);
|
||||
spy(SpringVersion.class);
|
||||
doReturn("3").when(SpringSecurityCoreVersion.class,"getVersion");
|
||||
doReturn("2").when(SpringVersion.class,"getVersion");
|
||||
doReturn("3").when(SpringSecurityCoreVersion.class, "getVersion");
|
||||
doReturn("2").when(SpringVersion.class, "getVersion");
|
||||
|
||||
performChecks();
|
||||
|
||||
|
@ -121,8 +121,8 @@ public class SpringSecurityCoreVersionTests {
|
|||
public void noWarnIfSpringVersionLarger() throws Exception {
|
||||
spy(SpringSecurityCoreVersion.class);
|
||||
spy(SpringVersion.class);
|
||||
doReturn("4.0.0.RELEASE").when(SpringSecurityCoreVersion.class,"getVersion");
|
||||
doReturn("4.0.0.RELEASE").when(SpringVersion.class,"getVersion");
|
||||
doReturn("4.0.0.RELEASE").when(SpringSecurityCoreVersion.class, "getVersion");
|
||||
doReturn("4.0.0.RELEASE").when(SpringVersion.class, "getVersion");
|
||||
|
||||
performChecks();
|
||||
|
||||
|
@ -135,8 +135,8 @@ public class SpringSecurityCoreVersionTests {
|
|||
String minSpringVersion = "3.2.8.RELEASE";
|
||||
spy(SpringSecurityCoreVersion.class);
|
||||
spy(SpringVersion.class);
|
||||
doReturn("3.2.0.RELEASE").when(SpringSecurityCoreVersion.class,"getVersion");
|
||||
doReturn("3.2.10.RELEASE").when(SpringVersion.class,"getVersion");
|
||||
doReturn("3.2.0.RELEASE").when(SpringSecurityCoreVersion.class, "getVersion");
|
||||
doReturn("3.2.10.RELEASE").when(SpringVersion.class, "getVersion");
|
||||
|
||||
performChecks(minSpringVersion);
|
||||
|
||||
|
@ -147,8 +147,8 @@ public class SpringSecurityCoreVersionTests {
|
|||
public void noLoggingIfPropertySet() throws Exception {
|
||||
spy(SpringSecurityCoreVersion.class);
|
||||
spy(SpringVersion.class);
|
||||
doReturn("3").when(SpringSecurityCoreVersion.class,"getVersion");
|
||||
doReturn("2").when(SpringVersion.class,"getVersion");
|
||||
doReturn("3").when(SpringSecurityCoreVersion.class, "getVersion");
|
||||
doReturn("2").when(SpringVersion.class, "getVersion");
|
||||
System.setProperty(getDisableChecksProperty(), Boolean.TRUE.toString());
|
||||
|
||||
performChecks();
|
||||
|
|
|
@ -25,7 +25,7 @@ import java.util.function.Function;
|
|||
public class PasswordEncodedUser {
|
||||
private static final UserDetails USER = withUsername("user").password("password").roles("USER").build();
|
||||
|
||||
private static final UserDetails ADMIN = withUsername("admin").password("password").roles("USER","ADMIN").build();
|
||||
private static final UserDetails ADMIN = withUsername("admin").password("password").roles("USER", "ADMIN").build();
|
||||
|
||||
public static UserDetails user() {
|
||||
return User.withUserDetails(USER).build();
|
||||
|
@ -48,7 +48,7 @@ public class PasswordEncodedUser {
|
|||
.passwordEncoder(passwordEncoder());
|
||||
}
|
||||
|
||||
private static Function<String,String> passwordEncoder() {
|
||||
private static Function<String, String> passwordEncoder() {
|
||||
return rawPassword -> "{noop}" + rawPassword;
|
||||
}
|
||||
|
||||
|
|
|
@ -150,7 +150,7 @@ public class UserTests {
|
|||
|
||||
@Test
|
||||
public void withUserDetailsWhenAllEnabled() throws Exception {
|
||||
User expected = new User("rob","pass", true, true, true, true, ROLE_12);
|
||||
User expected = new User("rob", "pass", true, true, true, true, ROLE_12);
|
||||
|
||||
UserDetails actual = User.withUserDetails(expected).build();
|
||||
|
||||
|
@ -166,7 +166,7 @@ public class UserTests {
|
|||
|
||||
@Test
|
||||
public void withUserDetailsWhenAllDisabled() throws Exception {
|
||||
User expected = new User("rob","pass", false, false, false, false, ROLE_12);
|
||||
User expected = new User("rob", "pass", false, false, false, false, ROLE_12);
|
||||
|
||||
UserDetails actual = User.withUserDetails(expected).build();
|
||||
|
||||
|
|
|
@ -107,8 +107,8 @@ public class RememberMeAuthenticationTokenMixinTests extends AbstractMixinTests
|
|||
.readValue(String.format(REMEMBERME_AUTH_JSON, "\"password\""), RememberMeAuthenticationToken.class);
|
||||
assertThat(token).isNotNull();
|
||||
assertThat(token.getPrincipal()).isNotNull().isInstanceOf(User.class);
|
||||
assertThat(((User)token.getPrincipal()).getUsername()).isEqualTo("admin");
|
||||
assertThat(((User)token.getPrincipal()).getPassword()).isEqualTo("1234");
|
||||
assertThat(((User) token.getPrincipal()).getUsername()).isEqualTo("admin");
|
||||
assertThat(((User) token.getPrincipal()).getPassword()).isEqualTo("1234");
|
||||
assertThat(((User) token.getPrincipal()).getAuthorities()).hasSize(1).contains(new SimpleGrantedAuthority("ROLE_USER"));
|
||||
assertThat(token.getAuthorities()).hasSize(1).contains(new SimpleGrantedAuthority("ROLE_USER"));
|
||||
assertThat(((User) token.getPrincipal()).isEnabled()).isEqualTo(true);
|
||||
|
|
|
@ -120,7 +120,7 @@ public class UsernamePasswordAuthenticationTokenMixinTests extends AbstractMixin
|
|||
.readValue(AUTHENTICATED_JSON, UsernamePasswordAuthenticationToken.class);
|
||||
assertThat(token).isNotNull();
|
||||
assertThat(token.getPrincipal()).isNotNull().isInstanceOf(User.class);
|
||||
assertThat(((User)token.getPrincipal()).getAuthorities()).isNotNull().hasSize(1).contains(new SimpleGrantedAuthority("ROLE_USER"));
|
||||
assertThat(((User) token.getPrincipal()).getAuthorities()).isNotNull().hasSize(1).contains(new SimpleGrantedAuthority("ROLE_USER"));
|
||||
assertThat(token.isAuthenticated()).isEqualTo(true);
|
||||
assertThat(token.getAuthorities()).hasSize(1).contains(new SimpleGrantedAuthority("ROLE_USER"));
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ public class PasswordEncoderFactories {
|
|||
*/
|
||||
public static PasswordEncoder createDelegatingPasswordEncoder() {
|
||||
String encodingId = "bcrypt";
|
||||
Map<String,PasswordEncoder> encoders = new HashMap<>();
|
||||
Map<String, PasswordEncoder> encoders = new HashMap<>();
|
||||
encoders.put(encodingId, new BCryptPasswordEncoder());
|
||||
encoders.put("ldap", new LdapShaPasswordEncoder());
|
||||
encoders.put("MD4", new Md4PasswordEncoder());
|
||||
|
|
|
@ -123,7 +123,7 @@ public class DelegatingPasswordEncoder implements PasswordEncoder {
|
|||
private static final String SUFFIX = "}";
|
||||
private final String idForEncode;
|
||||
private final PasswordEncoder passwordEncoderForEncode;
|
||||
private final Map<String,PasswordEncoder> idToPasswordEncoder;
|
||||
private final Map<String, PasswordEncoder> idToPasswordEncoder;
|
||||
private PasswordEncoder defaultPasswordEncoderForMatches = new UnmappedIdPasswordEncoder();
|
||||
|
||||
/**
|
||||
|
|
|
@ -34,7 +34,7 @@ public class HexTests {
|
|||
@Test
|
||||
public void encode() {
|
||||
assertThat(Hex.encode(new byte[] { (byte) 'A', (byte) 'B', (byte) 'C',
|
||||
(byte) 'D' })).isEqualTo(new char[] {'4','1','4','2','4','3','4','4'});
|
||||
(byte) 'D' })).isEqualTo(new char[] {'4', '1', '4', '2', '4', '3', '4', '4'});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -55,7 +55,7 @@ public class DelegatingPasswordEncoderTests {
|
|||
|
||||
private String noopEncodedPassword = "{noop}" + this.encodedPassword;
|
||||
|
||||
private Map<String,PasswordEncoder> delegates;
|
||||
private Map<String, PasswordEncoder> delegates;
|
||||
|
||||
private DelegatingPasswordEncoder passwordEncoder;
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ public class LdapShaPasswordEncoderTests {
|
|||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void invalidPrefixIsRejected() {
|
||||
this.sha.matches("somepassword","{MD9}xxxxxxxxxx");
|
||||
this.sha.matches("somepassword", "{MD9}xxxxxxxxxx");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
|
|
|
@ -1,120 +1,120 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.security.crypto.scrypt;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Shazin Sadakath
|
||||
*
|
||||
*/
|
||||
public class SCryptPasswordEncoderTests {
|
||||
|
||||
@Test
|
||||
public void matches() {
|
||||
SCryptPasswordEncoder encoder = new SCryptPasswordEncoder();
|
||||
String result = encoder.encode("password");
|
||||
assertThat(result).isNotEqualTo("password");
|
||||
assertThat(encoder.matches("password", result)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unicode() {
|
||||
SCryptPasswordEncoder encoder = new SCryptPasswordEncoder();
|
||||
String result = encoder.encode("passw\u9292rd");
|
||||
assertThat(encoder.matches("pass\u9292\u9292rd", result)).isFalse();
|
||||
assertThat(encoder.matches("passw\u9292rd", result)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notMatches() {
|
||||
SCryptPasswordEncoder encoder = new SCryptPasswordEncoder();
|
||||
String result = encoder.encode("password");
|
||||
assertThat(encoder.matches("bogus", result)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customParameters() {
|
||||
SCryptPasswordEncoder encoder = new SCryptPasswordEncoder(512, 8, 4, 32, 16);
|
||||
String result = encoder.encode("password");
|
||||
assertThat(result).isNotEqualTo("password");
|
||||
assertThat(encoder.matches("password", result)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void differentPasswordHashes() {
|
||||
SCryptPasswordEncoder encoder = new SCryptPasswordEncoder();
|
||||
String password = "secret";
|
||||
assertThat(encoder.encode(password)).isNotEqualTo(encoder.encode(password));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void samePasswordWithDifferentParams() {
|
||||
SCryptPasswordEncoder oldEncoder = new SCryptPasswordEncoder(16384, 8, 1, 32,64);
|
||||
SCryptPasswordEncoder newEncoder = new SCryptPasswordEncoder();
|
||||
|
||||
String password = "secret";
|
||||
String oldEncodedPassword = oldEncoder.encode(password);
|
||||
assertThat(newEncoder.matches(password, oldEncodedPassword)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesntMatchNullEncodedValue() {
|
||||
SCryptPasswordEncoder encoder = new SCryptPasswordEncoder();
|
||||
assertThat(encoder.matches("password", null)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesntMatchEmptyEncodedValue() {
|
||||
SCryptPasswordEncoder encoder = new SCryptPasswordEncoder();
|
||||
assertThat(encoder.matches("password", "")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesntMatchBogusEncodedValue() {
|
||||
SCryptPasswordEncoder encoder = new SCryptPasswordEncoder();
|
||||
assertThat(encoder.matches("password", "012345678901234567890123456789")).isFalse();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void invalidCpuCostParameter() {
|
||||
new SCryptPasswordEncoder(Integer.MIN_VALUE, 16, 2, 32, 16);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void invalidMemoryCostParameter() {
|
||||
new SCryptPasswordEncoder(2, Integer.MAX_VALUE, 2, 32, 16);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void invalidParallelizationParameter() {
|
||||
new SCryptPasswordEncoder(2, 8, Integer.MAX_VALUE, 32, 16);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void invalidSaltLengthParameter() {
|
||||
new SCryptPasswordEncoder(2, 8, 1, 16, -1);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void invalidKeyLengthParameter() {
|
||||
new SCryptPasswordEncoder(2, 8, 1, -1, 16);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.security.crypto.scrypt;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Shazin Sadakath
|
||||
*
|
||||
*/
|
||||
public class SCryptPasswordEncoderTests {
|
||||
|
||||
@Test
|
||||
public void matches() {
|
||||
SCryptPasswordEncoder encoder = new SCryptPasswordEncoder();
|
||||
String result = encoder.encode("password");
|
||||
assertThat(result).isNotEqualTo("password");
|
||||
assertThat(encoder.matches("password", result)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unicode() {
|
||||
SCryptPasswordEncoder encoder = new SCryptPasswordEncoder();
|
||||
String result = encoder.encode("passw\u9292rd");
|
||||
assertThat(encoder.matches("pass\u9292\u9292rd", result)).isFalse();
|
||||
assertThat(encoder.matches("passw\u9292rd", result)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notMatches() {
|
||||
SCryptPasswordEncoder encoder = new SCryptPasswordEncoder();
|
||||
String result = encoder.encode("password");
|
||||
assertThat(encoder.matches("bogus", result)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customParameters() {
|
||||
SCryptPasswordEncoder encoder = new SCryptPasswordEncoder(512, 8, 4, 32, 16);
|
||||
String result = encoder.encode("password");
|
||||
assertThat(result).isNotEqualTo("password");
|
||||
assertThat(encoder.matches("password", result)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void differentPasswordHashes() {
|
||||
SCryptPasswordEncoder encoder = new SCryptPasswordEncoder();
|
||||
String password = "secret";
|
||||
assertThat(encoder.encode(password)).isNotEqualTo(encoder.encode(password));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void samePasswordWithDifferentParams() {
|
||||
SCryptPasswordEncoder oldEncoder = new SCryptPasswordEncoder(16384, 8, 1, 32, 64);
|
||||
SCryptPasswordEncoder newEncoder = new SCryptPasswordEncoder();
|
||||
|
||||
String password = "secret";
|
||||
String oldEncodedPassword = oldEncoder.encode(password);
|
||||
assertThat(newEncoder.matches(password, oldEncodedPassword)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesntMatchNullEncodedValue() {
|
||||
SCryptPasswordEncoder encoder = new SCryptPasswordEncoder();
|
||||
assertThat(encoder.matches("password", null)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesntMatchEmptyEncodedValue() {
|
||||
SCryptPasswordEncoder encoder = new SCryptPasswordEncoder();
|
||||
assertThat(encoder.matches("password", "")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesntMatchBogusEncodedValue() {
|
||||
SCryptPasswordEncoder encoder = new SCryptPasswordEncoder();
|
||||
assertThat(encoder.matches("password", "012345678901234567890123456789")).isFalse();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void invalidCpuCostParameter() {
|
||||
new SCryptPasswordEncoder(Integer.MIN_VALUE, 16, 2, 32, 16);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void invalidMemoryCostParameter() {
|
||||
new SCryptPasswordEncoder(2, Integer.MAX_VALUE, 2, 32, 16);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void invalidParallelizationParameter() {
|
||||
new SCryptPasswordEncoder(2, 8, Integer.MAX_VALUE, 32, 16);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void invalidSaltLengthParameter() {
|
||||
new SCryptPasswordEncoder(2, 8, 1, 16, -1);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void invalidKeyLengthParameter() {
|
||||
new SCryptPasswordEncoder(2, 8, 1, -1, 16);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -40,5 +40,8 @@
|
|||
<property name="illegalPattern" value="true"/>
|
||||
<property name="message" value="Trailing whitespace"/>
|
||||
</module>
|
||||
|
||||
<!-- Whitespace -->
|
||||
<module name="WhitespaceAfterCheck" />
|
||||
</module>
|
||||
</module>
|
||||
|
|
|
@ -47,7 +47,7 @@ public class ConcurrentSessionManagementTests extends AbstractWebServerIntegrati
|
|||
final MockHttpSession session1 = new MockHttpSession();
|
||||
final MockHttpSession session2 = new MockHttpSession();
|
||||
|
||||
MockMvc mockMvc = createMockMvc("classpath:/spring/http-security-concurrency.xml","classpath:/spring/in-memory-provider.xml", "classpath:/spring/testapp-servlet.xml");
|
||||
MockMvc mockMvc = createMockMvc("classpath:/spring/http-security-concurrency.xml", "classpath:/spring/in-memory-provider.xml", "classpath:/spring/testapp-servlet.xml");
|
||||
|
||||
mockMvc.perform(get("secure/index").session(session1))
|
||||
.andExpect(status().is3xxRedirection());
|
||||
|
|
|
@ -127,7 +127,7 @@ public final class PasswordComparisonAuthenticator extends AbstractLdapAuthentic
|
|||
return null;
|
||||
}
|
||||
if(passwordAttrValue instanceof byte[]) {
|
||||
return new String((byte[])passwordAttrValue);
|
||||
return new String((byte[]) passwordAttrValue);
|
||||
}
|
||||
return String.valueOf(passwordAttrValue);
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public class LdapUtilsTests {
|
|||
|
||||
when(mockCtx.getNameInNamespace()).thenReturn("dc=springframework,dc=org");
|
||||
|
||||
assertThat(LdapUtils.getRelativeName("dc=springframework,dc=org",mockCtx)).isEqualTo("");
|
||||
assertThat(LdapUtils.getRelativeName("dc=springframework,dc=org", mockCtx)).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -125,7 +125,7 @@ public class OAuth2AuthorizationRequestRedirectFilter extends OncePerRequestFilt
|
|||
|
||||
String redirectUriStr = this.expandRedirectUri(request, clientRegistration);
|
||||
|
||||
Map<String,Object> additionalParameters = new HashMap<>();
|
||||
Map<String, Object> additionalParameters = new HashMap<>();
|
||||
additionalParameters.put(OAuth2ParameterNames.REGISTRATION_ID, clientRegistration.getRegistrationId());
|
||||
|
||||
OAuth2AuthorizationRequest.Builder builder;
|
||||
|
|
|
@ -117,7 +117,7 @@ public class OAuth2LoginAuthenticationFilter extends AbstractAuthenticationProce
|
|||
}
|
||||
this.authorizationRequestRepository.removeAuthorizationRequest(request);
|
||||
|
||||
String registrationId = (String)authorizationRequest.getAdditionalParameters().get(OAuth2ParameterNames.REGISTRATION_ID);
|
||||
String registrationId = (String) authorizationRequest.getAdditionalParameters().get(OAuth2ParameterNames.REGISTRATION_ID);
|
||||
ClientRegistration clientRegistration = this.clientRegistrationRepository.findByRegistrationId(registrationId);
|
||||
|
||||
OAuth2LoginAuthenticationToken authenticationRequest = new OAuth2LoginAuthenticationToken(
|
||||
|
@ -125,7 +125,7 @@ public class OAuth2LoginAuthenticationFilter extends AbstractAuthenticationProce
|
|||
authenticationRequest.setDetails(this.authenticationDetailsSource.buildDetails(request));
|
||||
|
||||
OAuth2LoginAuthenticationToken authenticationResult =
|
||||
(OAuth2LoginAuthenticationToken)this.getAuthenticationManager().authenticate(authenticationRequest);
|
||||
(OAuth2LoginAuthenticationToken) this.getAuthenticationManager().authenticate(authenticationRequest);
|
||||
|
||||
OAuth2AuthenticationToken oauth2Authentication = new OAuth2AuthenticationToken(
|
||||
authenticationResult.getPrincipal(),
|
||||
|
|
|
@ -119,7 +119,7 @@ public class OAuth2LoginAuthenticationProviderTests {
|
|||
when(this.authorizationRequest.getScopes()).thenReturn(new LinkedHashSet<>(Collections.singleton("openid")));
|
||||
|
||||
OAuth2LoginAuthenticationToken authentication =
|
||||
(OAuth2LoginAuthenticationToken)this.authenticationProvider.authenticate(
|
||||
(OAuth2LoginAuthenticationToken) this.authenticationProvider.authenticate(
|
||||
new OAuth2LoginAuthenticationToken(this.clientRegistration, this.authorizationExchange));
|
||||
|
||||
assertThat(authentication).isNull();
|
||||
|
@ -175,7 +175,7 @@ public class OAuth2LoginAuthenticationProviderTests {
|
|||
when(this.userService.loadUser(any())).thenReturn(principal);
|
||||
|
||||
OAuth2LoginAuthenticationToken authentication =
|
||||
(OAuth2LoginAuthenticationToken)this.authenticationProvider.authenticate(
|
||||
(OAuth2LoginAuthenticationToken) this.authenticationProvider.authenticate(
|
||||
new OAuth2LoginAuthenticationToken(this.clientRegistration, this.authorizationExchange));
|
||||
|
||||
assertThat(authentication.isAuthenticated()).isTrue();
|
||||
|
@ -207,7 +207,7 @@ public class OAuth2LoginAuthenticationProviderTests {
|
|||
this.authenticationProvider.setAuthoritiesMapper(authoritiesMapper);
|
||||
|
||||
OAuth2LoginAuthenticationToken authentication =
|
||||
(OAuth2LoginAuthenticationToken)this.authenticationProvider.authenticate(
|
||||
(OAuth2LoginAuthenticationToken) this.authenticationProvider.authenticate(
|
||||
new OAuth2LoginAuthenticationToken(this.clientRegistration, this.authorizationExchange));
|
||||
|
||||
assertThat(authentication.getAuthorities()).isEqualTo(mappedAuthorities);
|
||||
|
|
|
@ -143,7 +143,7 @@ public class OidcAuthorizationCodeAuthenticationProviderTests {
|
|||
when(this.authorizationRequest.getScopes()).thenReturn(new LinkedHashSet<>(Collections.singleton("scope1")));
|
||||
|
||||
OAuth2LoginAuthenticationToken authentication =
|
||||
(OAuth2LoginAuthenticationToken)this.authenticationProvider.authenticate(
|
||||
(OAuth2LoginAuthenticationToken) this.authenticationProvider.authenticate(
|
||||
new OAuth2LoginAuthenticationToken(this.clientRegistration, this.authorizationExchange));
|
||||
|
||||
assertThat(authentication).isNull();
|
||||
|
@ -355,7 +355,7 @@ public class OidcAuthorizationCodeAuthenticationProviderTests {
|
|||
when(this.userService.loadUser(any())).thenReturn(principal);
|
||||
|
||||
OAuth2LoginAuthenticationToken authentication =
|
||||
(OAuth2LoginAuthenticationToken)this.authenticationProvider.authenticate(
|
||||
(OAuth2LoginAuthenticationToken) this.authenticationProvider.authenticate(
|
||||
new OAuth2LoginAuthenticationToken(this.clientRegistration, this.authorizationExchange));
|
||||
|
||||
assertThat(authentication.isAuthenticated()).isTrue();
|
||||
|
@ -389,7 +389,7 @@ public class OidcAuthorizationCodeAuthenticationProviderTests {
|
|||
this.authenticationProvider.setAuthoritiesMapper(authoritiesMapper);
|
||||
|
||||
OAuth2LoginAuthenticationToken authentication =
|
||||
(OAuth2LoginAuthenticationToken)this.authenticationProvider.authenticate(
|
||||
(OAuth2LoginAuthenticationToken) this.authenticationProvider.authenticate(
|
||||
new OAuth2LoginAuthenticationToken(this.clientRegistration, this.authorizationExchange));
|
||||
|
||||
assertThat(authentication.getAuthorities()).isEqualTo(mappedAuthorities);
|
||||
|
|
|
@ -159,7 +159,7 @@ public class OidcUserServiceTests {
|
|||
|
||||
assertThat(user.getAuthorities().size()).isEqualTo(1);
|
||||
assertThat(user.getAuthorities().iterator().next()).isInstanceOf(OidcUserAuthority.class);
|
||||
OidcUserAuthority userAuthority = (OidcUserAuthority)user.getAuthorities().iterator().next();
|
||||
OidcUserAuthority userAuthority = (OidcUserAuthority) user.getAuthorities().iterator().next();
|
||||
assertThat(userAuthority.getAuthority()).isEqualTo("ROLE_USER");
|
||||
assertThat(userAuthority.getIdToken()).isEqualTo(user.getIdToken());
|
||||
assertThat(userAuthority.getUserInfo()).isEqualTo(user.getUserInfo());
|
||||
|
|
|
@ -121,7 +121,7 @@ public class DefaultOAuth2UserServiceTests {
|
|||
|
||||
assertThat(user.getAuthorities().size()).isEqualTo(1);
|
||||
assertThat(user.getAuthorities().iterator().next()).isInstanceOf(OAuth2UserAuthority.class);
|
||||
OAuth2UserAuthority userAuthority = (OAuth2UserAuthority)user.getAuthorities().iterator().next();
|
||||
OAuth2UserAuthority userAuthority = (OAuth2UserAuthority) user.getAuthorities().iterator().next();
|
||||
assertThat(userAuthority.getAuthority()).isEqualTo("ROLE_USER");
|
||||
assertThat(userAuthority.getAttributes()).isEqualTo(user.getAttributes());
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ public class OAuth2AuthorizationRequestUriBuilderTests {
|
|||
@Test
|
||||
public void buildWhenScopeMultiThenSeparatedByEncodedSpace() {
|
||||
OAuth2AuthorizationRequest request = OAuth2AuthorizationRequest.implicit()
|
||||
.additionalParameters(Collections.singletonMap("foo","bar"))
|
||||
.additionalParameters(Collections.singletonMap("foo", "bar"))
|
||||
.authorizationUri("https://idp.example.com/oauth2/v2/auth")
|
||||
.clientId("client-id")
|
||||
.state("thestate")
|
||||
|
|
|
@ -75,7 +75,7 @@ public interface ClaimAccessor {
|
|||
return null;
|
||||
}
|
||||
Map<String, Object> claimValues = new HashMap<>();
|
||||
((Map<?, ?>)this.getClaims().get(claim)).forEach((k, v) -> claimValues.put(k.toString(), v));
|
||||
((Map<?, ?>) this.getClaims().get(claim)).forEach((k, v) -> claimValues.put(k.toString(), v));
|
||||
return claimValues;
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ public interface ClaimAccessor {
|
|||
return null;
|
||||
}
|
||||
List<String> claimValues = new ArrayList<>();
|
||||
((List<?>)this.getClaims().get(claim)).forEach(e -> claimValues.add(e.toString()));
|
||||
((List<?>) this.getClaims().get(claim)).forEach(e -> claimValues.add(e.toString()));
|
||||
return claimValues;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ import java.util.Set;
|
|||
*/
|
||||
public final class OAuth2AccessTokenResponse {
|
||||
private OAuth2AccessToken accessToken;
|
||||
private Map<String,Object> additionalParameters;
|
||||
private Map<String, Object> additionalParameters;
|
||||
|
||||
private OAuth2AccessTokenResponse() {
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ public final class OAuth2AccessTokenResponse {
|
|||
private OAuth2AccessToken.TokenType tokenType;
|
||||
private long expiresIn;
|
||||
private Set<String> scopes;
|
||||
private Map<String,Object> additionalParameters;
|
||||
private Map<String, Object> additionalParameters;
|
||||
|
||||
private Builder(String tokenValue) {
|
||||
this.tokenValue = tokenValue;
|
||||
|
@ -76,7 +76,7 @@ public final class OAuth2AccessTokenResponse {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder additionalParameters(Map<String,Object> additionalParameters) {
|
||||
public Builder additionalParameters(Map<String, Object> additionalParameters) {
|
||||
this.additionalParameters = additionalParameters;
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public final class OAuth2AuthorizationRequest implements Serializable {
|
|||
private String redirectUri;
|
||||
private Set<String> scopes;
|
||||
private String state;
|
||||
private Map<String,Object> additionalParameters;
|
||||
private Map<String, Object> additionalParameters;
|
||||
|
||||
private OAuth2AuthorizationRequest() {
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ public final class OAuth2AuthorizationRequest implements Serializable {
|
|||
private String redirectUri;
|
||||
private Set<String> scopes;
|
||||
private String state;
|
||||
private Map<String,Object> additionalParameters;
|
||||
private Map<String, Object> additionalParameters;
|
||||
|
||||
private Builder(AuthorizationGrantType authorizationGrantType) {
|
||||
Assert.notNull(authorizationGrantType, "authorizationGrantType cannot be null");
|
||||
|
@ -147,7 +147,7 @@ public final class OAuth2AuthorizationRequest implements Serializable {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder additionalParameters(Map<String,Object> additionalParameters) {
|
||||
public Builder additionalParameters(Map<String, Object> additionalParameters) {
|
||||
this.additionalParameters = additionalParameters;
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -123,12 +123,12 @@ public final class DefaultAddressStandardClaim implements AddressStandardClaim {
|
|||
}
|
||||
|
||||
public Builder(Map<String, Object> addressFields) {
|
||||
this.formatted((String)addressFields.get(FORMATTED_FIELD_NAME));
|
||||
this.streetAddress((String)addressFields.get(STREET_ADDRESS_FIELD_NAME));
|
||||
this.locality((String)addressFields.get(LOCALITY_FIELD_NAME));
|
||||
this.region((String)addressFields.get(REGION_FIELD_NAME));
|
||||
this.postalCode((String)addressFields.get(POSTAL_CODE_FIELD_NAME));
|
||||
this.country((String)addressFields.get(COUNTRY_FIELD_NAME));
|
||||
this.formatted((String) addressFields.get(FORMATTED_FIELD_NAME));
|
||||
this.streetAddress((String) addressFields.get(STREET_ADDRESS_FIELD_NAME));
|
||||
this.locality((String) addressFields.get(LOCALITY_FIELD_NAME));
|
||||
this.region((String) addressFields.get(REGION_FIELD_NAME));
|
||||
this.postalCode((String) addressFields.get(POSTAL_CODE_FIELD_NAME));
|
||||
this.country((String) addressFields.get(COUNTRY_FIELD_NAME));
|
||||
}
|
||||
|
||||
public Builder formatted(String formatted) {
|
||||
|
|
|
@ -87,11 +87,11 @@ public class HelloWebfluxMethodApplicationITests {
|
|||
}
|
||||
|
||||
private Consumer<Map<String, Object>> robsCredentials() {
|
||||
return basicAuthenticationCredentials("rob","rob");
|
||||
return basicAuthenticationCredentials("rob", "rob");
|
||||
}
|
||||
|
||||
private Consumer<Map<String, Object>> adminCredentials() {
|
||||
return basicAuthenticationCredentials("admin","admin");
|
||||
return basicAuthenticationCredentials("admin", "admin");
|
||||
}
|
||||
|
||||
private String base64Encode(String value) {
|
||||
|
|
|
@ -49,7 +49,7 @@ public class SecurityConfig {
|
|||
public MapReactiveUserDetailsService userDetailsRepository() {
|
||||
User.UserBuilder userBuilder = User.withDefaultPasswordEncoder();
|
||||
UserDetails rob = userBuilder.username("rob").password("rob").roles("USER").build();
|
||||
UserDetails admin = userBuilder.username("admin").password("admin").roles("USER","ADMIN").build();
|
||||
UserDetails admin = userBuilder.username("admin").password("admin").roles("USER", "ADMIN").build();
|
||||
return new MapReactiveUserDetailsService(rob, admin);
|
||||
}
|
||||
|
||||
|
|
|
@ -138,10 +138,10 @@ public class HelloWebfluxMethodApplicationTests {
|
|||
}
|
||||
|
||||
private Consumer<Map<String, Object>> robsCredentials() {
|
||||
return basicAuthenticationCredentials("rob","rob");
|
||||
return basicAuthenticationCredentials("rob", "rob");
|
||||
}
|
||||
|
||||
private Consumer<Map<String, Object>> adminCredentials() {
|
||||
return basicAuthenticationCredentials("admin","admin");
|
||||
return basicAuthenticationCredentials("admin", "admin");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,10 +87,10 @@ public class HelloWebfluxApplicationITests {
|
|||
}
|
||||
|
||||
private Consumer<Map<String, Object>> userCredentials() {
|
||||
return basicAuthenticationCredentials("user","user");
|
||||
return basicAuthenticationCredentials("user", "user");
|
||||
}
|
||||
|
||||
private Consumer<Map<String, Object>> invalidCredentials() {
|
||||
return basicAuthenticationCredentials("user","INVALID");
|
||||
return basicAuthenticationCredentials("user", "INVALID");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,13 +32,13 @@ import reactor.core.publisher.Mono;
|
|||
public class HelloUserController {
|
||||
|
||||
@GetMapping("/")
|
||||
public Mono<Map<String,String>> hello(Mono<Principal> principal) {
|
||||
public Mono<Map<String, String>> hello(Mono<Principal> principal) {
|
||||
return principal
|
||||
.map(Principal::getName)
|
||||
.map(this::helloMessage);
|
||||
}
|
||||
|
||||
private Map<String,String> helloMessage(String username) {
|
||||
private Map<String, String> helloMessage(String username) {
|
||||
return Collections.singletonMap("message", "Hello " + username + "!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,10 +112,10 @@ public class HelloWebfluxApplicationTests {
|
|||
}
|
||||
|
||||
private Consumer<Map<String, Object>> userCredentials() {
|
||||
return basicAuthenticationCredentials("user","user");
|
||||
return basicAuthenticationCredentials("user", "user");
|
||||
}
|
||||
|
||||
private Consumer<Map<String, Object>> invalidCredentials() {
|
||||
return basicAuthenticationCredentials("user","INVALID");
|
||||
return basicAuthenticationCredentials("user", "INVALID");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,10 +86,10 @@ public class HelloWebfluxFnApplicationITests {
|
|||
}
|
||||
|
||||
private Consumer<Map<String, Object>> userCredentials() {
|
||||
return basicAuthenticationCredentials("user","user");
|
||||
return basicAuthenticationCredentials("user", "user");
|
||||
}
|
||||
|
||||
private Consumer<Map<String, Object>> invalidCredentials() {
|
||||
return basicAuthenticationCredentials("user","INVALID");
|
||||
return basicAuthenticationCredentials("user", "INVALID");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,10 +115,10 @@ public class HelloWebfluxFnApplicationTests {
|
|||
}
|
||||
|
||||
private Consumer<Map<String, Object>> userCredentials() {
|
||||
return basicAuthenticationCredentials("user","user");
|
||||
return basicAuthenticationCredentials("user", "user");
|
||||
}
|
||||
|
||||
private Consumer<Map<String, Object>> invalidCredentials() {
|
||||
return basicAuthenticationCredentials("user","INVALID");
|
||||
return basicAuthenticationCredentials("user", "INVALID");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,11 +27,11 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http
|
||||
.authorizeRequests()
|
||||
.antMatchers("/login","/resources/**").permitAll()
|
||||
.antMatchers("/login", "/resources/**").permitAll()
|
||||
.anyRequest().authenticated()
|
||||
.and()
|
||||
.jee()
|
||||
.mappableRoles("USER","ADMIN");
|
||||
.mappableRoles("USER", "ADMIN");
|
||||
}
|
||||
// @formatter:on
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||
auth.
|
||||
inMemoryAuthentication()
|
||||
.withUser("dianne").password("password").roles("USER").and()
|
||||
.withUser("rod").password("password").roles("USER","ADMIN").and()
|
||||
.withUser("rod").password("password").roles("USER", "ADMIN").and()
|
||||
.withUser("scott").password("password").roles("USER");
|
||||
}
|
||||
// @formatter:on
|
||||
|
|
|
@ -58,7 +58,7 @@ public class ClientApplication {
|
|||
|
||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||
|
||||
for (Map.Entry<String,ContactManager> entry : contactServices.entrySet()) {
|
||||
for (Map.Entry<String, ContactManager> entry : contactServices.entrySet()) {
|
||||
String beanName = entry.getKey();
|
||||
ContactManager remoteContactManager = entry.getValue();
|
||||
Object object = this.beanFactory.getBean("&" + beanName);
|
||||
|
|
|
@ -98,11 +98,11 @@ public class AbstractAuthorizeTagTests {
|
|||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void expressionFromChildContext() throws IOException {
|
||||
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("user", "pass","USER"));
|
||||
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("user", "pass", "USER"));
|
||||
DefaultWebSecurityExpressionHandler expected = new DefaultWebSecurityExpressionHandler();
|
||||
tag.setAccess("permitAll");
|
||||
WebApplicationContext wac = mock(WebApplicationContext.class);
|
||||
when(wac.getBeansOfType(SecurityExpressionHandler.class)).thenReturn(Collections.<String,SecurityExpressionHandler>singletonMap("wipe", expected));
|
||||
when(wac.getBeansOfType(SecurityExpressionHandler.class)).thenReturn(Collections.<String, SecurityExpressionHandler>singletonMap("wipe", expected));
|
||||
servletContext.setAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher", wac);
|
||||
|
||||
assertThat(tag.authorize()).isTrue();
|
||||
|
|
|
@ -66,7 +66,7 @@ public class Sec2935Tests {
|
|||
@Test
|
||||
public void postProcessorUserNoUser() throws Exception {
|
||||
mvc
|
||||
.perform(get("/admin/abc").with(user("user").roles("ADMIN","USER")))
|
||||
.perform(get("/admin/abc").with(user("user").roles("ADMIN", "USER")))
|
||||
.andExpect(status().isNotFound())
|
||||
.andExpect(authenticated().withUsername("user"));
|
||||
|
||||
|
@ -79,7 +79,7 @@ public class Sec2935Tests {
|
|||
@Test
|
||||
public void postProcessorUserOtherUser() throws Exception {
|
||||
mvc
|
||||
.perform(get("/admin/abc").with(user("user1").roles("ADMIN","USER")))
|
||||
.perform(get("/admin/abc").with(user("user1").roles("ADMIN", "USER")))
|
||||
.andExpect(status().isNotFound())
|
||||
.andExpect(authenticated().withUsername("user1"));
|
||||
|
||||
|
@ -93,7 +93,7 @@ public class Sec2935Tests {
|
|||
@Test
|
||||
public void postProcessorUserWithMockUser() throws Exception {
|
||||
mvc
|
||||
.perform(get("/admin/abc").with(user("user1").roles("ADMIN","USER")))
|
||||
.perform(get("/admin/abc").with(user("user1").roles("ADMIN", "USER")))
|
||||
.andExpect(status().isNotFound())
|
||||
.andExpect(authenticated().withUsername("user1"));
|
||||
|
||||
|
@ -112,7 +112,7 @@ public class Sec2935Tests {
|
|||
.build();
|
||||
|
||||
mvc
|
||||
.perform(get("/admin/abc").with(user("user1").roles("ADMIN","USER")))
|
||||
.perform(get("/admin/abc").with(user("user1").roles("ADMIN", "USER")))
|
||||
.andExpect(status().isNotFound())
|
||||
.andExpect(authenticated().withUsername("user1"));
|
||||
|
||||
|
@ -132,7 +132,7 @@ public class Sec2935Tests {
|
|||
.build();
|
||||
|
||||
mvc
|
||||
.perform(get("/admin/abc").with(user("user1").roles("ADMIN","USER")))
|
||||
.perform(get("/admin/abc").with(user("user1").roles("ADMIN", "USER")))
|
||||
.andExpect(status().isNotFound())
|
||||
.andExpect(authenticated().withUsername("user1"));
|
||||
|
||||
|
|
|
@ -159,7 +159,7 @@ public class SecurityMockMvcRequestPostProcessorsCsrfTests {
|
|||
|
||||
MockHttpServletRequestBuilder requestWithCsrf = post("/")
|
||||
.param(token.getParameterName(), token.getToken())
|
||||
.session((MockHttpSession)request.getSession());
|
||||
.session((MockHttpSession) request.getSession());
|
||||
this.mockMvc.perform(requestWithCsrf)
|
||||
.andExpect(status().isOk());
|
||||
// @formatter:on
|
||||
|
|
|
@ -28,6 +28,6 @@ import org.springframework.security.test.context.support.WithMockUser;
|
|||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Inherited
|
||||
@Documented
|
||||
@WithMockUser(value="rob",roles="ADMIN")
|
||||
@WithMockUser(value="rob", roles="ADMIN")
|
||||
public @interface WithAdminRob {
|
||||
}
|
||||
|
|
|
@ -103,8 +103,8 @@ public class WithUserDetailsAuthenticationTests {
|
|||
auth
|
||||
.inMemoryAuthentication()
|
||||
.withUser("user").password("password").roles("USER").and()
|
||||
.withUser("admin").password("password").roles("USER","ADMIN");
|
||||
.withUser("admin").password("password").roles("USER", "ADMIN");
|
||||
}
|
||||
// @formatter:on
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,8 +103,8 @@ public class WithUserDetailsClassLevelAuthenticationTests {
|
|||
auth
|
||||
.inMemoryAuthentication()
|
||||
.withUser("user").password("password").roles("USER").and()
|
||||
.withUser("admin").password("password").roles("USER","ADMIN");
|
||||
.withUser("admin").password("password").roles("USER", "ADMIN");
|
||||
}
|
||||
// @formatter:on
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ public class DefaultLoginPageGeneratingFilter extends GenericFilterBean {
|
|||
private String openIDusernameParameter;
|
||||
private String openIDrememberMeParameter;
|
||||
private Map<String, String> oauth2AuthenticationUrlToClientName;
|
||||
private Function<HttpServletRequest,Map<String,String>> resolveHiddenInputs = request -> Collections
|
||||
private Function<HttpServletRequest, Map<String, String>> resolveHiddenInputs = request -> Collections
|
||||
.emptyMap();
|
||||
|
||||
|
||||
|
@ -298,7 +298,7 @@ public class DefaultLoginPageGeneratingFilter extends GenericFilterBean {
|
|||
}
|
||||
|
||||
private void renderHiddenInputs(StringBuilder sb, HttpServletRequest request) {
|
||||
for(Map.Entry<String,String> input : this.resolveHiddenInputs.apply(request).entrySet()) {
|
||||
for(Map.Entry<String, String> input : this.resolveHiddenInputs.apply(request).entrySet()) {
|
||||
sb.append(" <input name=\"" + input.getKey()
|
||||
+ "\" type=\"hidden\" value=\"" + input.getValue() + "\" />\n");
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.springframework.web.server.ServerWebExchange;
|
|||
* @author Rob Winch
|
||||
* @since 5.0
|
||||
*/
|
||||
public class ServerFormLoginAuthenticationConverter implements Function<ServerWebExchange,Mono<Authentication>> {
|
||||
public class ServerFormLoginAuthenticationConverter implements Function<ServerWebExchange, Mono<Authentication>> {
|
||||
|
||||
private String usernameParameter = "username";
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ import reactor.core.publisher.Mono;
|
|||
* @author Rob Winch
|
||||
* @since 5.0
|
||||
*/
|
||||
public class ServerHttpBasicAuthenticationConverter implements Function<ServerWebExchange,Mono<Authentication>> {
|
||||
public class ServerHttpBasicAuthenticationConverter implements Function<ServerWebExchange, Mono<Authentication>> {
|
||||
|
||||
public static final String BASIC = "Basic ";
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ public class AuthenticationWebFilter implements WebFilter {
|
|||
|
||||
private ServerAuthenticationSuccessHandler authenticationSuccessHandler = new WebFilterChainServerAuthenticationSuccessHandler();
|
||||
|
||||
private Function<ServerWebExchange,Mono<Authentication>> authenticationConverter = new ServerHttpBasicAuthenticationConverter();
|
||||
private Function<ServerWebExchange, Mono<Authentication>> authenticationConverter = new ServerHttpBasicAuthenticationConverter();
|
||||
|
||||
private ServerAuthenticationFailureHandler authenticationFailureHandler = new ServerAuthenticationEntryPointFailureHandler(new HttpBasicServerAuthenticationEntryPoint());
|
||||
|
||||
|
@ -97,7 +97,7 @@ public class AuthenticationWebFilter implements WebFilter {
|
|||
this.authenticationSuccessHandler = authenticationSuccessHandler;
|
||||
}
|
||||
|
||||
public void setAuthenticationConverter(Function<ServerWebExchange,Mono<Authentication>> authenticationConverter) {
|
||||
public void setAuthenticationConverter(Function<ServerWebExchange, Mono<Authentication>> authenticationConverter) {
|
||||
this.authenticationConverter = authenticationConverter;
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ public class LogoutWebFilter implements WebFilter {
|
|||
.map(result -> exchange)
|
||||
.flatMap(this::flatMapAuthentication)
|
||||
.flatMap( authentication -> {
|
||||
WebFilterExchange webFilterExchange = new WebFilterExchange(exchange,chain);
|
||||
WebFilterExchange webFilterExchange = new WebFilterExchange(exchange, chain);
|
||||
return logout(webFilterExchange, authentication);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -27,13 +27,13 @@ import java.util.Map;
|
|||
*/
|
||||
public class AuthorizationContext {
|
||||
private final ServerWebExchange exchange;
|
||||
private final Map<String,Object> variables;
|
||||
private final Map<String, Object> variables;
|
||||
|
||||
public AuthorizationContext(ServerWebExchange exchange) {
|
||||
this(exchange, Collections.emptyMap());
|
||||
}
|
||||
|
||||
public AuthorizationContext(ServerWebExchange exchange, Map<String,Object> variables) {
|
||||
public AuthorizationContext(ServerWebExchange exchange, Map<String, Object> variables) {
|
||||
this.exchange = exchange;
|
||||
this.variables = variables;
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ public class AuthorizationContext {
|
|||
return exchange;
|
||||
}
|
||||
|
||||
public Map<String,Object> getVariables() {
|
||||
public Map<String, Object> getVariables() {
|
||||
return Collections.unmodifiableMap(variables);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,14 +64,14 @@ public class WebSessionServerCsrfTokenRepository
|
|||
.flatMap( attrs -> save(attrs, token));
|
||||
}
|
||||
|
||||
private Mono<CsrfToken> save(Map<String,Object> attributes, CsrfToken token) {
|
||||
private Mono<CsrfToken> save(Map<String, Object> attributes, CsrfToken token) {
|
||||
return Mono.defer(() -> {
|
||||
putToken(attributes, token);
|
||||
return Mono.justOrEmpty(token);
|
||||
});
|
||||
}
|
||||
|
||||
private void putToken(Map<String,Object> attributes, CsrfToken token) {
|
||||
private void putToken(Map<String, Object> attributes, CsrfToken token) {
|
||||
if(token == null) {
|
||||
attributes.remove(this.sessionAttributeName);
|
||||
} else {
|
||||
|
@ -118,7 +118,7 @@ public class WebSessionServerCsrfTokenRepository
|
|||
}
|
||||
|
||||
|
||||
private CsrfToken createCsrfToken(Map<String,Object> attributes) {
|
||||
private CsrfToken createCsrfToken(Map<String, Object> attributes) {
|
||||
return new LazyCsrfToken(attributes, createCsrfToken());
|
||||
}
|
||||
|
||||
|
@ -131,7 +131,7 @@ public class WebSessionServerCsrfTokenRepository
|
|||
}
|
||||
|
||||
private class LazyCsrfToken implements CsrfToken {
|
||||
private final Map<String,Object> attributes;
|
||||
private final Map<String, Object> attributes;
|
||||
private final CsrfToken delegate;
|
||||
|
||||
private LazyCsrfToken(Map<String, Object> attributes, CsrfToken delegate) {
|
||||
|
|
|
@ -68,8 +68,8 @@ public final class PathPatternParserServerWebExchangeMatcher implements ServerWe
|
|||
if(!match) {
|
||||
return MatchResult.notMatch();
|
||||
}
|
||||
Map<String,String> pathVariables = this.pattern.matchAndExtract(path).getUriVariables();
|
||||
Map<String,Object> variables = new HashMap<>(pathVariables);
|
||||
Map<String, String> pathVariables = this.pattern.matchAndExtract(path).getUriVariables();
|
||||
Map<String, Object> variables = new HashMap<>(pathVariables);
|
||||
return MatchResult.match(variables);
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ public interface ServerWebExchangeMatcher {
|
|||
|
||||
class MatchResult {
|
||||
private final boolean match;
|
||||
private final Map<String,Object> variables;
|
||||
private final Map<String, Object> variables;
|
||||
|
||||
private MatchResult(boolean match, Map<String, Object> variables) {
|
||||
this.match = match;
|
||||
|
@ -43,7 +43,7 @@ public interface ServerWebExchangeMatcher {
|
|||
return match;
|
||||
}
|
||||
|
||||
public Map<String,Object> getVariables() {
|
||||
public Map<String, Object> getVariables() {
|
||||
return variables;
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ public interface ServerWebExchangeMatcher {
|
|||
return match(Collections.emptyMap());
|
||||
}
|
||||
|
||||
public static Mono<MatchResult> match(Map<String,Object> variables) {
|
||||
public static Mono<MatchResult> match(Map<String, Object> variables) {
|
||||
return Mono.just(new MatchResult(true, variables));
|
||||
}
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ public class DigestAuthUtilsTests {
|
|||
public void testSplitNormalOperation() {
|
||||
String unsplit = "username=\"rod==\"";
|
||||
assertThat(DigestAuthUtils.split(unsplit, "=")[0]).isEqualTo("username");
|
||||
assertThat(DigestAuthUtils.split(unsplit, "=")[1]).isEqualTo("\"rod==\"");// should
|
||||
assertThat(DigestAuthUtils.split(unsplit, "=")[1]).isEqualTo("\"rod==\""); // should
|
||||
// not
|
||||
// remove
|
||||
// quotes
|
||||
|
|
|
@ -84,7 +84,7 @@ public class SavedCookieMixinTests extends AbstractMixinTests {
|
|||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void deserializeSavedCookieWithList() throws IOException, JSONException {
|
||||
List<SavedCookie> savedCookies = (List<SavedCookie>)mapper.readValue(COOKIES_JSON, Object.class);
|
||||
List<SavedCookie> savedCookies = (List<SavedCookie>) mapper.readValue(COOKIES_JSON, Object.class);
|
||||
assertThat(savedCookies).isNotNull().hasSize(1);
|
||||
assertThat(savedCookies.get(0).getName()).isEqualTo("SESSION");
|
||||
assertThat(savedCookies.get(0).getValue()).isEqualTo("123456789");
|
||||
|
|
|
@ -39,7 +39,7 @@ public class ServerFormLoginAuthenticationConverterTests {
|
|||
@Mock
|
||||
private ServerWebExchange exchange;
|
||||
|
||||
private MultiValueMap<String,String> data = new LinkedMultiValueMap<>();
|
||||
private MultiValueMap<String, String> data = new LinkedMultiValueMap<>();
|
||||
|
||||
private ServerFormLoginAuthenticationConverter converter = new ServerFormLoginAuthenticationConverter();
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ public class AuthenticationWebFilterTests {
|
|||
@Mock
|
||||
private ServerAuthenticationSuccessHandler successHandler;
|
||||
@Mock
|
||||
private Function<ServerWebExchange,Mono<Authentication>> authenticationConverter;
|
||||
private Function<ServerWebExchange, Mono<Authentication>> authenticationConverter;
|
||||
@Mock
|
||||
private ReactiveAuthenticationManager authenticationManager;
|
||||
@Mock
|
||||
|
@ -96,7 +96,7 @@ public class AuthenticationWebFilterTests {
|
|||
|
||||
@Test
|
||||
public void filterWhenDefaultsAndAuthenticationSuccessThenContinues() {
|
||||
when(this.authenticationManager.authenticate(any())).thenReturn(Mono.just(new TestingAuthenticationToken("test","this", "ROLE")));
|
||||
when(this.authenticationManager.authenticate(any())).thenReturn(Mono.just(new TestingAuthenticationToken("test", "this", "ROLE")));
|
||||
this.filter = new AuthenticationWebFilter(this.authenticationManager);
|
||||
|
||||
WebTestClient client = WebTestClientBuilder
|
||||
|
@ -185,7 +185,7 @@ public class AuthenticationWebFilterTests {
|
|||
when(this.authenticationConverter.apply(any())).thenReturn(authentication);
|
||||
when(this.authenticationManager.authenticate(any())).thenReturn(authentication);
|
||||
when(this.successHandler.onAuthenticationSuccess(any(), any())).thenReturn(Mono.empty());
|
||||
when(this.securityContextRepository.save(any(),any())).thenAnswer( a -> Mono.just(a.getArguments()[0]));
|
||||
when(this.securityContextRepository.save(any(), any())).thenAnswer( a -> Mono.just(a.getArguments()[0]));
|
||||
|
||||
WebTestClient client = WebTestClientBuilder
|
||||
.bindToWebFilters(this.filter)
|
||||
|
@ -231,7 +231,7 @@ public class AuthenticationWebFilterTests {
|
|||
Mono<Authentication> authentication = Mono.just(new TestingAuthenticationToken("test", "this", "ROLE_USER"));
|
||||
when(this.authenticationConverter.apply(any())).thenReturn(authentication);
|
||||
when(this.authenticationManager.authenticate(any())).thenReturn(Mono.error(new BadCredentialsException("Failed")));
|
||||
when(this.failureHandler.onAuthenticationFailure(any(),any())).thenReturn(Mono.empty());
|
||||
when(this.failureHandler.onAuthenticationFailure(any(), any())).thenReturn(Mono.empty());
|
||||
|
||||
WebTestClient client = WebTestClientBuilder
|
||||
.bindToWebFilters(this.filter)
|
||||
|
@ -244,7 +244,7 @@ public class AuthenticationWebFilterTests {
|
|||
.expectStatus().isOk()
|
||||
.expectBody().isEmpty();
|
||||
|
||||
verify(this.failureHandler).onAuthenticationFailure(any(),any());
|
||||
verify(this.failureHandler).onAuthenticationFailure(any(), any());
|
||||
verify(this.securityContextRepository, never()).save(any(), any());
|
||||
verifyZeroInteractions(this.successHandler);
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public class AuthorizationWebFilterTests {
|
|||
@Test
|
||||
public void filterWhenNoSecurityContextThenThrowsAccessDenied() {
|
||||
when(this.chain.filter(this.exchange)).thenReturn(this.chainResult.mono());
|
||||
AuthorizationWebFilter filter = new AuthorizationWebFilter((a,e) -> Mono.error(new AccessDeniedException("Denied")));
|
||||
AuthorizationWebFilter filter = new AuthorizationWebFilter((a, e) -> Mono.error(new AccessDeniedException("Denied")));
|
||||
|
||||
Mono<Void> result = filter.filter(this.exchange, this.chain);
|
||||
|
||||
|
@ -63,7 +63,7 @@ public class AuthorizationWebFilterTests {
|
|||
@Test
|
||||
public void filterWhenNoAuthenticationThenThrowsAccessDenied() {
|
||||
when(this.chain.filter(this.exchange)).thenReturn(this.chainResult.mono());
|
||||
AuthorizationWebFilter filter = new AuthorizationWebFilter((a,e) -> Mono.error(new AccessDeniedException("Denied")));
|
||||
AuthorizationWebFilter filter = new AuthorizationWebFilter((a, e) -> Mono.error(new AccessDeniedException("Denied")));
|
||||
|
||||
Mono<Void> result = filter
|
||||
.filter(this.exchange, this.chain)
|
||||
|
@ -78,11 +78,11 @@ public class AuthorizationWebFilterTests {
|
|||
@Test
|
||||
public void filterWhenAuthenticationThenThrowsAccessDenied() {
|
||||
when(this.chain.filter(this.exchange)).thenReturn(this.chainResult.mono());
|
||||
AuthorizationWebFilter filter = new AuthorizationWebFilter((a,e) -> Mono.error(new AccessDeniedException("Denied")));
|
||||
AuthorizationWebFilter filter = new AuthorizationWebFilter((a, e) -> Mono.error(new AccessDeniedException("Denied")));
|
||||
|
||||
Mono<Void> result = filter
|
||||
.filter(this.exchange, this.chain)
|
||||
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(new TestingAuthenticationToken("a","b", "R")));
|
||||
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(new TestingAuthenticationToken("a", "b", "R")));
|
||||
|
||||
StepVerifier.create(result)
|
||||
.expectError(AccessDeniedException.class)
|
||||
|
@ -94,7 +94,7 @@ public class AuthorizationWebFilterTests {
|
|||
public void filterWhenDoesNotAccessAuthenticationThenSecurityContextNotSubscribed() {
|
||||
PublisherProbe<SecurityContext> context = PublisherProbe.empty();
|
||||
when(this.chain.filter(this.exchange)).thenReturn(this.chainResult.mono());
|
||||
AuthorizationWebFilter filter = new AuthorizationWebFilter((a,e) -> Mono.error(new AccessDeniedException("Denied")));
|
||||
AuthorizationWebFilter filter = new AuthorizationWebFilter((a, e) -> Mono.error(new AccessDeniedException("Denied")));
|
||||
|
||||
Mono<Void> result = filter
|
||||
.filter(this.exchange, this.chain)
|
||||
|
@ -111,7 +111,7 @@ public class AuthorizationWebFilterTests {
|
|||
public void filterWhenGrantedAndDoesNotAccessAuthenticationThenChainSubscribedAndSecurityContextNotSubscribed() {
|
||||
PublisherProbe<SecurityContext> context = PublisherProbe.empty();
|
||||
when(this.chain.filter(this.exchange)).thenReturn(this.chainResult.mono());
|
||||
AuthorizationWebFilter filter = new AuthorizationWebFilter((a,e) -> Mono.just(new AuthorizationDecision(true)));
|
||||
AuthorizationWebFilter filter = new AuthorizationWebFilter((a, e) -> Mono.just(new AuthorizationDecision(true)));
|
||||
|
||||
Mono<Void> result = filter
|
||||
.filter(this.exchange, this.chain)
|
||||
|
@ -127,7 +127,7 @@ public class AuthorizationWebFilterTests {
|
|||
public void filterWhenGrantedAndDoeAccessAuthenticationThenChainSubscribedAndSecurityContextSubscribed() {
|
||||
PublisherProbe<SecurityContext> context = PublisherProbe.empty();
|
||||
when(this.chain.filter(this.exchange)).thenReturn(this.chainResult.mono());
|
||||
AuthorizationWebFilter filter = new AuthorizationWebFilter((a,e) -> a
|
||||
AuthorizationWebFilter filter = new AuthorizationWebFilter((a, e) -> a
|
||||
.map( auth -> new AuthorizationDecision(true))
|
||||
.defaultIfEmpty(new AuthorizationDecision(true))
|
||||
);
|
||||
|
|
|
@ -74,7 +74,7 @@ public class ReactorContextWebFilterTests {
|
|||
|
||||
@Test
|
||||
public void filterWhenGetPrincipalMonoThenNoInteractions() {
|
||||
this.handler = WebTestHandler.bindToWebFilters(this.filter, (e,c) -> {
|
||||
this.handler = WebTestHandler.bindToWebFilters(this.filter, (e, c) -> {
|
||||
ReactiveSecurityContextHolder.getContext();
|
||||
return c.filter(e);
|
||||
});
|
||||
|
@ -88,7 +88,7 @@ public class ReactorContextWebFilterTests {
|
|||
public void filterWhenPrincipalAndGetPrincipalThenInteractAndUseOriginalPrincipal() {
|
||||
SecurityContextImpl context = new SecurityContextImpl(this.principal);
|
||||
when(this.repository.load(any())).thenReturn(Mono.just(context));
|
||||
this.handler = WebTestHandler.bindToWebFilters(this.filter, (e,c) ->
|
||||
this.handler = WebTestHandler.bindToWebFilters(this.filter, (e, c) ->
|
||||
ReactiveSecurityContextHolder.getContext()
|
||||
.map(SecurityContext::getAuthentication)
|
||||
.doOnSuccess( p -> assertThat(p).isSameAs(this.principal))
|
||||
|
|
|
@ -36,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
public class SecurityContextServerWebExchangeWebFilterTests {
|
||||
SecurityContextServerWebExchangeWebFilter filter = new SecurityContextServerWebExchangeWebFilter();
|
||||
|
||||
Authentication principal = new TestingAuthenticationToken("user","password", "ROLE_USER");
|
||||
Authentication principal = new TestingAuthenticationToken("user", "password", "ROLE_USER");
|
||||
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build());
|
||||
|
||||
|
@ -73,7 +73,7 @@ public class SecurityContextServerWebExchangeWebFilterTests {
|
|||
|
||||
@Test
|
||||
public void filterWhenPrincipalNullThenContextEmpty() {
|
||||
Authentication defaultAuthentication = new TestingAuthenticationToken("anonymouse","anonymous", "TEST");
|
||||
Authentication defaultAuthentication = new TestingAuthenticationToken("anonymouse", "anonymous", "TEST");
|
||||
Mono<Void> result = this.filter.filter(this.exchange, new DefaultWebFilterChain( e ->
|
||||
e.getPrincipal()
|
||||
.defaultIfEmpty(defaultAuthentication)
|
||||
|
|
|
@ -94,9 +94,9 @@ public class OnCommittedResponseWrapperTests {
|
|||
int off = 2;
|
||||
int len = 3;
|
||||
|
||||
response.getWriter().write(buff,off,len);
|
||||
response.getWriter().write(buff, off, len);
|
||||
|
||||
verify(writer).write(buff,off,len);
|
||||
verify(writer).write(buff, off, len);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -114,9 +114,9 @@ public class OnCommittedResponseWrapperTests {
|
|||
int off = 2;
|
||||
int len = 3;
|
||||
|
||||
response.getWriter().write(s,off,len);
|
||||
response.getWriter().write(s, off, len);
|
||||
|
||||
verify(writer).write(s,off,len);
|
||||
verify(writer).write(s, off, len);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -602,7 +602,7 @@ public class OnCommittedResponseWrapperTests {
|
|||
int len = 3;
|
||||
response.setContentLength(3);
|
||||
|
||||
response.getWriter().write(buff,off,len);
|
||||
response.getWriter().write(buff, off, len);
|
||||
|
||||
assertThat(committed).isTrue();
|
||||
}
|
||||
|
@ -624,7 +624,7 @@ public class OnCommittedResponseWrapperTests {
|
|||
int len = 3;
|
||||
response.setContentLength(3);
|
||||
|
||||
response.getWriter().write(s,off,len);
|
||||
response.getWriter().write(s, off, len);
|
||||
|
||||
assertThat(committed).isTrue();
|
||||
}
|
||||
|
@ -1104,7 +1104,7 @@ public class OnCommittedResponseWrapperTests {
|
|||
@Test
|
||||
public void addHeaderContentLengthPrintWriterWriteStringCommits() throws Exception {
|
||||
int expected = 1234;
|
||||
response.addHeader("Content-Length",String.valueOf(String.valueOf(expected).length()));
|
||||
response.addHeader("Content-Length", String.valueOf(String.valueOf(expected).length()));
|
||||
|
||||
response.getWriter().write(expected);
|
||||
|
||||
|
|
Loading…
Reference in New Issue