Example usage for org.springframework.util Assert notEmpty

List of usage examples for org.springframework.util Assert notEmpty

Introduction

In this page you can find the example usage for org.springframework.util Assert notEmpty.

Prototype

public static void notEmpty(@Nullable Map<?, ?> map, Supplier<String> messageSupplier) 

Source Link

Document

Assert that a Map contains entries; that is, it must not be null and must contain at least one entry.

Usage

From source file:org.springframework.oxm.jaxb.Jaxb2Marshaller.java

/**
 * Set multiple JAXB context paths. The given array of context paths gets
 * converted to a colon-delimited string, as supported by JAXB.
 *//*from  w w w. j  a  v  a  2s  .c om*/
public void setContextPaths(String... contextPaths) {
    Assert.notEmpty(contextPaths, "'contextPaths' must not be empty");
    this.contextPath = StringUtils.arrayToDelimitedString(contextPaths, ":");
}

From source file:org.springframework.oxm.jaxb.Jaxb2Marshaller.java

@SuppressWarnings("deprecation") // on JDK 9
private Schema loadSchema(Resource[] resources, String schemaLanguage) throws IOException, SAXException {
    if (logger.isDebugEnabled()) {
        logger.debug("Setting validation schema to "
                + StringUtils.arrayToCommaDelimitedString(this.schemaResources));
    }//from   w  ww  . j  a v  a  2  s  .com
    Assert.notEmpty(resources, "No resources given");
    Assert.hasLength(schemaLanguage, "No schema language provided");
    Source[] schemaSources = new Source[resources.length];
    XMLReader xmlReader = org.xml.sax.helpers.XMLReaderFactory.createXMLReader();
    xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
    for (int i = 0; i < resources.length; i++) {
        Assert.notNull(resources[i], "Resource is null");
        Assert.isTrue(resources[i].exists(), "Resource " + resources[i] + " does not exist");
        InputSource inputSource = SaxResourceUtils.createInputSource(resources[i]);
        schemaSources[i] = new SAXSource(xmlReader, inputSource);
    }
    SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaLanguage);
    if (this.schemaResourceResolver != null) {
        schemaFactory.setResourceResolver(this.schemaResourceResolver);
    }
    return schemaFactory.newSchema(schemaSources);
}

From source file:org.springframework.security.access.vote.AbstractAccessDecisionManager.java

protected AbstractAccessDecisionManager(List<AccessDecisionVoter<? extends Object>> decisionVoters) {
    Assert.notEmpty(decisionVoters, "A list of AccessDecisionVoters is required");
    this.decisionVoters = decisionVoters;
}

From source file:org.springframework.security.access.vote.AbstractAccessDecisionManager.java

public void afterPropertiesSet() throws Exception {
    Assert.notEmpty(this.decisionVoters, "A list of AccessDecisionVoters is required");
    Assert.notNull(this.messages, "A message source must be set");
}

From source file:org.springframework.security.acls.cassandra.CassandraAclService.java

public Map<ObjectIdentity, Acl> readAclsById(List<ObjectIdentity> objects, List<Sid> sids)
        throws NotFoundException {
    Assert.notEmpty(objects, "Objects to lookup required");

    if (LOG.isDebugEnabled()) {
        LOG.debug("BEGIN readAclById: objectIdentities: " + objects + ", sids: " + sids);
    }//from   www .j av a2 s .com

    // contains FULLY loaded Acl objects
    Map<ObjectIdentity, Acl> result = new HashMap<ObjectIdentity, Acl>();
    List<ObjectIdentity> objectsToLookup = new ArrayList<ObjectIdentity>(objects);

    // Check for Acls in the cache
    if (aclCache != null) {
        for (ObjectIdentity oi : objects) {
            boolean aclLoaded = false;

            Acl acl = aclCache.getFromCache(oi);
            if (acl != null && acl.isSidLoaded(sids)) {
                // Ensure any cached element supports all the requested SIDs
                result.put(oi, acl);
                aclLoaded = true;
            }
            if (aclLoaded) {
                objectsToLookup.remove(oi);
            }
        }
    }

    if (!objectsToLookup.isEmpty()) {
        Map<ObjectIdentity, Acl> loadedAcls = doLookup(objectsToLookup);
        result.putAll(loadedAcls);

        // Put loaded Acls in the cache
        if (aclCache != null) {
            for (Acl loadedAcl : loadedAcls.values()) {
                aclCache.putInCache((AclImpl) loadedAcl);
            }
        }
    }

    for (ObjectIdentity oid : objects) {
        if (!result.containsKey(oid)) {
            throw new NotFoundException("Unable to find ACL information for object identity '" + oid + "'");
        }
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("END readAclById: acls: " + result.values());
    }
    return result;
}

