List of usage examples for java.util Collection contains
boolean contains(Object o);
From source file:edu.umn.msi.tropix.persistence.aop.SecurityAspect.java
@Before(value = "execution(* edu.umn.msi.tropix.persistence.service.*+.*(..))") public void doAccessCheck(final JoinPoint joinPoint) { LOG.trace("Verifying persistence layer access to " + joinPoint.getSignature().toLongString()); final Method method = AopUtils.getMethod(joinPoint); if (method.getAnnotation(PersistenceMethod.class) == null) { return;//from ww w.j a v a 2 s .c o m } final Annotation[][] annotations = method.getParameterAnnotations(); String userId = null; for (int i = 0; i < annotations.length; i++) { final UserId userIdAnnotation = getAnnnotation(UserId.class, annotations[i]); if (userIdAnnotation != null) { final Object arg = joinPoint.getArgs()[i]; userId = (String) arg; break; } } Preconditions.checkNotNull(userId, "No parameter ananotations of type UserId found, but one is required."); @SuppressWarnings("unchecked") final Collection<Class<? extends Annotation>> securityAnnotations = Arrays.asList(Owns.class, Reads.class, Modifies.class, MemberOf.class); for (int i = 0; i < annotations.length; i++) { for (final Annotation annotation : annotations[i]) { if (securityAnnotations.contains(annotation.annotationType())) { verify(userId, joinPoint.getArgs()[i], annotations[i], joinPoint.getSignature() + "[" + i + "]"); } } } }
From source file:org.talend.license.LicenseRetriver.java
public void updateLicense() { File userHome = new File(System.getProperty("user.home")); File licenseRoot = new File(userHome, "licenses"); File history = new File(licenseRoot, ".history"); if (!licenseRoot.exists()) { licenseRoot.mkdirs();/*from w w w . j a v a 2 s .c o m*/ history.mkdirs(); } final Collection<File> files = new ArrayList<File>(); for (String version : versions) { Collection<File> fs = updateLicense(version, licenseRoot); if (null != fs) files.addAll(fs); } File[] his = licenseRoot.listFiles(new FileFilter() { public boolean accept(File f) { return f.isFile() && !files.contains(f); } }); if (null != his && his.length > 0) { for (File file : his) { file.renameTo(new File(history, file.getName())); } } }
From source file:net.solarnetwork.central.dras.biz.dao.test.ibatis.DaoEventBizTest.java
@Test public void assignMembers() { setupTestLocation();//ww w. j a v a 2 s . co m setupTestProgram(TEST_PROGRAM_ID, TEST_PROGRAM_NAME); setupTestParticipant(); setupTestParticipantGroup(); setupTestEvent(TEST_EVENT_ID, TEST_PROGRAM_ID); // add participant to program Set<Long> memberIds = new HashSet<Long>(1); memberIds.add(TEST_PARTICIPANT_ID); programDao.assignParticipantMembers(TEST_PROGRAM_ID, memberIds, TEST_EFFECTIVE_ID); MembershipCommand participants = new MembershipCommand(); participants.getGroup().addAll(memberIds); // add participant to participant group participantGroupDao.assignParticipantMembers(TEST_PARTICIPANT_GROUP_ID, memberIds, TEST_EFFECTIVE_ID); memberIds.clear(); memberIds.add(TEST_PARTICIPANT_GROUP_ID); MembershipCommand groups = new MembershipCommand(); groups.getGroup().addAll(memberIds); // assign participant and group EffectiveCollection<Event, Member> result = eventBiz.assignMembers(TEST_EVENT_ID, participants, groups); assertNotNull(result); assertNotNull(result.getEffective()); assertNotNull(result.getObject()); assertEquals(TEST_EVENT_ID, result.getObject().getId()); assertNotNull(result.getCollection()); assertEquals(2, result.getCollection().size()); // we have Participant and ParticipantGroup objects Map<String, Collection<Long>> mapping = result.getMemberMap(); assertEquals(2, mapping.size()); Collection<Long> foundParticipants = mapping.get(Participant.class.getSimpleName()); assertNotNull(foundParticipants); assertEquals(1, foundParticipants.size()); Collection<Long> foundParticipantGroups = mapping.get(ParticipantGroup.class.getSimpleName()); assertNotNull(foundParticipantGroups); assertEquals(1, foundParticipantGroups.size()); assertTrue(foundParticipants.contains(TEST_PARTICIPANT_ID)); assertTrue(foundParticipantGroups.contains(TEST_PARTICIPANT_GROUP_ID)); }
From source file:edu.uci.ics.jung.io.PajekNetIOTest.java
private void checkSets(Collection<Number> s1, Collection<Number> s2, List<Number> id1, List<Number> id2) { for (Number u : s1) { int j = id1.indexOf(u); assertTrue(s2.contains(id2.get(j))); }// ww w . j a va2 s. com }
From source file:de.hybris.platform.servicelayer.media.impl.DefaultMediaPermissionServiceIntegrationTest.java
/** * Test method for/*from w w w.j a v a2s . c o m*/ * {@link de.hybris.platform.servicelayer.media.impl.DefaultMediaPermissionService#denyReadPermission(de.hybris.platform.core.model.media.MediaModel, de.hybris.platform.core.model.security.PrincipalModel)} * . */ @Test public void testDenyPermission() { final PermissionAssignment testAssignment = new PermissionAssignment(PermissionsConstants.READ, userService.getCurrentUser(), true); final Collection<PermissionAssignment> permAssignments = permissionManagementService .getItemPermissionsForPrincipal(testMediaItem, userService.getCurrentUser()); Assert.assertFalse(permAssignments.contains(testAssignment)); mediaPermissionService.denyReadPermission(testMediaItem, userService.getCurrentUser()); final PermissionCheckResult checkResult = permissionCheckingService.checkItemPermission(testMediaItem, userService.getCurrentUser(), PermissionsConstants.READ); Assert.assertFalse(checkResult.isGranted()); }
From source file:org.mitre.oauth2.web.DeviceEndpoint.java
@RequestMapping(value = "/" + URL, method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public String requestDeviceCode(@RequestParam("client_id") String clientId, @RequestParam(name = "scope", required = false) String scope, Map<String, String> parameters, ModelMap model) {/*from w w w . jav a 2 s . co m*/ ClientDetailsEntity client; try { client = clientService.loadClientByClientId(clientId); // make sure this client can do the device flow Collection<String> authorizedGrantTypes = client.getAuthorizedGrantTypes(); if (authorizedGrantTypes != null && !authorizedGrantTypes.isEmpty() && !authorizedGrantTypes.contains(DeviceTokenGranter.GRANT_TYPE)) { throw new InvalidClientException("Unauthorized grant type: " + DeviceTokenGranter.GRANT_TYPE); } } catch (IllegalArgumentException e) { logger.error("IllegalArgumentException was thrown when attempting to load client", e); model.put(HttpCodeView.CODE, HttpStatus.BAD_REQUEST); return HttpCodeView.VIEWNAME; } if (client == null) { logger.error("could not find client " + clientId); model.put(HttpCodeView.CODE, HttpStatus.NOT_FOUND); return HttpCodeView.VIEWNAME; } // make sure the client is allowed to ask for those scopes Set<String> requestedScopes = OAuth2Utils.parseParameterList(scope); Set<String> allowedScopes = client.getScope(); if (!scopeService.scopesMatch(allowedScopes, requestedScopes)) { // client asked for scopes it can't have logger.error("Client asked for " + requestedScopes + " but is allowed " + allowedScopes); model.put(HttpCodeView.CODE, HttpStatus.BAD_REQUEST); model.put(JsonErrorView.ERROR, "invalid_scope"); return JsonErrorView.VIEWNAME; } // if we got here the request is legit try { DeviceCode dc = deviceCodeService.createNewDeviceCode(requestedScopes, client, parameters); Map<String, Object> response = new HashMap<>(); response.put("device_code", dc.getDeviceCode()); response.put("user_code", dc.getUserCode()); response.put("verification_uri", config.getIssuer() + USER_URL); if (client.getDeviceCodeValiditySeconds() != null) { response.put("expires_in", client.getDeviceCodeValiditySeconds()); } if (config.isAllowCompleteDeviceCodeUri()) { URI verificationUriComplete = new URIBuilder(config.getIssuer() + USER_URL) .addParameter("user_code", dc.getUserCode()).build(); response.put("verification_uri_complete", verificationUriComplete.toString()); } model.put(JsonEntityView.ENTITY, response); return JsonEntityView.VIEWNAME; } catch (DeviceCodeCreationException dcce) { model.put(HttpCodeView.CODE, HttpStatus.BAD_REQUEST); model.put(JsonErrorView.ERROR, dcce.getError()); model.put(JsonErrorView.ERROR_MESSAGE, dcce.getMessage()); return JsonErrorView.VIEWNAME; } catch (URISyntaxException use) { logger.error("unable to build verification_uri_complete due to wrong syntax of uri components"); model.put(HttpCodeView.CODE, HttpStatus.INTERNAL_SERVER_ERROR); return HttpCodeView.VIEWNAME; } }
From source file:ee.ria.xroad.proxy.clientproxy.ClientMessageProcessor.java
private static URI[] getServiceAddresses(ServiceId serviceProvider, SecurityServerId serverId) throws Exception { log.trace("getServiceAddresses({}, {})", serviceProvider, serverId); Collection<String> hostNames = GlobalConf.getProviderAddress(serviceProvider.getClientId()); if (hostNames == null || hostNames.isEmpty()) { throw new CodedException(X_UNKNOWN_MEMBER, "Could not find addresses for service provider \"%s\"", serviceProvider);/*from w w w. j a v a2s. co m*/ } if (serverId != null) { final String securityServerAddress = GlobalConf.getSecurityServerAddress(serverId); if (securityServerAddress == null) { throw new CodedException(X_INVALID_SECURITY_SERVER, "Could not find security server \"%s\"", serverId); } if (!hostNames.contains(securityServerAddress)) { throw new CodedException(X_INVALID_SECURITY_SERVER, "Invalid security server \"%s\"", serviceProvider); } hostNames = Collections.singleton(securityServerAddress); } String protocol = isSslEnabled() ? "https" : "http"; int port = getServerProxyPort(); List<URI> addresses = new ArrayList<>(hostNames.size()); for (String host : hostNames) { addresses.add(new URI(protocol, null, host, port, "/", null, null)); } return addresses.toArray(new URI[addresses.size()]); }
From source file:com.liferay.blade.cli.command.CreateCommand.java
private boolean _isExistingTemplate(String templateName) throws Exception { Collection<String> templateNames = BladeUtil.getTemplateNames(getBladeCLI()); return templateNames.contains(templateName); }
From source file:com.jaspersoft.jasperserver.export.modules.scheduling.ReportJobsImporter.java
protected boolean isUpdateResource(String resourceUri) { Collection updateResources = (Collection) getContextAttributes() .getAttribute(ResourceImporter.ATTRIBUTE_UPDATE_RESOURCES); return updateResources != null && updateResources.contains(resourceUri); }
From source file:com.oltpbenchmark.util.TestCollectionUtil.java
/** * testPop//from w w w. j a v a 2 s .co m */ @SuppressWarnings("unchecked") public void testPop() { String expected[] = new String[11]; RandomGenerator rng = new RandomGenerator(0); for (int i = 0; i < expected.length; i++) { expected[i] = rng.astring(1, 32); } // FOR Collection<String> collections[] = new Collection[] { CollectionUtil.addAll(new ListOrderedSet<String>(), expected), CollectionUtil.addAll(new HashSet<String>(), expected), CollectionUtil.addAll(new ArrayList<String>(), expected), }; for (Collection<String> c : collections) { assertNotNull(c); assertEquals(c.getClass().getSimpleName(), expected.length, c.size()); String pop = CollectionUtil.pop(c); assertNotNull(c.getClass().getSimpleName(), pop); assertEquals(c.getClass().getSimpleName(), expected.length - 1, c.size()); assertFalse(c.getClass().getSimpleName(), c.contains(pop)); if (c instanceof List || c instanceof ListOrderedSet) { assertEquals(c.getClass().getSimpleName(), expected[0], pop); } } // FOR }