Example usage for java.util Collection containsAll

List of usage examples for java.util Collection containsAll

Introduction

In this page you can find the example usage for java.util Collection containsAll.

Prototype

boolean containsAll(Collection<?> c);

Source Link

Document

Returns true if this collection contains all of the elements in the specified collection.

Usage

From source file:com.task.springsec.SecurityUtil.java

/**
 * test if current user principal contains all given authorities
 *   //  w  w  w. j ava2 s .com
 * @param authorities the roles will be checked 
 */
public static void assertAll(String... authorities) {

    if (null == authorities || authorities.length == 0) {
        return;
    }

    final ArrayList<GrantedAuthority> required = new ArrayList<GrantedAuthority>();
    for (String auth : authorities) {
        required.add(new GrantedAuthorityImpl(auth));
    }

    final Collection<? extends GrantedAuthority> granted = getPrincipalAuthorities();
    if (!granted.containsAll(required)) {
        Authentication currentUser = SecurityContextHolder.getContext().getAuthentication();
        throw new AccessDeniedException("The current principal doesn't has enough authority. Authentication: "
                + (currentUser == null ? "" : currentUser.getName()));
    }
}

From source file:com.task.springsec.SecurityUtil.java

/**
 * Return true if the authenticated principal is granted ALL of the roles 
 * specified in authorities.//ww  w .j  a  va  2s .  co  m
 * 
 * @param authorities A comma separated list of roles which the user must have  
 * been granted ALL.
 * @return true true if the authenticated principal is granted authorities 
 * of ALL the specified roles.
 */
public static boolean isAllGranted(String authorities) {
    if (null == authorities || "".equals(authorities)) {
        return false;
    }
    final Collection<? extends GrantedAuthority> granted = getPrincipalAuthorities();
    boolean isAllGranted = granted.containsAll(parseAuthorities(authorities));
    return isAllGranted;
}

From source file:id.co.sigma.zk.spring.security.SecurityUtil.java

/**
 * test if current user principal contains all given authorities
 *   /*from  w  w w . j a v  a  2  s. c  om*/
 * @param authorities the roles will be checked 
 */
public static void assertAll(String... authorities) {

    if (null == authorities || authorities.length == 0) {
        return;
    }

    final ArrayList<GrantedAuthority> required = new ArrayList<GrantedAuthority>();
    for (String auth : authorities) {
        required.add(new SimpleGrantedAuthority(auth));
    }

    final Collection<? extends GrantedAuthority> granted = getPrincipalAuthorities();
    if (!granted.containsAll(required)) {
        Authentication currentUser = SecurityContextHolder.getContext().getAuthentication();
        throw new AccessDeniedException("The current principal doesn't has enough authority. Authentication: "
                + (currentUser == null ? "" : currentUser.getName()));
    }
}

From source file:nc.noumea.mairie.annuairev2.saisie.core.security.SecurityUtil.java

/**
 * test if current user principal contains all given authorities
 *
 * @param authorities/*www  .java2 s .  c o  m*/
 *            the roles will be checked
 */
public static void assertAll(String... authorities) {

    if (null == authorities || authorities.length == 0) {
        return;
    }

    final ArrayList<GrantedAuthority> required = new ArrayList<>();
    for (String auth : authorities) {
        required.add(new SimpleGrantedAuthority(auth));
    }

    final Collection<? extends GrantedAuthority> granted = getPrincipalAuthorities();
    if (!granted.containsAll(required)) {
        Authentication currentUser = SecurityContextHolder.getContext().getAuthentication();
        throw new AccessDeniedException("The current principal doesn't has enough authority. Authentication: "
                + (currentUser == null ? "" : currentUser.getName()));
    }
}

From source file:com.cloudera.oryx.common.OryxTest.java

public static <T> void assertContainsSame(Collection<T> expected, Collection<T> actual) {
    if (expected == null) {
        assertNull(actual);// www.  j  a  v  a  2  s .  c om
    } else {
        assertNotNull(actual);
        assertEquals(expected.size(), actual.size());
        if (!expected.containsAll(actual)) {
            fail("Found unexpected values " + minus(actual, expected));
        }
        if (!actual.containsAll(expected)) {
            fail("Missing values " + minus(expected, actual));
        }
    }
}

From source file:org.dawnsci.jexl.internal.ExpressionEngineImpl.java

private static void test(String expr, String... vars) throws Exception {

    ExpressionEngineImpl impl = new ExpressionEngineImpl();
    final Collection<String> found = impl.getLazyVariables(expr);

    if (found.size() != vars.length)
        throw new Exception("Incorrect number of variables found!");
    if (!found.containsAll(Arrays.asList(vars)))
        throw new Exception("Incorrect number of variables found!");
    System.out.println(found);// w  w w .j a v a 2 s .com
    System.out.println(">>>> Ok <<<<");
}

From source file:ubic.basecode.util.RegressionTesting.java

/**
 * Test whether two collections contain the same items.
 * /* ww  w . j  a  v a2 s .c  om*/
 * @param a
 * @param b
 * @return
 */
public static boolean containsSame(Collection<? extends Object> a, Collection<? extends Object> b) {
    if (a.size() != b.size())
        return false;

    if (!a.containsAll(b))
        return false;

    return true;
}

From source file:org.ms123.common.data.Utils.java

public static <T> boolean isCollectionEqual(Collection<T> lhs, Collection<T> rhs) {
    return lhs.size() == rhs.size() && lhs.containsAll(rhs) && rhs.containsAll(lhs);
}

From source file:com.threewks.thundr.view.jsp.el.CollectionFunctions.java

/**
 * //from  ww w.j  a  v  a 2s.  com
 * @param collectionOrArray a {@link Collection} or array of object
 * @param objectCollectionOrArray a single object, and array of objects or a {@link Collection} of objects
 * @return true if the first argument contains all of the elements in the second argument. If the second argument is an empty collection, returns true. if the second element is null, returns true
 *         if a null is contained in the first argument.
 */
@SuppressWarnings("unchecked")
public static boolean contains(Object collectionOrArray, Object objectCollectionOrArray) {
    Collection<Object> collection = toCollection(collectionOrArray);
    Collection<Object> asCollection = Cast.as(objectCollectionOrArray, Collection.class);
    if (asCollection == null) {
        asCollection = isArray(objectCollectionOrArray) ? Arrays.asList((Object[]) objectCollectionOrArray)
                : Collections.singleton(objectCollectionOrArray);
    }

    return collection.containsAll(asCollection);
}

From source file:org.zkoss.spring.security.SecurityUtil.java

/**
 * Return true if the authenticated principal is granted ALL of the roles 
 * specified in authorities.//from  w w w  .  j ava  2  s. c  om
 * 
 * @param authorities A comma separated list of roles which the user must have  
 * been granted ALL.
 * @return true true if the authenticated principal is granted authorities 
 * of ALL the specified roles.
 */
public static boolean isAllGranted(String authorities) {
    if (null == authorities || "".equals(authorities)) {
        return false;
    }
    final Collection<? extends GrantedAuthority> granted = getPrincipalAuthorities();
    boolean isAllGranted = granted.containsAll(parseAuthoritiesString(authorities));
    return isAllGranted;
}