List of usage examples for org.springframework.util Assert notEmpty
public static void notEmpty(@Nullable Map<?, ?> map, Supplier<String> messageSupplier)
From source file:org.springframework.security.web.authentication.logout.LogoutFilter.java
public LogoutFilter(String logoutSuccessUrl, LogoutHandler... handlers) { Assert.notEmpty(handlers, "LogoutHandlers are required"); this.handlers = Arrays.asList(handlers); Assert.isTrue(!StringUtils.hasLength(logoutSuccessUrl) || UrlUtils.isValidRedirectUrl(logoutSuccessUrl), logoutSuccessUrl + " isn't a valid redirect URL"); SimpleUrlLogoutSuccessHandler urlLogoutSuccessHandler = new SimpleUrlLogoutSuccessHandler(); if (StringUtils.hasText(logoutSuccessUrl)) { urlLogoutSuccessHandler.setDefaultTargetUrl(logoutSuccessUrl); }/*w ww .j a va2 s . c o m*/ logoutSuccessHandler = urlLogoutSuccessHandler; setFilterProcessesUrl("/j_spring_security_logout"); }
From source file:org.springframework.security.web.authentication.session.CompositeSessionAuthenticationStrategy.java
public CompositeSessionAuthenticationStrategy(List<SessionAuthenticationStrategy> delegateStrategies) { Assert.notEmpty(delegateStrategies, "delegateStrategies cannot be null or empty"); for (SessionAuthenticationStrategy strategy : delegateStrategies) { if (strategy == null) { throw new IllegalArgumentException( "delegateStrategies cannot contain null entires. Got " + delegateStrategies); }/*from ww w . j ava 2 s . com*/ } this.delegateStrategies = delegateStrategies; }
From source file:org.springframework.security.web.header.writers.ClearSiteDataHeaderWriter.java
/** * <p>//w w w. jav a 2 s . c o m * Creates a new instance of {@link ClearSiteDataHeaderWriter} with given sources. * The constructor also initializes <b>requestMatcher</b> with a new instance of * <b>SecureRequestMatcher</b> to ensure that header is only applied if and when * the request is secure as per the <b>Incomplete Clearing</b> section. * </p> * * @param sources (i.e. "cache", "cookies", "storage", "executionContexts" or "*") * @throws {@link IllegalArgumentException} if sources is null or empty. */ public ClearSiteDataHeaderWriter(String... sources) { Assert.notEmpty(sources, "sources cannot be empty or null"); this.requestMatcher = new SecureRequestMatcher(); this.headerValue = Stream.of(sources).map(this::quote).collect(Collectors.joining(", ")); }
From source file:org.springframework.security.web.server.util.matcher.MediaTypeServerWebExchangeMatcher.java
/** * Creates a new instance/*from w ww. jav a2 s . c o m*/ * @param matchingMediaTypes the types to match on */ public MediaTypeServerWebExchangeMatcher(MediaType... matchingMediaTypes) { Assert.notEmpty(matchingMediaTypes, "matchingMediaTypes cannot be null"); Assert.noNullElements(matchingMediaTypes, "matchingMediaTypes cannot contain null"); this.matchingMediaTypes = Arrays.asList(matchingMediaTypes); }
From source file:org.springframework.security.web.server.util.matcher.MediaTypeServerWebExchangeMatcher.java
/** * Creates a new instance/*w ww. ja va 2s. c o m*/ * @param matchingMediaTypes the types to match on */ public MediaTypeServerWebExchangeMatcher(Collection<MediaType> matchingMediaTypes) { Assert.notEmpty(matchingMediaTypes, "matchingMediaTypes cannot be null"); Assert.isTrue(!matchingMediaTypes.contains(null), () -> "matchingMediaTypes cannot contain null. Got " + matchingMediaTypes); this.matchingMediaTypes = matchingMediaTypes; }
From source file:org.springframework.security.web.util.matcher.AndRequestMatcher.java
/** * Creates a new instance/*w w w . j a va 2 s .com*/ * * @param requestMatchers the {@link RequestMatcher} instances to try */ public AndRequestMatcher(List<RequestMatcher> requestMatchers) { Assert.notEmpty(requestMatchers, "requestMatchers must contain a value"); if (requestMatchers.contains(null)) { throw new IllegalArgumentException("requestMatchers cannot contain null values"); } this.requestMatchers = requestMatchers; }
From source file:org.springframework.security.web.util.matcher.MediaTypeRequestMatcher.java
/** * Creates an instance/*from ww w . ja v a2 s . c o m*/ * @param contentNegotiationStrategy the {@link ContentNegotiationStrategy} to use * @param matchingMediaTypes the {@link MediaType} that will make the * {@link RequestMatcher} return true */ public MediaTypeRequestMatcher(ContentNegotiationStrategy contentNegotiationStrategy, Collection<MediaType> matchingMediaTypes) { Assert.notNull(contentNegotiationStrategy, "ContentNegotiationStrategy cannot be null"); Assert.notEmpty(matchingMediaTypes, "matchingMediaTypes cannot be null or empty"); this.contentNegotiationStrategy = contentNegotiationStrategy; this.matchingMediaTypes = matchingMediaTypes; }
From source file:org.springframework.security.web.util.matcher.OrRequestMatcher.java
/** * Creates a new instance/*from w w w . j av a2s. c o m*/ * * @param requestMatchers the {@link RequestMatcher} instances to try */ public OrRequestMatcher(List<RequestMatcher> requestMatchers) { Assert.notEmpty(requestMatchers, "requestMatchers must contain a value"); if (requestMatchers.contains(null)) { throw new IllegalArgumentException("requestMatchers cannot contain null values"); } this.requestMatchers = requestMatchers; }
From source file:org.springframework.test.context.ContextLoaderUtils.java
/** * Resolve the {@link ContextLoader} {@linkplain Class class} to use for the supplied * list of {@link ContextConfigurationAttributes} and then instantiate and return that * {@code ContextLoader}.//from w w w . j a v a 2s. c om * * <p>If the supplied {@code defaultContextLoaderClassName} is {@code null} or * <em>empty</em>, depending on the absence or presence of * {@link org.springframework.test.context.web.WebAppConfiguration @WebAppConfiguration} either * {@code "org.springframework.test.context.support.DelegatingSmartContextLoader"} or * {@code "org.springframework.test.context.web.WebDelegatingSmartContextLoader"} will * be used as the default context loader class name. For details on the class * resolution process, see {@link #resolveContextLoaderClass}. * * @param testClass the test class for which the {@code ContextLoader} should be * resolved; must not be {@code null} * @param configAttributesList the list of configuration attributes to process; must * not be {@code null} or <em>empty</em>; must be ordered <em>bottom-up</em> * (i.e., as if we were traversing up the class hierarchy) * @param defaultContextLoaderClassName the name of the default {@code ContextLoader} * class to use; may be {@code null} or <em>empty</em> * @return the resolved {@code ContextLoader} for the supplied {@code testClass} * (never {@code null}) * @see #resolveContextLoaderClass */ static ContextLoader resolveContextLoader(Class<?> testClass, List<ContextConfigurationAttributes> configAttributesList, String defaultContextLoaderClassName) { Assert.notNull(testClass, "Class must not be null"); Assert.notEmpty(configAttributesList, "ContextConfigurationAttributes list must not be empty"); if (!StringUtils.hasText(defaultContextLoaderClassName)) { Class<? extends Annotation> webAppConfigClass = loadWebAppConfigurationClass(); defaultContextLoaderClassName = webAppConfigClass != null && testClass.isAnnotationPresent(webAppConfigClass) ? DEFAULT_WEB_CONTEXT_LOADER_CLASS_NAME : DEFAULT_CONTEXT_LOADER_CLASS_NAME; } Class<? extends ContextLoader> contextLoaderClass = resolveContextLoaderClass(testClass, configAttributesList, defaultContextLoaderClassName); return instantiateClass(contextLoaderClass, ContextLoader.class); }
From source file:org.springframework.test.context.ContextLoaderUtils.java
/** * Resolve the {@link ContextLoader} {@linkplain Class class} to use for the supplied * list of {@link ContextConfigurationAttributes}. * * <p>Beginning with the first level in the context configuration attributes hierarchy: * * <ol>// w w w . j a v a 2 s .c o m * <li>If the {@link ContextConfigurationAttributes#getContextLoaderClass() * contextLoaderClass} property of {@link ContextConfigurationAttributes} is * configured with an explicit class, that class will be returned.</li> * <li>If an explicit {@code ContextLoader} class is not specified at the current * level in the hierarchy, traverse to the next level in the hierarchy and return to * step #1.</li> * <li>If no explicit {@code ContextLoader} class is found after traversing the * hierarchy, an attempt will be made to load and return the class with the supplied * {@code defaultContextLoaderClassName}.</li> * </ol> * * @param testClass the class for which to resolve the {@code ContextLoader} class; * must not be {@code null}; only used for logging purposes * @param configAttributesList the list of configuration attributes to process; must * not be {@code null} or <em>empty</em>; must be ordered <em>bottom-up</em> * (i.e., as if we were traversing up the class hierarchy) * @param defaultContextLoaderClassName the name of the default {@code ContextLoader} * class to use; must not be {@code null} or empty * @return the {@code ContextLoader} class to use for the supplied test class * @throws IllegalArgumentException if {@code @ContextConfiguration} is not * <em>present</em> on the supplied test class * @throws IllegalStateException if the default {@code ContextLoader} class could not * be loaded */ @SuppressWarnings("unchecked") static Class<? extends ContextLoader> resolveContextLoaderClass(Class<?> testClass, List<ContextConfigurationAttributes> configAttributesList, String defaultContextLoaderClassName) { Assert.notNull(testClass, "Class must not be null"); Assert.notEmpty(configAttributesList, "ContextConfigurationAttributes list must not be empty"); Assert.hasText(defaultContextLoaderClassName, "Default ContextLoader class name must not be null or empty"); for (ContextConfigurationAttributes configAttributes : configAttributesList) { if (logger.isTraceEnabled()) { logger.trace(String.format("Processing ContextLoader for context configuration attributes %s", configAttributes)); } Class<? extends ContextLoader> contextLoaderClass = configAttributes.getContextLoaderClass(); if (!ContextLoader.class.equals(contextLoaderClass)) { if (logger.isDebugEnabled()) { logger.debug(String.format( "Found explicit ContextLoader class [%s] for context configuration attributes %s", contextLoaderClass.getName(), configAttributes)); } return contextLoaderClass; } } try { if (logger.isTraceEnabled()) { logger.trace(String.format("Using default ContextLoader class [%s] for test class [%s]", defaultContextLoaderClassName, testClass.getName())); } return (Class<? extends ContextLoader>) ClassUtils.forName(defaultContextLoaderClassName, ContextLoaderUtils.class.getClassLoader()); } catch (Throwable t) { throw new IllegalStateException("Could not load default ContextLoader class [" + defaultContextLoaderClassName + "]. Specify @ContextConfiguration's 'loader' " + "attribute or make the default loader class available.", t); } }