From source file:org.springframework.security.authentication.jaas.AbstractJaasAuthenticationProvider.java

/**
 * Validates the required properties are set. In addition, if
 * {@link #setCallbackHandlers(JaasAuthenticationCallbackHandler[])} has not been
 * called with valid handlers, initializes to use {@link JaasNameCallbackHandler} and
 * {@link JaasPasswordCallbackHandler}./*  ww  w.  j a va 2  s .  c  o m*/
 */
public void afterPropertiesSet() throws Exception {
    Assert.hasLength(this.loginContextName, "loginContextName cannot be null or empty");
    Assert.notEmpty(this.authorityGranters, "authorityGranters cannot be null or empty");
    if (ObjectUtils.isEmpty(this.callbackHandlers)) {
        setCallbackHandlers(new JaasAuthenticationCallbackHandler[] { new JaasNameCallbackHandler(),
                new JaasPasswordCallbackHandler() });
    }
    Assert.notNull(this.loginExceptionResolver, "loginExceptionResolver cannot be null");
}

From source file:org.springframework.security.config.method.ProtectPointcutPostProcessor.java

public void setPointcutMap(Map<String, List<ConfigAttribute>> map) {
    Assert.notEmpty(map, "configAttributes cannot be empty");
    for (String expression : map.keySet()) {
        List<ConfigAttribute> value = map.get(expression);
        addPointcut(expression, value);/*from  w  w  w. j  a  v a2s. c  o m*/
    }
}

From source file:org.springframework.security.ldap.DefaultSpringSecurityContextSource.java

/**
 * Builds a Spring LDAP-compliant Provider URL string, i.e. a space-separated list of
 * LDAP servers with their base DNs. As the base DN must be identical for all servers,
 * it needs to be supplied only once.//from www.j  a v  a 2s.  c  o  m
 *
 * @param urls A list of string values which are LDAP server URLs. An example would be
 *
 * <pre>
 * ldap://ldap.company.com:389
 * </pre>
 *
 * . LDAPS URLs may be used as well, given that Spring Security is able to connect to
 * the server.
 * @param baseDn The common Base DN for all provided servers, e.g.
 *
 * <pre>
 * dc=company,dc=com
 * </pre>
 *
 * .
 * @return A Spring Security/Spring LDAP-compliant Provider URL string.
 */
private static String buildProviderUrl(List<String> urls, String baseDn) {
    Assert.notNull(baseDn, "The Base DN for the LDAP server must not be null.");
    Assert.notEmpty(urls, "At least one LDAP server URL must be provided.");

    String trimmedBaseDn = baseDn.trim();
    StringBuilder providerUrl = new StringBuilder();

    for (String serverUrl : urls) {
        String trimmedUrl = serverUrl.trim();
        if ("".equals(trimmedUrl)) {
            continue;
        }

        providerUrl.append(trimmedUrl);
        if (!trimmedUrl.endsWith("/")) {
            providerUrl.append("/");
        }
        providerUrl.append(trimmedBaseDn);
        providerUrl.append(" ");
    }

    return providerUrl.toString();

}

From source file:org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint.java

public void afterPropertiesSet() throws Exception {
    Assert.notEmpty(entryPoints, "entryPoints must be specified");
    Assert.notNull(defaultEntryPoint, "defaultEntryPoint must be specified");
}

From source file:org.springframework.security.web.authentication.logout.LogoutFilter.java

/**
 * Constructor which takes a <tt>LogoutSuccessHandler</tt> instance to determine the target destination
 * after logging out. The list of <tt>LogoutHandler</tt>s are intended to perform the actual logout functionality
 * (such as clearing the security context, invalidating the session, etc.).
 *///from w ww  . j  ava2s  . c  o  m
public LogoutFilter(LogoutSuccessHandler logoutSuccessHandler, LogoutHandler... handlers) {
    Assert.notEmpty(handlers, "LogoutHandlers are required");
    this.handlers = Arrays.asList(handlers);
    Assert.notNull(logoutSuccessHandler, "logoutSuccessHandler cannot be null");
    this.logoutSuccessHandler = logoutSuccessHandler;
    setFilterProcessesUrl("/j_spring_security_logout");
}