List of usage examples for java.util Set containsAll
boolean containsAll(Collection<?> c);
From source file:com.janrain.backplane2.server.provision.ProvisioningController2Test.java
/** return true if clientToCheck has grants for all busesToCheck */ private boolean checkGrantExists(MockHttpServletResponse grantListResponse, String clientToCheck, List<String> busesToCheck) throws Exception { Map<String, Map<String, String>> listResult = new ObjectMapper().readValue( grantListResponse.getContentAsString(), MapType.construct(Map.class, SimpleType.construct(String.class), MapType.construct(Map.class, SimpleType.construct(String.class), SimpleType.construct(String.class)))); Set<String> busesGranted = new HashSet<String>(); Map<String, String> grantsForClient = listResult.get(clientToCheck); if (grantsForClient != null) { for (String grantId : grantsForClient.keySet()) { Scope scope = new Scope(grantsForClient.get(grantId)); busesGranted.addAll(scope.getScopeFieldValues(BackplaneMessage.Field.BUS)); }//ww w. j av a2s .co m } return busesGranted.containsAll(busesToCheck); }
From source file:edu.rice.cs.bioinfo.programs.phylonet.algos.network.NetworkLikelihoodFromGTT.java
private Set<NetNode> findEdgeHavingNoBL(Network network, Set<String> singleAlleleSpecies) { Set<NetNode> node2ignore = new HashSet<>(); Map<NetNode, Set<String>> node2leaves = new HashMap<>(); for (Object nodeO : Networks.postTraversal(network)) { NetNode node = (NetNode) nodeO;//from ww w . ja v a 2 s. co m Set<String> leaves = new HashSet<>(); if (node.isLeaf()) { leaves.add(node.getName()); } else { for (Object childO : node.getChildren()) { NetNode childNode = (NetNode) childO; Set<String> childLeaves = node2leaves.get(childNode); leaves.addAll(childLeaves); } } if (leaves.size() <= 1 && singleAlleleSpecies.containsAll(leaves)) { node2ignore.add(node); } node2leaves.put(node, leaves); } return node2ignore; }
From source file:org.dataconservancy.dcs.archive.impl.elm.DcsEntityStreamTest.java
private void compareEntities(InputStream src, Map<String, Set<String>> entities) throws InvalidXmlException { Set<String> origEntities = new HashSet<String>(); for (Set<String> set : entities.values()) { origEntities.addAll(set);/*from w w w.j a v a2s . c o m*/ } List<String> foundEntities = new ArrayList<String>(); Dcp dcp = model.buildSip(src); for (DcsEntity c : dcp.getCollections()) { foundEntities.add(c.getId()); } for (DcsEntity d : dcp.getDeliverableUnits()) { foundEntities.add(d.getId()); } for (DcsEntity e : dcp.getEvents()) { foundEntities.add(e.getId()); } for (DcsEntity f : dcp.getFiles()) { foundEntities.add(f.getId()); } for (DcsEntity m : dcp.getManifestations()) { foundEntities.add(m.getId()); } assertEquals(origEntities.size(), foundEntities.size()); assertTrue(origEntities.containsAll(foundEntities)); }
From source file:redis.client.jedis.CustomShardedJedisFactory.java
/** * {@link ShardedJedis}Jedis?/* w w w.j a v a 2s .com*/ * <p> * <font color="red">'PING'???"Jedis"?</font> * <p> * {@inheritDoc} */ @Override public boolean validateObject(PooledObject<ShardedJedis> pooledShardedJedis) { final ShardedJedis shardedJedis = pooledShardedJedis.getObject(); // "Sharded.getAllShardInfo() returns 160*shards info list not returns the original shards list" // https://github.com/xetorthio/jedis/issues/837 Collection<JedisShardInfo> allClusterShardInfos = shardedJedis.getAllShardInfo(); // ?160??ShardedJedisTest.getAllShardInfo() // ??Shard? Set<JedisShardInfo> checkedShards = new HashSet<JedisShardInfo>(originalShardListSize); checkedShards.addAll(allClusterShardInfos); logger.debug("Active Shard list for current validated sharded Jedis: {}", checkedShards); // "?" if (serverStateCheckTimerTask.isActiveShardListUpdated()) { shards = new ArrayList<JedisShardInfo>(serverStateCheckTimerTask.getAllActiveJedisShards()); logger.debug("Active Shard list after updated: {}", shards); } if (checkedShards.size() != shards.size()) { // ? logger.debug("Find a pooled sharded Jedis is updated: {}", checkedShards); return false; } else { // ????(?????) if (!checkedShards.containsAll(shards)) { logger.debug("Find a pooled sharded Jedis is updated: {}", checkedShards); return false; } } return true; }
From source file:org.kuali.coeus.common.budget.impl.rate.BudgetRatesServiceImpl.java
protected boolean areBudgetRatesOutOfSyncWithInsttituteRates(List instituteRates, List budgetRates) { Set<String> instituteRateKeys = storeAllKeys((List<AbstractInstituteRate>) instituteRates); Set<String> budgetRateKeys = storeAllKeys((List<AbstractInstituteRate>) budgetRates); return !instituteRateKeys.containsAll(budgetRateKeys); }
From source file:org.rhq.enterprise.server.auth.SubjectManagerBean.java
public Subject updateSubject(Subject whoami, Subject subjectToModify, String newPassword) { // let a user change his own details Set<Permission> globalPermissions = authorizationManager.getExplicitGlobalPermissions(whoami); boolean isSecurityManager = globalPermissions.contains(Permission.MANAGE_SECURITY); if (!whoami.equals(subjectToModify) && !isSecurityManager) { throw new PermissionException("You [" + whoami.getName() + "] do not have permission to update user [" + subjectToModify.getName() + "]."); }/*from w ww . j a va 2 s . c o m*/ boolean subjectToModifyIsSystemSuperuser = authorizationManager.isSystemSuperuser(subjectToModify); if (!subjectToModify.getFactive() && subjectToModifyIsSystemSuperuser) { throw new PermissionException( "You cannot disable the system user [" + subjectToModify.getName() + "]."); } Subject attachedSubject = getSubjectById(subjectToModify.getId()); if (attachedSubject == null) { throw new IllegalArgumentException("No user exists with id [" + subjectToModify.getId() + "]."); } if (!attachedSubject.getName().equals(subjectToModify.getName())) { throw new IllegalArgumentException("You cannot change a user's username."); } Set<Role> newRoles = subjectToModify.getRoles(); if (newRoles != null) { Set<Role> currentRoles = new HashSet<Role>( roleManager.findRolesBySubject(subjectToModify.getId(), PageControl.getUnlimitedInstance())); boolean rolesChanged = !(newRoles.containsAll(currentRoles) && currentRoles.containsAll(newRoles)); if (rolesChanged) { int[] newRoleIds = new int[newRoles.size()]; int i = 0; for (Role role : newRoles) { newRoleIds[i++] = role.getId(); } roleManager.setAssignedSubjectRoles(whoami, subjectToModify.getId(), newRoleIds); } } boolean ldapRolesModified = false; Set<Role> newLdapRoles = subjectToModify.getLdapRoles(); if (newLdapRoles == null) { newLdapRoles = Collections.emptySet(); } if (newLdapRoles != null) { RoleCriteria subjectLdapRolesCriteria = new RoleCriteria(); subjectLdapRolesCriteria.addFilterLdapSubjectId(subjectToModify.getId()); PageList<Role> currentLdapRoles = roleManager.findRolesByCriteria(whoami, subjectLdapRolesCriteria); ldapRolesModified = !(currentLdapRoles.containsAll(newLdapRoles) && newLdapRoles.containsAll(currentLdapRoles)); } boolean isUserWithPrincipal = isUserWithPrincipal(subjectToModify.getName()); if (ldapRolesModified) { if (!isSecurityManager) { throw new PermissionException( "You cannot change the LDAP roles assigned to [" + subjectToModify.getName() + "] - only a user with the MANAGE_SECURITY permission can do so."); } else if (isUserWithPrincipal) { throw new PermissionException( "You cannot set LDAP roles on non-LDAP user [" + subjectToModify.getName() + "]."); } // TODO: Update LDAP roles. } if (newPassword != null) { if (!isUserWithPrincipal(subjectToModify.getName())) { throw new IllegalArgumentException("You cannot set a password for an LDAP user."); } changePasswordInternal(subjectToModify.getName(), newPassword); } return entityManager.merge(subjectToModify); }
From source file:org.xdi.oxauth.client.RegisterRequest.java
public static RegisterRequest fromJson(String p_json) throws JSONException { final JSONObject requestObject = new JSONObject(p_json); final List<String> redirectUris = new ArrayList<String>(); if (requestObject.has(REDIRECT_URIS.toString())) { JSONArray redirectUrisJsonArray = requestObject.getJSONArray(REDIRECT_URIS.toString()); for (int i = 0; i < redirectUrisJsonArray.length(); i++) { String redirectionUri = redirectUrisJsonArray.getString(i); redirectUris.add(redirectionUri); }//from ww w . j av a 2 s.co m } final Set<ResponseType> responseTypes = new HashSet<ResponseType>(); final Set<GrantType> grantTypes = new HashSet<GrantType>(); if (requestObject.has(RESPONSE_TYPES.toString())) { JSONArray responseTypesJsonArray = requestObject.getJSONArray(RESPONSE_TYPES.toString()); for (int i = 0; i < responseTypesJsonArray.length(); i++) { ResponseType rt = ResponseType.fromString(responseTypesJsonArray.getString(i)); if (rt != null) { responseTypes.add(rt); } } } else { // Default responseTypes.add(ResponseType.CODE); } if (responseTypes.contains(ResponseType.CODE)) { grantTypes.add(GrantType.AUTHORIZATION_CODE); } if (responseTypes.contains(ResponseType.ID_TOKEN) || responseTypes.containsAll(Arrays.asList(ResponseType.TOKEN, ResponseType.ID_TOKEN))) { grantTypes.add(GrantType.IMPLICIT); } if (responseTypes.containsAll(Arrays.asList(ResponseType.CODE, ResponseType.ID_TOKEN)) || responseTypes.containsAll(Arrays.asList(ResponseType.CODE, ResponseType.TOKEN)) || responseTypes .containsAll(Arrays.asList(ResponseType.CODE, ResponseType.TOKEN, ResponseType.ID_TOKEN))) { grantTypes.add(GrantType.AUTHORIZATION_CODE); grantTypes.add(GrantType.IMPLICIT); } if (requestObject.has(GRANT_TYPES.toString())) { JSONArray grantTypesJsonArray = requestObject.getJSONArray(GRANT_TYPES.toString()); for (int i = 0; i < grantTypesJsonArray.length(); i++) { GrantType gt = GrantType.fromString(grantTypesJsonArray.getString(i)); if (gt != null) { grantTypes.add(gt); switch (gt) { case AUTHORIZATION_CODE: responseTypes.add(ResponseType.CODE); break; case IMPLICIT: responseTypes.add(ResponseType.TOKEN); responseTypes.add(ResponseType.ID_TOKEN); break; case REFRESH_TOKEN: break; default: break; } } } } else { // Default grantTypes.add(GrantType.AUTHORIZATION_CODE); } final List<String> contacts = new ArrayList<String>(); if (requestObject.has(CONTACTS.toString())) { JSONArray contactsJsonArray = requestObject.getJSONArray(CONTACTS.toString()); for (int i = 0; i < contactsJsonArray.length(); i++) { contacts.add(contactsJsonArray.getString(i)); } } final List<String> defaultAcrValues = new ArrayList<String>(); if (requestObject.has(DEFAULT_ACR_VALUES.toString())) { JSONArray defaultAcrValuesJsonArray = requestObject.getJSONArray(DEFAULT_ACR_VALUES.toString()); for (int i = 0; i < defaultAcrValuesJsonArray.length(); i++) { defaultAcrValues.add(defaultAcrValuesJsonArray.getString(i)); } } final List<String> postLogoutRedirectUris = new ArrayList<String>(); if (requestObject.has(POST_LOGOUT_REDIRECT_URIS.toString())) { JSONArray postLogoutRedirectUrisJsonArray = requestObject .getJSONArray(POST_LOGOUT_REDIRECT_URIS.toString()); for (int i = 0; i < postLogoutRedirectUrisJsonArray.length(); i++) { postLogoutRedirectUris.add(postLogoutRedirectUrisJsonArray.getString(i)); } } final List<String> requestUris = new ArrayList<String>(); if (requestObject.has(REQUEST_URIS.toString())) { JSONArray requestUrisJsonArray = requestObject.getJSONArray(REQUEST_URIS.toString()); for (int i = 0; i < requestUrisJsonArray.length(); i++) { requestUris.add(requestUrisJsonArray.getString(i)); } } final List<String> scopes = new ArrayList<String>(); if (requestObject.has(SCOPES.toString())) { JSONArray scopesJsonArray = requestObject.getJSONArray(SCOPES.toString()); for (int i = 0; i < scopesJsonArray.length(); i++) { scopes.add(scopesJsonArray.getString(i)); } } final RegisterRequest result = new RegisterRequest(); result.setJsonObject(requestObject); result.setFederationUrl(requestObject.optString(FEDERATION_METADATA_URL.toString())); result.setFederationId(requestObject.optString(FEDERATION_METADATA_ID.toString())); result.setRequestUris(requestUris); result.setInitiateLoginUri(requestObject.optString(INITIATE_LOGIN_URI.toString())); result.setPostLogoutRedirectUris(postLogoutRedirectUris); result.setDefaultAcrValues(defaultAcrValues); result.setRequireAuthTime(requestObject.has(REQUIRE_AUTH_TIME.toString()) && requestObject.getBoolean(REQUIRE_AUTH_TIME.toString())); result.setLogoutUri(requestObject.optString(LOGOUT_URI.toString())); result.setLogoutSessionRequired(requestObject.optBoolean(LOGOUT_SESSION_REQUIRED.toString())); result.setDefaultMaxAge( requestObject.has(DEFAULT_MAX_AGE.toString()) ? requestObject.getInt(DEFAULT_MAX_AGE.toString()) : null); result.setIdTokenEncryptedResponseEnc( requestObject.has(ID_TOKEN_ENCRYPTED_RESPONSE_ENC.toString()) ? BlockEncryptionAlgorithm .fromName(requestObject.getString(ID_TOKEN_ENCRYPTED_RESPONSE_ENC.toString())) : null); result.setIdTokenEncryptedResponseAlg( requestObject.has(ID_TOKEN_ENCRYPTED_RESPONSE_ALG.toString()) ? KeyEncryptionAlgorithm .fromName(requestObject.getString(ID_TOKEN_ENCRYPTED_RESPONSE_ALG.toString())) : null); result.setIdTokenSignedResponseAlg(requestObject.has(ID_TOKEN_SIGNED_RESPONSE_ALG.toString()) ? SignatureAlgorithm.fromName(requestObject.getString(ID_TOKEN_SIGNED_RESPONSE_ALG.toString())) : null); result.setUserInfoEncryptedResponseEnc( requestObject.has(USERINFO_ENCRYPTED_RESPONSE_ENC.toString()) ? BlockEncryptionAlgorithm .fromName(requestObject.getString(USERINFO_ENCRYPTED_RESPONSE_ENC.toString())) : null); result.setUserInfoEncryptedResponseAlg( requestObject.has(USERINFO_ENCRYPTED_RESPONSE_ALG.toString()) ? KeyEncryptionAlgorithm .fromName(requestObject.getString(USERINFO_ENCRYPTED_RESPONSE_ALG.toString())) : null); result.setUserInfoSignedResponseAlg(requestObject.has(USERINFO_SIGNED_RESPONSE_ALG.toString()) ? SignatureAlgorithm.fromName(requestObject.getString(USERINFO_SIGNED_RESPONSE_ALG.toString())) : null); result.setRedirectUris(redirectUris); result.setScopes(scopes); result.setResponseTypes(new ArrayList<ResponseType>(responseTypes)); result.setGrantTypes(new ArrayList<GrantType>(grantTypes)); result.setApplicationType(requestObject.has(APPLICATION_TYPE.toString()) ? ApplicationType.fromString(requestObject.getString(APPLICATION_TYPE.toString())) : ApplicationType.WEB); result.setContacts(contacts); result.setClientName(requestObject.optString(CLIENT_NAME.toString())); result.setLogoUri(requestObject.optString(LOGO_URI.toString())); result.setClientUri(requestObject.optString(CLIENT_URI.toString())); result.setTokenEndpointAuthMethod(requestObject.has(TOKEN_ENDPOINT_AUTH_METHOD.toString()) ? AuthenticationMethod.fromString(requestObject.getString(TOKEN_ENDPOINT_AUTH_METHOD.toString())) : AuthenticationMethod.CLIENT_SECRET_BASIC); result.setPolicyUri(requestObject.optString(POLICY_URI.toString())); result.setTosUri(requestObject.optString(TOS_URI.toString())); result.setJwksUri(requestObject.optString(JWKS_URI.toString())); result.setJwks(requestObject.optString(JWKS.toString())); result.setSectorIdentifierUri(requestObject.optString(SECTOR_IDENTIFIER_URI.toString())); result.setSubjectType(requestObject.has(SUBJECT_TYPE.toString()) ? SubjectType.fromString(requestObject.getString(SUBJECT_TYPE.toString())) : null); result.setRequestObjectSigningAlg(requestObject.has(REQUEST_OBJECT_SIGNING_ALG.toString()) ? SignatureAlgorithm.fromName(requestObject.getString(REQUEST_OBJECT_SIGNING_ALG.toString())) : null); return result; }
From source file:org.localmatters.serializer.config.SerializationElementHandlerTest.java
/** * Tests the resolution of the extensions when some are invalid *///from w ww.j av a2 s . com public void testResolveInvalidExtensions() { Map<ComplexSerialization, String> extensions = new HashMap<ComplexSerialization, String>(); Map<String, ComplexSerialization> parents = new HashMap<String, ComplexSerialization>(); extensions.put(new ComplexSerialization(), "12345"); extensions.put(new ComplexSerialization(), "6789"); replay(element); Set<String> results = SerializationElementHandler.resolveExtensions(extensions, parents); verify(element); assertEquals(2, CollectionUtils.size(results)); assertTrue(results.containsAll(Arrays.asList("12345", "6789"))); }
From source file:com.ikon.module.jcr.JcrSearchModule.java
/** * Get keyword map/*w w w.j av a2 s . co m*/ */ private Map<String, Integer> getKeywordMapCached(String token, List<String> filter) throws RepositoryException, DatabaseException { log.debug("getKeywordMapCached({}, {})", token, filter); HashMap<String, Integer> keywordMap = new HashMap<String, Integer>(); Session session = null; try { // TODO This JCR Session could be removed if (token == null) { session = JCRUtils.getSession(); } else { session = JcrSessionManager.getInstance().get(token); } Collection<UserNodeKeywords> userDocKeywords = UserNodeKeywordsManager.get(session.getUserID()) .values(); for (Iterator<UserNodeKeywords> kwIt = userDocKeywords.iterator(); kwIt.hasNext();) { Set<String> docKeywords = kwIt.next().getKeywords(); if (filter != null && docKeywords.containsAll(filter)) { for (Iterator<String> itDocKeywords = docKeywords.iterator(); itDocKeywords.hasNext();) { String keyword = itDocKeywords.next(); if (!filter.contains(keyword)) { Integer occurs = keywordMap.get(keyword) != null ? keywordMap.get(keyword) : 0; keywordMap.put(keyword, occurs + 1); } } } } } catch (javax.jcr.RepositoryException e) { log.error(e.getMessage(), e); throw new RepositoryException(e.getMessage(), e); } finally { if (token == null) JCRUtils.logout(session); } log.debug("getKeywordMapCached: {}", keywordMap); return keywordMap; }
From source file:org.localmatters.serializer.config.SerializationElementHandlerTest.java
/** * Tests the resolution of the references when some are invalid *///w w w.j av a 2 s .c om public void testResolveInvalidReferences() { Map<ReferenceSerialization, String> references = new HashMap<ReferenceSerialization, String>(); Map<String, Serialization> serializations = new HashMap<String, Serialization>(); references.put(new ReferenceSerialization(), "12345"); references.put(new ReferenceSerialization(), "6789"); replay(element); Set<String> results = SerializationElementHandler.resolveReferences(references, serializations); verify(element); assertEquals(2, CollectionUtils.size(results)); assertTrue(results.containsAll(Arrays.asList("12345", "6789"))); }