List of usage examples for java.util Collections disjoint
public static boolean disjoint(Collection<?> c1, Collection<?> c2)
From source file:org.apache.accumulo.core.util.LocalityGroupUtil.java
public static Map<String, Set<ByteSequence>> getLocalityGroups(AccumuloConfiguration acuconf) throws LocalityGroupConfigurationError { Map<String, Set<ByteSequence>> result = new HashMap<String, Set<ByteSequence>>(); String[] groups = acuconf.get(Property.TABLE_LOCALITY_GROUPS).split(","); for (String group : groups) { if (group.length() > 0) result.put(group, new HashSet<ByteSequence>()); }//from w w w.j a v a 2 s . co m HashSet<ByteSequence> all = new HashSet<ByteSequence>(); for (Entry<String, String> entry : acuconf) { String property = entry.getKey(); String value = entry.getValue(); String prefix = Property.TABLE_LOCALITY_GROUP_PREFIX.getKey(); if (property.startsWith(prefix)) { // this property configures a locality group, find out which one: String group = property.substring(prefix.length()); String[] parts = group.split("\\."); group = parts[0]; if (result.containsKey(group)) { if (parts.length == 1) { Set<ByteSequence> colFamsSet = decodeColumnFamilies(value); if (!Collections.disjoint(all, colFamsSet)) { colFamsSet.retainAll(all); throw new LocalityGroupConfigurationError("Column families " + colFamsSet + " in group " + group + " is already used by another locality group"); } all.addAll(colFamsSet); result.put(group, colFamsSet); } } } } // result.put("", all); return result; }
From source file:org.biopax.validator.rules.ComplexAssemblyHasComplexParticipantRule.java
private boolean isBound(Set<PhysicalEntity> participants) { for (PhysicalEntity pe : participants) { //if(pe instanceof Complex) continue; // it's impossible as far isBound called from where it is called if (pe.getFeature() != null && pe.getFeature() instanceof BindingFeature) { BindingFeature bf1 = (BindingFeature) pe.getFeature(); BindingFeature bf2 = bf1.getBindsTo(); if (bf2 != null) { Set<PhysicalEntity> bf2Of = bf2.getFeatureOf(); //if these phys. entities are (same side) participants as well if (!Collections.disjoint(participants, bf2Of)) return true; }/*from w w w . ja v a2 s . c o m*/ } } return false; }
From source file:org.craftercms.studio.impl.v1.service.content.ContentTypeServiceImpl.java
@Override public boolean isUserAllowed(Set<String> userRoles, ContentTypeConfigTO item) { if (item != null) { String name = item.getName(); Set<String> allowedRoles = item.getAllowedRoles(); logger.debug("Checking allowed roles on " + name + ". user roles: " + userRoles + ", allowed roles: " + allowedRoles);/* ww w.ja va 2 s.c o m*/ if (allowedRoles == null || allowedRoles.size() == 0) { return true; } else { boolean notAllowed = Collections.disjoint(userRoles, allowedRoles); if (notAllowed) { logger.debug(name + " is not allowed for the user."); return false; } else { return true; } } } else { logger.debug( "no content type config provided. returning true for user access to content type checking."); return true; } }
From source file:opensnap.security.SecurityChannelInterceptor.java
private boolean browseMap(Map<String, Object> map, String destinationRoot, String destination, List<String> userRoles) { for (String key : map.keySet()) { Object value = map.get(key); if (value instanceof String) { List<String> allowedRoles = Arrays.asList(((String) value).split(",")); if (key.endsWith("*")) { if (destination.startsWith(destinationRoot + key.substring(0, key.length() - 1))) { return !Collections.disjoint(userRoles, allowedRoles); }/*from www. j ava 2 s . com*/ } else if (destination.equals(destinationRoot + key)) { return !Collections.disjoint(userRoles, allowedRoles); } } else { Assert.isInstanceOf(Map.class, value); if (browseMap((Map) value, destinationRoot + key + "/", destination, userRoles)) { return true; } } } return false; }
From source file:com.floragunn.searchguard.dlic.rest.validation.AbstractConfigurationValidator.java
public boolean validateSettings() { // no payload for DELETE and GET requests if (method.equals(Method.DELETE) || method.equals(Method.GET)) { return true; }/*ww w. j a v a 2 s. c o m*/ // try to parse payload try { this.settingsBuilder = toSettingsBuilder(content); } catch (ElasticsearchException e) { this.errorType = ErrorType.BODY_NOT_PARSEABLE; return false; } Settings settings = settingsBuilder.build(); Set<String> requested = settings.names(); // check if payload is accepted at all if (!this.payloadAllowed && !requested.isEmpty()) { this.errorType = ErrorType.PAYLOAD_NOT_ALLOWED; return false; } // check if payload is mandatory if (this.payloadMandatory && requested.isEmpty()) { this.errorType = ErrorType.PAYLOAD_MANDATORY; return false; } // mandatory settings, one of ... if (Collections.disjoint(requested, mandatoryOrKeys)) { this.missingMandatoryOrKeys.addAll(mandatoryOrKeys); } // mandatory settings Set<String> mandatory = new HashSet<>(mandatoryKeys); mandatory.removeAll(requested); missingMandatoryKeys.addAll(mandatory); // invalid settings Set<String> allowed = new HashSet<>(allowedKeys.keySet()); requested.removeAll(allowed); this.invalidKeys.addAll(requested); boolean valid = missingMandatoryKeys.isEmpty() && invalidKeys.isEmpty() && missingMandatoryOrKeys.isEmpty(); if (!valid) { this.errorType = ErrorType.INVALID_CONFIGURATION; } // check types try { if (!checkDatatypes()) { this.errorType = ErrorType.WRONG_DATATYPE; return false; } } catch (Exception e) { this.errorType = ErrorType.BODY_NOT_PARSEABLE; return false; } return valid; }
From source file:org.codice.ddf.catalog.ui.security.AccessControlPolicyExtension.java
private KeyValueCollectionPermission isPermitted(CollectionPermission s, KeyValueCollectionPermission match, KeyValueCollectionPermission allPerms) { Map<String, Set<String>> subject = getPermissions(s.getPermissionList()); Map<String, Set<String>> metacard = getPermissions(allPerms.getPermissionList()); // There is nothing to imply if the incoming permission set doesn't contain _ALL_ ACL attributes if (Collections.disjoint(metacard.keySet(), ACCESS_CONTROL_IMPLIED)) { return match; // Simply imply nothing early on (essentially a no-op in this extension) }/*ww w. jav a2 s . c o m*/ // get all permissions implied by the subject, this function returns what permissions // to filter from the key-value permission collection Supplier<Set<String>> impliedPermissions = () -> { if (isSystem.test(subject) || isOwner.apply(subject, metacard)) { return metacard.keySet(); // all permissions are implied } else if (hasAccessAdministrators.apply(subject, metacard) || hasAccessIndividuals.apply(subject, metacard) || hasAccessGroups.apply(subject, metacard)) { return ACCESS_CONTROL_IMPLIED; // access control perms implied } else { return Collections.emptySet(); // nothing is implied } }; // filter out all implied permissions Function<Set<String>, KeyValueCollectionPermission> filterPermissions = (implied) -> { List<KeyValuePermission> values = match.getPermissionList().stream().map(p -> (KeyValuePermission) p) .filter((permission) -> !implied.contains((permission).getKey())).collect(Collectors.toList()); return new KeyValueCollectionPermission(match.getAction(), values); }; return filterPermissions.apply(impliedPermissions.get()); }
From source file:org.codice.ddf.catalog.ui.security.accesscontrol.AccessControlPolicyExtension.java
private KeyValueCollectionPermission isPermitted(CollectionPermission s, KeyValueCollectionPermission match, KeyValueCollectionPermission allPerms) { Map<String, Set<String>> subject = getPermissions(s.getPermissionList()); Map<String, Set<String>> metacard = getPermissions(allPerms.getPermissionList()); // There is nothing to imply if the incoming permission set doesn't contain _ALL_ ACL attributes if (Collections.disjoint(metacard.keySet(), ACCESS_CONTROL_IMPLIED)) { return match; // Simply imply nothing early on (essentially a no-op in this extension) }//from w ww . j ava2 s. c o m // To be able to have viewing access to the metacard, you must satisfy the following criteria SecurityPredicate subjectImpliesACL = (sub, mc) -> hasAccessAdministrators.apply(sub, mc) || hasAccessIndividuals.apply(sub, mc) || hasAccessGroups.apply(sub, mc) || (READ_ACTION.equals(allPerms.getAction()) && (hasAccessGroupsReadOnly.apply(sub, mc) || hasAccessIndividualsReadOnly.apply(sub, mc))); // get all permissions implied by the subject, this function returns what permissions // to filter from the key-value permission collection Supplier<Set<String>> impliedPermissions = () -> { if (isSystem.test(subject) || isOwner.apply(subject, metacard)) { return metacard.keySet(); // all permissions are implied } else if (subjectImpliesACL.apply(subject, metacard)) { return ACCESS_CONTROL_IMPLIED; // access control perms implied } else { return Collections.emptySet(); // nothing is implied } }; // filter out all implied permissions Function<Set<String>, KeyValueCollectionPermission> filterPermissions = (implied) -> { List<KeyValuePermission> values = match.getPermissionList().stream().map(p -> (KeyValuePermission) p) .filter((permission) -> !implied.contains((permission).getKey())).collect(Collectors.toList()); return new KeyValueCollectionPermission(match.getAction(), values); }; return filterPermissions.apply(impliedPermissions.get()); }
From source file:eu.trentorise.smartcampus.permissionprovider.manager.SecurityAdapter.java
/** * Method checks if a user (defined by its list of attributes) is authorized * to access the system./*from w ww . ja v a2s . c om*/ * * First it's checked the list of attributes passed as checkAttrs, then, if * this check fails, name and surname of the user * * @param authName * authority name to get list of attributes * @param checkAttrs * list of attributes to check * @param attrs * user attributes * @return true if user attribute is present in authority white-list, false * otherwise */ public boolean access(String authName, List<String> checkAttrs, Map<String, String> attrs) { List<SecurityEntry> securityList = securityMap.get(authName); if (securityList != null) { for (SecurityEntry se : securityList) { // check id attrs if (!se.getIdSecurityEntries().isEmpty()) { // security entry MUST contain only valid key attribute if (Collections.disjoint(checkAttrs, se.getIdSecurityEntries().keySet())) { continue; } boolean valid = true; for (String idAttr : checkAttrs) { try { if (se.getIdSecurityEntries().get(idAttr) != null && !attrs.get(idAttr).equals(se.getIdSecurityEntries().get(idAttr))) { valid = false; break; } } catch (NullPointerException e) { valid = false; break; } } if (!valid) continue; return true; } // check for name and surname try { if (!(attrs.get(Config.NAME_ATTR).equals(se.getNameValue()) && attrs.get(Config.SURNAME_ATTR).equals(se.getSurnameValue()))) { continue; } } catch (NullPointerException e) { continue; } return true; } } else { return true; } String attrValues = ""; for (String attrKey : checkAttrs) { attrValues += attrKey + " -> " + attrs.get(attrKey) + " "; } logger.error("Authentication failed. User: givenname -> " + attrs.get(Config.NAME_ATTR) + " surname -> " + attrs.get(Config.SURNAME_ATTR) + " " + attrValues); return false; }
From source file:com.orange.cepheus.broker.Subscriptions.java
/** * find subscriptionID matching the updateContext. * @param searchEntityId the entity id to search * @param searchAttributes the attributes to search * @return list of matching subscription *//*from w w w . ja v a 2 s . c o m*/ public Iterator<Subscription> findSubscriptions(EntityId searchEntityId, Set<String> searchAttributes) { // Filter out expired subscriptions Predicate<Subscription> filterExpired = subscription -> subscription.getExpirationDate() .isAfter(Instant.now()); // Filter only matching entity ids Predicate<EntityId> filterEntityId = patterns.getFilterEntityId(searchEntityId); // Only filter by attributes if search is looking for them final boolean noAttributes = searchAttributes == null || searchAttributes.size() == 0; // Filter each subscription (remove expired) and return its providing application // if at least one of its listed entities matches the searched context element // and if all searched attributes are defined in the subscription (if any) return subscriptions.values().stream().filter(filterExpired) .filter(subscription -> subscription.getSubscribeContext().getEntityIdList().stream() .filter(filterEntityId).findFirst().isPresent() && (noAttributes || !Collections .disjoint(subscription.getSubscribeContext().getAttributeList(), searchAttributes))) .iterator(); }
From source file:com.thoughtworks.go.domain.materials.Modifications.java
public boolean shouldBeIgnoredByFilterIn(MaterialConfig materialConfig) { if (materialConfig.filter().shouldNeverIgnore()) { return false; }// www. j av a2 s.c om Set<ModifiedFile> allFiles = getAllFiles(this); Set<ModifiedFile> ignoredFiles = new HashSet<>(); for (ModifiedFile file : allFiles) { appyIgnoreFilter(materialConfig, file, ignoredFiles); } LOG.debug("Checking ignore filters for {}", materialConfig); LOG.debug("Ignored files: {}", ignoredFiles); LOG.debug("Changed files: {}", CollectionUtils.subtract(allFiles, ignoredFiles)); if (materialConfig.isInvertFilter()) { // return true (ignore) if we are inverting the filter, and the ignoredFiles and allFiles are disjoint sets return Collections.disjoint(allFiles, ignoredFiles); } else { return ignoredFiles.containsAll(allFiles); } }