Use Supplier variants of Assert methods

This commit is contained in:
Christoph Dreis 2018-03-26 22:57:52 +02:00 committed by Rob Winch
parent 7d4e7bf42d
commit d07cfe655d
32 changed files with 69 additions and 66 deletions

View File

@ -92,11 +92,11 @@ public abstract class AclFormattingUtils {
*/ */
public static String printBinary(int mask, char code) { public static String printBinary(int mask, char code) {
Assert.doesNotContain(Character.toString(code), Assert.doesNotContain(Character.toString(code),
Character.toString(Permission.RESERVED_ON), Permission.RESERVED_ON Character.toString(Permission.RESERVED_ON),
+ " is a reserved character code"); () -> Permission.RESERVED_ON + " is a reserved character code");
Assert.doesNotContain(Character.toString(code), Assert.doesNotContain(Character.toString(code),
Character.toString(Permission.RESERVED_OFF), Permission.RESERVED_OFF Character.toString(Permission.RESERVED_OFF),
+ " is a reserved character code"); () -> Permission.RESERVED_OFF + " is a reserved character code");
return printBinary(mask, Permission.RESERVED_ON, Permission.RESERVED_OFF) return printBinary(mask, Permission.RESERVED_ON, Permission.RESERVED_OFF)
.replace(Permission.RESERVED_ON, code); .replace(Permission.RESERVED_ON, code);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -104,9 +104,9 @@ public class DefaultPermissionFactory implements PermissionFactory {
// Ensure no existing Permission uses this integer or code // Ensure no existing Permission uses this integer or code
Assert.isTrue(!registeredPermissionsByInteger.containsKey(mask), Assert.isTrue(!registeredPermissionsByInteger.containsKey(mask),
"An existing Permission already provides mask " + mask); () -> "An existing Permission already provides mask " + mask);
Assert.isTrue(!registeredPermissionsByName.containsKey(permissionName), Assert.isTrue(!registeredPermissionsByName.containsKey(permissionName),
"An existing Permission already provides name '" + permissionName + "'"); () -> "An existing Permission already provides name '" + permissionName + "'");
// Register the new Permission // Register the new Permission
registeredPermissionsByInteger.put(mask, perm); registeredPermissionsByInteger.put(mask, perm);

View File

@ -111,7 +111,7 @@ public class JdbcAclService implements AclService {
throws NotFoundException { throws NotFoundException {
Map<ObjectIdentity, Acl> map = readAclsById(Arrays.asList(object), sids); Map<ObjectIdentity, Acl> map = readAclsById(Arrays.asList(object), sids);
Assert.isTrue(map.containsKey(object), Assert.isTrue(map.containsKey(object),
"There should have been an Acl entry for ObjectIdentity " + object); () -> "There should have been an Acl entry for ObjectIdentity " + object);
return (Acl) map.get(object); return (Acl) map.get(object);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -152,7 +152,7 @@ public class AuthenticationConfiguration {
return null; return null;
} }
Assert.isTrue(beanNamesForType.length == 1, Assert.isTrue(beanNamesForType.length == 1,
"Expecting to only find a single bean for type " + interfaceName () -> "Expecting to only find a single bean for type " + interfaceName
+ ", but found " + Arrays.asList(beanNamesForType)); + ", but found " + Arrays.asList(beanNamesForType));
lazyTargetSource.setTargetBeanName(beanNamesForType[0]); lazyTargetSource.setTargetBeanName(beanNamesForType[0]);
lazyTargetSource.setBeanFactory(applicationContext); lazyTargetSource.setBeanFactory(applicationContext);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -457,7 +457,7 @@ public class GlobalMethodSecurityConfiguration
EnableGlobalMethodSecurity methodSecurityAnnotation = AnnotationUtils EnableGlobalMethodSecurity methodSecurityAnnotation = AnnotationUtils
.findAnnotation(getClass(), EnableGlobalMethodSecurity.class); .findAnnotation(getClass(), EnableGlobalMethodSecurity.class);
Assert.notNull(methodSecurityAnnotation, Assert.notNull(methodSecurityAnnotation,
EnableGlobalMethodSecurity.class.getName() + " is required"); () -> EnableGlobalMethodSecurity.class.getName() + " is required");
Map<String, Object> methodSecurityAttrs = AnnotationUtils Map<String, Object> methodSecurityAttrs = AnnotationUtils
.getAnnotationAttributes(methodSecurityAnnotation); .getAnnotationAttributes(methodSecurityAnnotation);
this.enableMethodSecurity = AnnotationAttributes.fromMap(methodSecurityAttrs); this.enableMethodSecurity = AnnotationAttributes.fromMap(methodSecurityAttrs);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -42,7 +42,7 @@ final class GlobalMethodSecuritySelector implements ImportSelector {
.getAnnotationAttributes(annoType.getName(), false); .getAnnotationAttributes(annoType.getName(), false);
AnnotationAttributes attributes = AnnotationAttributes AnnotationAttributes attributes = AnnotationAttributes
.fromMap(annotationAttributes); .fromMap(annotationAttributes);
Assert.notNull(attributes, String.format( Assert.notNull(attributes, () -> String.format(
"@%s is not present on importing class '%s' as expected", "@%s is not present on importing class '%s' as expected",
annoType.getSimpleName(), importingClassMetadata.getClassName())); annoType.getSimpleName(), importingClassMetadata.getClassName()));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -278,7 +278,9 @@ public final class WebSecurity extends
protected Filter performBuild() throws Exception { protected Filter performBuild() throws Exception {
Assert.state( Assert.state(
!securityFilterChainBuilders.isEmpty(), !securityFilterChainBuilders.isEmpty(),
"At least one SecurityBuilder<? extends SecurityFilterChain> needs to be specified. Typically this done by adding a @Configuration that extends WebSecurityConfigurerAdapter. More advanced users can invoke " () -> "At least one SecurityBuilder<? extends SecurityFilterChain> needs to be specified. "
+ "Typically this done by adding a @Configuration that extends WebSecurityConfigurerAdapter. "
+ "More advanced users can invoke "
+ WebSecurity.class.getSimpleName() + WebSecurity.class.getSimpleName()
+ ".addSecurityFilterChainBuilder directly"); + ".addSecurityFilterChainBuilder directly");
int chainSize = ignoredRequests.size() + securityFilterChainBuilders.size(); int chainSize = ignoredRequests.size() + securityFilterChainBuilders.size();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -220,7 +220,7 @@ public final class UrlAuthorizationConfigurer<H extends HttpSecurityBuilder<H>>
private static String hasRole(String role) { private static String hasRole(String role) {
Assert.isTrue( Assert.isTrue(
!role.startsWith("ROLE_"), !role.startsWith("ROLE_"),
role () -> role
+ " should not start with ROLE_ since ROLE_ is automatically prepended when using hasRole. Consider using hasAuthority or access instead."); + " should not start with ROLE_ since ROLE_ is automatically prepended when using hasRole. Consider using hasAuthority or access instead.");
return "ROLE_" + role; return "ROLE_" + role;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -103,7 +103,7 @@ public class AuthenticationManagerBeanDefinitionParser implements BeanDefinition
else { else {
BeanDefinition provider = resolver.resolve( BeanDefinition provider = resolver.resolve(
providerElt.getNamespaceURI()).parse(providerElt, pc); providerElt.getNamespaceURI()).parse(providerElt, pc);
Assert.notNull(provider, "Parser for " + providerElt.getNodeName() Assert.notNull(provider, () -> "Parser for " + providerElt.getNodeName()
+ " returned a null bean definition"); + " returned a null bean definition");
String providerId = pc.getReaderContext().generateBeanName(provider); String providerId = pc.getReaderContext().generateBeanName(provider);
pc.registerBeanComponent(new BeanComponentDefinition(provider, pc.registerBeanComponent(new BeanComponentDefinition(provider,

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -49,7 +49,7 @@ public class CachingUserDetailsService implements UserDetailsService {
user = delegate.loadUserByUsername(username); user = delegate.loadUserByUsername(username);
} }
Assert.notNull(user, "UserDetailsService " + delegate Assert.notNull(user, () -> "UserDetailsService " + delegate
+ " returned null for username " + username + ". " + " returned null for username " + username + ". "
+ "This is an interface contract violation"); + "This is an interface contract violation");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -512,7 +512,7 @@ public class GlobalMethodSecurityBeanDefinitionParser implements BeanDefinitionP
synchronized (delegateMonitor) { synchronized (delegateMonitor) {
if (delegate == null) { if (delegate == null) {
Assert.state(beanFactory != null, Assert.state(beanFactory != null,
"BeanFactory must be set to resolve " + authMgrBean); () -> "BeanFactory must be set to resolve " + authMgrBean);
try { try {
delegate = beanFactory.getBean(authMgrBean, delegate = beanFactory.getBean(authMgrBean,
AuthenticationManager.class); AuthenticationManager.class);

View File

@ -54,7 +54,7 @@ public class SecuredAnnotationSecurityMetadataSource extends
annotationType = (Class<? extends Annotation>) GenericTypeResolver annotationType = (Class<? extends Annotation>) GenericTypeResolver
.resolveTypeArgument(annotationExtractor.getClass(), .resolveTypeArgument(annotationExtractor.getClass(),
AnnotationMetadataExtractor.class); AnnotationMetadataExtractor.class);
Assert.notNull(annotationType, annotationExtractor.getClass().getName() Assert.notNull(annotationType, () -> annotationExtractor.getClass().getName()
+ " must supply a generic parameter for AnnotationMetadataExtractor"); + " must supply a generic parameter for AnnotationMetadataExtractor");
} }

View File

@ -136,18 +136,18 @@ public abstract class AbstractSecurityInterceptor implements InitializingBean,
"An SecurityMetadataSource is required"); "An SecurityMetadataSource is required");
Assert.isTrue(this.obtainSecurityMetadataSource() Assert.isTrue(this.obtainSecurityMetadataSource()
.supports(getSecureObjectClass()), .supports(getSecureObjectClass()),
"SecurityMetadataSource does not support secure object class: " () -> "SecurityMetadataSource does not support secure object class: "
+ getSecureObjectClass()); + getSecureObjectClass());
Assert.isTrue(this.runAsManager.supports(getSecureObjectClass()), Assert.isTrue(this.runAsManager.supports(getSecureObjectClass()),
"RunAsManager does not support secure object class: " () -> "RunAsManager does not support secure object class: "
+ getSecureObjectClass()); + getSecureObjectClass());
Assert.isTrue(this.accessDecisionManager.supports(getSecureObjectClass()), Assert.isTrue(this.accessDecisionManager.supports(getSecureObjectClass()),
"AccessDecisionManager does not support secure object class: " () -> "AccessDecisionManager does not support secure object class: "
+ getSecureObjectClass()); + getSecureObjectClass());
if (this.afterInvocationManager != null) { if (this.afterInvocationManager != null) {
Assert.isTrue(this.afterInvocationManager.supports(getSecureObjectClass()), Assert.isTrue(this.afterInvocationManager.supports(getSecureObjectClass()),
"AfterInvocationManager does not support secure object class: " () -> "AfterInvocationManager does not support secure object class: "
+ getSecureObjectClass()); + getSecureObjectClass());
} }

View File

@ -95,7 +95,7 @@ public class AfterInvocationProviderManager implements AfterInvocationManager,
for (Object currentObject : newList) { for (Object currentObject : newList) {
Assert.isInstanceOf(AfterInvocationProvider.class, currentObject, Assert.isInstanceOf(AfterInvocationProvider.class, currentObject,
"AfterInvocationProvider " + currentObject.getClass().getName() () -> "AfterInvocationProvider " + currentObject.getClass().getName()
+ " must implement AfterInvocationProvider"); + " must implement AfterInvocationProvider");
providers.add((AfterInvocationProvider) currentObject); providers.add((AfterInvocationProvider) currentObject);
} }

View File

@ -123,7 +123,7 @@ public class MapBasedMethodSecurityMetadataSource extends
} }
String methodName = name.substring(lastDotIndex + 1); String methodName = name.substring(lastDotIndex + 1);
Assert.hasText(methodName, "Method not found for '" + name + "'"); Assert.hasText(methodName, () -> "Method not found for '" + name + "'");
String typeName = name.substring(0, lastDotIndex); String typeName = name.substring(0, lastDotIndex);
Class<?> type = ClassUtils.resolveClassName(typeName, this.beanClassLoader); Class<?> type = ClassUtils.resolveClassName(typeName, this.beanClassLoader);

View File

@ -126,7 +126,7 @@ public abstract class AbstractUserDetailsAuthenticationProvider implements
public Authentication authenticate(Authentication authentication) public Authentication authenticate(Authentication authentication)
throws AuthenticationException { throws AuthenticationException {
Assert.isInstanceOf(UsernamePasswordAuthenticationToken.class, authentication, Assert.isInstanceOf(UsernamePasswordAuthenticationToken.class, authentication,
messages.getMessage( () -> messages.getMessage(
"AbstractUserDetailsAuthenticationProvider.onlySupports", "AbstractUserDetailsAuthenticationProvider.onlySupports",
"Only UsernamePasswordAuthenticationToken is supported")); "Only UsernamePasswordAuthenticationToken is supported"));

View File

@ -158,8 +158,9 @@ public class JaasAuthenticationProvider extends AbstractJaasAuthenticationProvid
// the superclass is not called because it does additional checks that are // the superclass is not called because it does additional checks that are
// non-passive // non-passive
Assert.hasLength(getLoginContextName(), Assert.hasLength(getLoginContextName(),
"loginContextName must be set on " + getClass()); () -> "loginContextName must be set on " + getClass());
Assert.notNull(this.loginConfig, "loginConfig must be set on " + getClass()); Assert.notNull(this.loginConfig,
() -> "loginConfig must be set on " + getClass());
configureJaas(this.loginConfig); configureJaas(this.loginConfig);
Assert.notNull(Configuration.getConfiguration(), Assert.notNull(Configuration.getConfiguration(),

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -100,7 +100,7 @@ public class KeyBasedPersistenceTokenService implements TokenService, Initializi
} }
String[] tokens = StringUtils.delimitedListToStringArray( String[] tokens = StringUtils.delimitedListToStringArray(
Utf8.decode(Base64.getDecoder().decode(Utf8.encode(key))), ":"); Utf8.decode(Base64.getDecoder().decode(Utf8.encode(key))), ":");
Assert.isTrue(tokens.length >= 4, "Expected 4 or more tokens but found " Assert.isTrue(tokens.length >= 4, () -> "Expected 4 or more tokens but found "
+ tokens.length); + tokens.length);
long creationTime; long creationTime;

View File

@ -433,7 +433,7 @@ public class User implements UserDetails, CredentialsContainer {
List<GrantedAuthority> authorities = new ArrayList<>( List<GrantedAuthority> authorities = new ArrayList<>(
roles.length); roles.length);
for (String role : roles) { for (String role : roles) {
Assert.isTrue(!role.startsWith("ROLE_"), role Assert.isTrue(!role.startsWith("ROLE_"), () -> role
+ " cannot start with ROLE_ (it is automatically added)"); + " cannot start with ROLE_ (it is automatically added)");
authorities.add(new SimpleGrantedAuthority("ROLE_" + role)); authorities.add(new SimpleGrantedAuthority("ROLE_" + role));
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -57,7 +57,7 @@ public abstract class AbstractLdapAuthenticationProvider
public Authentication authenticate(Authentication authentication) public Authentication authenticate(Authentication authentication)
throws AuthenticationException { throws AuthenticationException {
Assert.isInstanceOf(UsernamePasswordAuthenticationToken.class, authentication, Assert.isInstanceOf(UsernamePasswordAuthenticationToken.class, authentication,
this.messages.getMessage("LdapAuthenticationProvider.onlySupports", () -> this.messages.getMessage("LdapAuthenticationProvider.onlySupports",
"Only UsernamePasswordAuthenticationToken is supported")); "Only UsernamePasswordAuthenticationToken is supported"));
final UsernamePasswordAuthenticationToken userToken = (UsernamePasswordAuthenticationToken) authentication; final UsernamePasswordAuthenticationToken userToken = (UsernamePasswordAuthenticationToken) authentication;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -431,7 +431,7 @@ public final class ClientRegistration {
private void validateAuthorizationCodeGrantType() { private void validateAuthorizationCodeGrantType() {
Assert.isTrue(AuthorizationGrantType.AUTHORIZATION_CODE.equals(this.authorizationGrantType), Assert.isTrue(AuthorizationGrantType.AUTHORIZATION_CODE.equals(this.authorizationGrantType),
"authorizationGrantType must be " + AuthorizationGrantType.AUTHORIZATION_CODE.getValue()); () -> "authorizationGrantType must be " + AuthorizationGrantType.AUTHORIZATION_CODE.getValue());
Assert.hasText(this.registrationId, "registrationId cannot be empty"); Assert.hasText(this.registrationId, "registrationId cannot be empty");
Assert.hasText(this.clientId, "clientId cannot be empty"); Assert.hasText(this.clientId, "clientId cannot be empty");
Assert.hasText(this.clientSecret, "clientSecret cannot be empty"); Assert.hasText(this.clientSecret, "clientSecret cannot be empty");
@ -449,7 +449,7 @@ public final class ClientRegistration {
private void validateImplicitGrantType() { private void validateImplicitGrantType() {
Assert.isTrue(AuthorizationGrantType.IMPLICIT.equals(this.authorizationGrantType), Assert.isTrue(AuthorizationGrantType.IMPLICIT.equals(this.authorizationGrantType),
"authorizationGrantType must be " + AuthorizationGrantType.IMPLICIT.getValue()); () -> "authorizationGrantType must be " + AuthorizationGrantType.IMPLICIT.getValue());
Assert.hasText(this.registrationId, "registrationId cannot be empty"); Assert.hasText(this.registrationId, "registrationId cannot be empty");
Assert.hasText(this.clientId, "clientId cannot be empty"); Assert.hasText(this.clientId, "clientId cannot be empty");
Assert.hasText(this.redirectUriTemplate, "redirectUriTemplate cannot be empty"); Assert.hasText(this.redirectUriTemplate, "redirectUriTemplate cannot be empty");

View File

@ -92,7 +92,7 @@ public class ChannelDecisionManagerImpl implements ChannelDecisionManager,
for (Object currentObject : newList) { for (Object currentObject : newList) {
Assert.isInstanceOf(ChannelProcessor.class, currentObject, Assert.isInstanceOf(ChannelProcessor.class, currentObject,
"ChannelProcessor " + currentObject.getClass().getName() () -> "ChannelProcessor " + currentObject.getClass().getName()
+ " must implement ChannelProcessor"); + " must implement ChannelProcessor");
channelProcessors.add((ChannelProcessor) currentObject); channelProcessors.add((ChannelProcessor) currentObject);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -67,7 +67,7 @@ public final class ExpressionBasedFilterInvocationSecurityMetadataSource
.entrySet()) { .entrySet()) {
RequestMatcher request = entry.getKey(); RequestMatcher request = entry.getKey();
Assert.isTrue(entry.getValue().size() == 1, Assert.isTrue(entry.getValue().size() == 1,
"Expected a single expression attribute for " + request); () -> "Expected a single expression attribute for " + request);
ArrayList<ConfigAttribute> attributes = new ArrayList<>(1); ArrayList<ConfigAttribute> attributes = new ArrayList<>(1);
String expression = entry.getValue().toArray(new ConfigAttribute[1])[0] String expression = entry.getValue().toArray(new ConfigAttribute[1])[0]
.getAttribute(); .getAttribute();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -76,7 +76,7 @@ public class ExceptionMappingAuthenticationFailureHandler extends
"Exception key must be a String (the exception classname)."); "Exception key must be a String (the exception classname).");
Assert.isInstanceOf(String.class, url, "URL must be a String"); Assert.isInstanceOf(String.class, url, "URL must be a String");
Assert.isTrue(UrlUtils.isValidRedirectUrl((String) url), Assert.isTrue(UrlUtils.isValidRedirectUrl((String) url),
"Not a valid redirect URL: " + url); () -> "Not a valid redirect URL: " + url);
this.failureUrlMap.put((String) exception, (String) url); this.failureUrlMap.put((String) exception, (String) url);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -41,8 +41,8 @@ public class ForwardAuthenticationFailureHandler implements AuthenticationFailur
* @param forwardUrl * @param forwardUrl
*/ */
public ForwardAuthenticationFailureHandler(String forwardUrl) { public ForwardAuthenticationFailureHandler(String forwardUrl) {
Assert.isTrue(UrlUtils.isValidRedirectUrl(forwardUrl), "'" Assert.isTrue(UrlUtils.isValidRedirectUrl(forwardUrl),
+ forwardUrl + "' is not a valid forward URL"); () -> "'" + forwardUrl + "' is not a valid forward URL");
this.forwardUrl = forwardUrl; this.forwardUrl = forwardUrl;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -41,8 +41,8 @@ public class ForwardAuthenticationSuccessHandler implements AuthenticationSucces
* @param forwardUrl * @param forwardUrl
*/ */
public ForwardAuthenticationSuccessHandler(String forwardUrl) { public ForwardAuthenticationSuccessHandler(String forwardUrl) {
Assert.isTrue(UrlUtils.isValidRedirectUrl(forwardUrl), "'" Assert.isTrue(UrlUtils.isValidRedirectUrl(forwardUrl),
+ forwardUrl + "' is not a valid forward URL"); () -> "'" + forwardUrl + "' is not a valid forward URL");
this.forwardUrl = forwardUrl; this.forwardUrl = forwardUrl;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -123,8 +123,8 @@ public class SimpleUrlAuthenticationFailureHandler implements
* @param defaultFailureUrl the failure URL, for example "/loginFailed.jsp". * @param defaultFailureUrl the failure URL, for example "/loginFailed.jsp".
*/ */
public void setDefaultFailureUrl(String defaultFailureUrl) { public void setDefaultFailureUrl(String defaultFailureUrl) {
Assert.isTrue(UrlUtils.isValidRedirectUrl(defaultFailureUrl), "'" Assert.isTrue(UrlUtils.isValidRedirectUrl(defaultFailureUrl),
+ defaultFailureUrl + "' is not a valid redirect URL"); () -> "'" + defaultFailureUrl + "' is not a valid redirect URL");
this.defaultFailureUrl = defaultFailureUrl; this.defaultFailureUrl = defaultFailureUrl;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -42,8 +42,8 @@ public class ForwardLogoutSuccessHandler implements LogoutSuccessHandler {
* @param targetUrl the target URL * @param targetUrl the target URL
*/ */
public ForwardLogoutSuccessHandler(String targetUrl) { public ForwardLogoutSuccessHandler(String targetUrl) {
Assert.isTrue(UrlUtils.isValidRedirectUrl(targetUrl), "'" + targetUrl Assert.isTrue(UrlUtils.isValidRedirectUrl(targetUrl),
+ "' is not a valid target URL"); () -> "'" + targetUrl + "' is not a valid target URL");
this.targetUrl = targetUrl; this.targetUrl = targetUrl;
} }

View File

@ -81,7 +81,7 @@ public class LogoutFilter extends GenericFilterBean {
Assert.isTrue( Assert.isTrue(
!StringUtils.hasLength(logoutSuccessUrl) !StringUtils.hasLength(logoutSuccessUrl)
|| UrlUtils.isValidRedirectUrl(logoutSuccessUrl), || UrlUtils.isValidRedirectUrl(logoutSuccessUrl),
logoutSuccessUrl + " isn't a valid redirect URL"); () -> logoutSuccessUrl + " isn't a valid redirect URL");
SimpleUrlLogoutSuccessHandler urlLogoutSuccessHandler = new SimpleUrlLogoutSuccessHandler(); SimpleUrlLogoutSuccessHandler urlLogoutSuccessHandler = new SimpleUrlLogoutSuccessHandler();
if (StringUtils.hasText(logoutSuccessUrl)) { if (StringUtils.hasText(logoutSuccessUrl)) {
urlLogoutSuccessHandler.setDefaultTargetUrl(logoutSuccessUrl); urlLogoutSuccessHandler.setDefaultTargetUrl(logoutSuccessUrl);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -35,7 +35,7 @@ public class MatcherSecurityWebFilterChain implements SecurityWebFilterChain {
public MatcherSecurityWebFilterChain(ServerWebExchangeMatcher matcher, List<WebFilter> filters) { public MatcherSecurityWebFilterChain(ServerWebExchangeMatcher matcher, List<WebFilter> filters) {
Assert.notNull(matcher, "matcher cannot be null"); Assert.notNull(matcher, "matcher cannot be null");
Assert.notEmpty(filters, "filters cannot be null or empty. Got " + filters); Assert.notEmpty(filters, () -> "filters cannot be null or empty. Got " + filters);
this.matcher = matcher; this.matcher = matcher;
this.filters = filters; this.filters = filters;
} }

View File

@ -93,7 +93,7 @@ public class ConcurrentSessionFilter extends GenericFilterBean {
public ConcurrentSessionFilter(SessionRegistry sessionRegistry, String expiredUrl) { public ConcurrentSessionFilter(SessionRegistry sessionRegistry, String expiredUrl) {
Assert.notNull(sessionRegistry, "SessionRegistry required"); Assert.notNull(sessionRegistry, "SessionRegistry required");
Assert.isTrue(expiredUrl == null || UrlUtils.isValidRedirectUrl(expiredUrl), Assert.isTrue(expiredUrl == null || UrlUtils.isValidRedirectUrl(expiredUrl),
expiredUrl + " isn't a valid redirect URL"); () -> expiredUrl + " isn't a valid redirect URL");
this.expiredUrl = expiredUrl; this.expiredUrl = expiredUrl;
this.sessionRegistry = sessionRegistry; this.sessionRegistry = sessionRegistry;
this.sessionInformationExpiredStrategy = new SessionInformationExpiredStrategy() { this.sessionInformationExpiredStrategy = new SessionInformationExpiredStrategy() {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -371,8 +371,8 @@ public class ResolvableMethod {
*/ */
public ResolvableMethod build() { public ResolvableMethod build() {
Set<Method> methods = MethodIntrospector.selectMethods(this.objectClass, this::isMatch); Set<Method> methods = MethodIntrospector.selectMethods(this.objectClass, this::isMatch);
Assert.state(!methods.isEmpty(), "No matching method: " + this); Assert.state(!methods.isEmpty(), () -> "No matching method: " + this);
Assert.state(methods.size() == 1, "Multiple matching methods: " + this + formatMethods(methods)); Assert.state(methods.size() == 1, () -> "Multiple matching methods: " + this + formatMethods(methods));
return new ResolvableMethod(methods.iterator().next()); return new ResolvableMethod(methods.iterator().next());
} }