List of usage examples for java.util ArrayList containsAll
boolean containsAll(Collection<?> c);
From source file:ro.nextreports.designer.querybuilder.RuntimeParametersPanel.java
@SuppressWarnings("unchecked") private void initParameterValue(JComponent component, Object value, String paramName, List<Serializable> defaultValues) { if (value == null) { return;//from w w w .j a va 2s .co m } if (component instanceof JTextField) { ((JTextField) component).setText(value.toString()); } else if (component instanceof JComboBox) { JComboBox combo = ((JComboBox) component); List<IdName> values = (List<IdName>) value; combo.removeAllItems(); combo.addItem("-- " + I18NSupport.getString("parameter.value.select") + " --"); for (int j = 0, len = values.size(); j < len; j++) { combo.addItem(values.get(j)); } Object old = parametersValues.get(paramName); if (old != null) { combo.setSelectedItem(old); } else if ((defaultValues != null) && (defaultValues.size() > 0)) { Serializable id = defaultValues.get(0); if (id instanceof IdName) { id = ((IdName) id).getId(); } combo.setSelectedItem(findIdName(combo.getModel(), id)); } } else if (component instanceof ListSelectionPanel) { ListSelectionPanel lsp = (ListSelectionPanel) component; DefaultListModel model = new DefaultListModel(); if (value != null) { List<IdName> values = (List<IdName>) value; for (int j = 0, len = values.size(); j < len; j++) { model.addElement(values.get(j)); } } ArrayList srcList = new ArrayList(Arrays.asList(model.toArray())); Object old = parametersValues.get(paramName); Object[] selected = new Object[0]; if (old != null) { selected = (Object[]) old; } else if ((defaultValues != null) && (defaultValues.size() > 0)) { selected = new Object[defaultValues.size()]; for (int k = 0, len = selected.length; k < len; k++) { Serializable id = defaultValues.get(k); if (id instanceof IdName) { id = ((IdName) id).getId(); } IdName in = findIdName(srcList, id); selected[k] = in; } } List dstList = Arrays.asList(selected); if (!srcList.containsAll(dstList)) { dstList = new ArrayList(); parametersValues.put(paramName, null); } else { srcList.removeAll(dstList); } if ((dstList.size() == 1) && ParameterUtil.NULL.equals(dstList.get(0))) { dstList = new ArrayList(); } lsp.setLists(srcList, dstList); } else if (component instanceof ListAddPanel) { ListAddPanel lap = (ListAddPanel) component; DefaultListModel model = new DefaultListModel(); if (value != null) { List<Object> values = (List<Object>) value; for (int j = 0, len = values.size(); j < len; j++) { model.addElement(values.get(j)); } } ArrayList srcList = new ArrayList(Arrays.asList(model.toArray())); Object old = parametersValues.get(paramName); Object[] selected = new Object[0]; if (old != null) { selected = (Object[]) old; } else if ((defaultValues != null) && (defaultValues.size() > 0)) { selected = new Object[defaultValues.size()]; for (int k = 0, len = selected.length; k < len; k++) { Serializable id = defaultValues.get(k); if (id instanceof IdName) { id = ((IdName) id).getId(); } selected[k] = id; } } List dstList = Arrays.asList(selected); if (!srcList.containsAll(dstList)) { dstList = new ArrayList(); parametersValues.put(paramName, null); } else { srcList.removeAll(dstList); } if ((dstList.size() == 1) && ParameterUtil.NULL.equals(dstList.get(0))) { dstList = new ArrayList(); } lap.setElements(dstList); } else if (component instanceof JDateTimePicker) { ((JDateTimePicker) component).setDate((Date) value); } else if (component instanceof JXDatePicker) { ((JXDatePicker) component).setDate((Date) value); } else if (component instanceof JCheckBox) { ((JCheckBox) component).setSelected((Boolean) value); } }
From source file:eu.freme.eservices.epublishing.webservice.EPubTest.java
@Ignore @Test//from www. j ava 2s . co m public void TestSections() throws IOException { String title = "Alice in Utopia"; String author = "Joske Vermeulen"; File zippedHTMLFile = new File("src/test/resources/alice.zip"); System.out.println("Converting " + zippedHTMLFile + " to EPUB format."); Metadata metadata = new Metadata(); ArrayList<String> titles = new ArrayList<>(); ArrayList<String> authors = new ArrayList<>(); ArrayList<Section> toc = new ArrayList<>(); titles.add(title); authors.add(author); metadata.setTitles(titles); //metadata.setAuthors(authors); toc.add(new Section("Chapter 1", "01.xhtml")); toc.add(new Section("Chapter 2", "02.xhtml")); metadata.setTableOfContents(toc); Gson gson = new Gson(); // create body part containing the ePub file FileDataBodyPart ePubFilePart = new FileDataBodyPart("htmlZip", zippedHTMLFile); // the form, to which parameters and binary content can be added FormDataMultiPart multiPart = new FormDataMultiPart(); multiPart.bodyPart(ePubFilePart); // add ePub multiPart.field("metadata", gson.toJson(metadata)); // now send it to the service Response response = target.path("e-publishing/html").request("application/epub+zip") .post(Entity.entity(multiPart, multiPart.getMediaType())); InputStream in = response.readEntity(InputStream.class); // write it to a (temporary) file File ePubFile = File.createTempFile("alice", ".epub"); System.out.println("Writing result to " + ePubFile); IOUtils.copy(in, new FileOutputStream(ePubFile)); //read file and perform checks EpubReader r = new EpubReader(); Book b = r.readEpub(new FileInputStream(ePubFile)); List<String> bookTitles = b.getMetadata().getTitles(); List<CreatorContributor> bookAuthors = b.getMetadata().getAuthors(); List<String> bookAuthorsNames = new ArrayList<>(); for (CreatorContributor a : bookAuthors) { bookAuthorsNames.add(a.getFirstname() + " " + a.getLastname()); } Assert.assertTrue("All titles are in the EPUB.", bookTitles.containsAll(titles)); Assert.assertTrue("All EPUB titles are in the given titles.", titles.containsAll(bookTitles)); System.out.println(bookAuthorsNames); Assert.assertTrue("All authors are in the EPUB.", bookAuthorsNames.containsAll(authors)); Assert.assertTrue("All EPUB authors are in the given authors.", authors.containsAll(bookAuthorsNames)); }
From source file:eu.freme.eservices.epublishing.webservice.EPubTest.java
@Ignore @Test/*from w w w . j av a 2s . com*/ public void TestAlice() throws IOException { String title = "Alice in Utopia"; String author = "Joske Vermeulen"; String author2 = "Marieke Vermalen"; String description = "Dit is een heel mooi boekske."; File zippedHTMLFile = new File("src/test/resources/alice.zip"); System.out.println("Converting " + zippedHTMLFile + " to EPUB format."); Metadata metadata = new Metadata(); ArrayList<String> titles = new ArrayList<>(); ArrayList<String> authors = new ArrayList<>(); ArrayList<String> descriptions = new ArrayList<>(); titles.add(title); authors.add(author); authors.add(author2); metadata.setTitles(titles); //metadata.setAuthors(authors); descriptions.add(description); metadata.setDescriptions(descriptions); Identifier id = new Identifier(null, "urn:ean:1234-7956-1356-1123"); metadata.setIdentifier(id); Gson gson = new Gson(); // create body part containing the ePub file FileDataBodyPart ePubFilePart = new FileDataBodyPart("htmlZip", zippedHTMLFile); // the form, to which parameters and binary content can be added FormDataMultiPart multiPart = new FormDataMultiPart(); multiPart.bodyPart(ePubFilePart); // add ePub multiPart.field("metadata", gson.toJson(metadata)); System.out.println(gson.toJson(metadata)); // now send it to the service Response response = target.path("e-publishing/html").request("application/epub+zip") .post(Entity.entity(multiPart, multiPart.getMediaType())); InputStream in = response.readEntity(InputStream.class); // write it to a (temporary) file File ePubFile = File.createTempFile("alice", ".epub"); System.out.println("Writing result to " + ePubFile); IOUtils.copy(in, new FileOutputStream(ePubFile)); //read file and perform checks EpubReader r = new EpubReader(); Book b = r.readEpub(new FileInputStream(ePubFile)); List<String> bookTitles = b.getMetadata().getTitles(); List<CreatorContributor> bookAuthors = b.getMetadata().getAuthors(); List<String> bookAuthorsNames = new ArrayList<>(); for (CreatorContributor a : bookAuthors) { bookAuthorsNames.add(a.getFirstname() + " " + a.getLastname()); } Assert.assertTrue(bookTitles.containsAll(titles)); Assert.assertTrue(titles.containsAll(bookTitles)); System.out.println(bookAuthorsNames); Assert.assertTrue(bookAuthorsNames.containsAll(authors)); Assert.assertTrue(authors.containsAll(bookAuthorsNames)); }
From source file:org.pentaho.test.platform.security.userroledao.jackrabbit.UserRoleDaoEncodeIT.java
@Test public void testRoleWithMembers() throws Exception { loginAsRepositoryAdmin();/*ww w. ja v a 2s. c o m*/ systemTenant = tenantManager.createTenant(null, ServerRepositoryPaths.getPentahoRootFolderName(), adminRoleName, authenticatedRoleName, "Anonymous"); userRoleDaoProxy.createUser(systemTenant, sysAdminUserName, "password", "", new String[] { adminRoleName }); login(sysAdminUserName, systemTenant, new String[] { adminRoleName, authenticatedRoleName }); mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, adminRoleName, authenticatedRoleName, "Anonymous"); userRoleDaoProxy.createUser(mainTenant_1, "admin", "password", "", new String[] { adminRoleName }); mainTenant_2 = tenantManager.createTenant(systemTenant, MAIN_TENANT_2, adminRoleName, authenticatedRoleName, "Anonymous"); userRoleDaoProxy.createUser(mainTenant_2, "admin", "password", "", new String[] { adminRoleName }); login("admin", mainTenant_1, new String[] { adminRoleName, authenticatedRoleName }); userRoleDaoProxy.createRole(mainTenant_1, ROLE_1, ROLE_DESCRIPTION_1, null); userRoleDaoProxy.createRole(mainTenant_1, ROLE_2, ROLE_DESCRIPTION_2, null); userRoleDaoProxy.createRole(mainTenant_1, ROLE_3, ROLE_DESCRIPTION_3, null); userRoleDaoProxy.createUser(mainTenant_1, USER_2, PASSWORD_2, USER_DESCRIPTION_2, new String[] { ROLE_1 }); userRoleDaoProxy.createUser(mainTenant_1, USER_3, PASSWORD_3, USER_DESCRIPTION_3, new String[] { ROLE_1, ROLE_2 }); List<IPentahoUser> users = userRoleDaoProxy.getRoleMembers(mainTenant_1, ROLE_2); assertEquals(1, users.size()); assertEquals(USER_3, users.get(0).getUsername()); ArrayList<String> expectedUserNames = new ArrayList<String>(); expectedUserNames.add(USER_2); expectedUserNames.add(USER_3); ArrayList<String> actualUserNames = new ArrayList<String>(); String role_delim = ((DefaultTenantedPrincipleNameResolver) tenantedRoleNameUtils).getDelimeter(); users = userRoleDaoProxy.getRoleMembers(null, ROLE_1 + role_delim + mainTenant_1.getRootFolderAbsolutePath()); for (IPentahoUser user : users) { actualUserNames.add(user.getUsername()); } assertEquals(2, actualUserNames.size()); assertTrue(actualUserNames.containsAll(expectedUserNames)); users = userRoleDaoProxy.getRoleMembers(mainTenant_1, ROLE_3); assertEquals(0, users.size()); userRoleDaoProxy.createUser(mainTenant_1, USER_5, PASSWORD_5, USER_DESCRIPTION_5, null); userRoleDaoProxy.createUser(mainTenant_1, USER_6, PASSWORD_6, USER_DESCRIPTION_6, null); userRoleDaoProxy.createUser(mainTenant_1, USER_7, PASSWORD_7, USER_DESCRIPTION_7, null); userRoleDaoProxy.createRole(mainTenant_1, ROLE_5, ROLE_DESCRIPTION_6, new String[] { USER_5 }); userRoleDaoProxy.createRole(mainTenant_1, ROLE_6, ROLE_DESCRIPTION_7, new String[] { USER_5, USER_6 }); ArrayList<String> expectedRoleNames = new ArrayList<String>(); expectedRoleNames.add(ROLE_6); expectedRoleNames.add(authenticatedRoleName); ArrayList<String> actualRoleNames = new ArrayList<String>(); List<IPentahoRole> roles = userRoleDaoProxy.getUserRoles(mainTenant_1, USER_6); for (IPentahoRole role : roles) { actualRoleNames.add(role.getName()); } assertEquals(2, roles.size()); assertTrue(actualRoleNames.containsAll(expectedRoleNames)); expectedRoleNames = new ArrayList<String>(); expectedRoleNames.add(ROLE_5); expectedRoleNames.add(ROLE_6); expectedRoleNames.add(authenticatedRoleName); actualRoleNames = new ArrayList<String>(); roles = userRoleDaoProxy.getUserRoles(null, USER_5 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath()); for (IPentahoRole role : roles) { actualRoleNames.add(role.getName()); } assertEquals(3, actualRoleNames.size()); assertTrue(actualRoleNames.containsAll(expectedRoleNames)); roles = userRoleDaoProxy.getUserRoles(mainTenant_1, USER_7); assertEquals(1, roles.size()); assertEquals(authenticatedRoleName, roles.get(0).getName()); userRoleDaoProxy.setUserRoles(null, USER_7 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath(), new String[] { ROLE_5, ROLE_6 }); roles = userRoleDaoProxy.getUserRoles(null, USER_7 + DefaultTenantedPrincipleNameResolver.DEFAULT_DELIMETER + mainTenant_1.getRootFolderAbsolutePath()); actualRoleNames.clear(); for (IPentahoRole role : roles) { actualRoleNames.add(role.getName()); } assertEquals(3, actualRoleNames.size()); assertTrue(actualRoleNames.containsAll(expectedRoleNames)); expectedUserNames = new ArrayList<String>(); expectedUserNames.add(USER_1); expectedUserNames.add(USER_2); expectedRoleNames.add(authenticatedRoleName); userRoleDaoProxy.setRoleMembers(null, ROLE_3 + role_delim + mainTenant_1.getRootFolderAbsolutePath(), new String[] { USER_1, USER_2 }); users = userRoleDaoProxy.getRoleMembers(null, ROLE_3 + role_delim + mainTenant_1.getRootFolderAbsolutePath()); actualUserNames.clear(); for (IPentahoUser user : users) { actualUserNames.add(user.getUsername()); } assertEquals(2, actualUserNames.size()); assertTrue(actualUserNames.containsAll(expectedUserNames)); }
From source file:org.cloudfoundry.identity.uaa.oauth.UaaTokenServices.java
@Override public OAuth2AccessToken refreshAccessToken(String refreshTokenValue, TokenRequest request) throws AuthenticationException { if (null == refreshTokenValue) { throw new InvalidTokenException("Invalid refresh token (empty token)"); }//from ww w.ja v a2 s .c o m if (!"refresh_token".equals(request.getRequestParameters().get("grant_type"))) { throw new InvalidGrantException( "Invalid grant type: " + request.getRequestParameters().get("grant_type")); } TokenValidation tokenValidation = validateToken(refreshTokenValue); Map<String, Object> claims = tokenValidation.getClaims(); refreshTokenValue = tokenValidation.getJwt().getEncoded(); @SuppressWarnings("unchecked") ArrayList<String> tokenScopes = (ArrayList<String>) claims.get(SCOPE); if (isRestrictRefreshGrant() && !tokenScopes.contains(UAA_REFRESH_TOKEN)) { throw new InsufficientScopeException(String.format("Expected scope %s is missing", UAA_REFRESH_TOKEN)); } // TODO: Should reuse the access token you get after the first // successful authentication. // You will get an invalid_grant error if your previous token has not // expired yet. // OAuth2RefreshToken refreshToken = // tokenStore.readRefreshToken(refreshTokenValue); // if (refreshToken == null) { // throw new InvalidGrantException("Invalid refresh token: " + // refreshTokenValue); // } String clientId = (String) claims.get(CID); if (clientId == null || !clientId.equals(request.getClientId())) { throw new InvalidGrantException("Wrong client for this refresh token: " + refreshTokenValue); } String userid = (String) claims.get(USER_ID); String refreshTokenId = (String) claims.get(JTI); String accessTokenId = generateUniqueTokenId(); boolean opaque = TokenConstants.OPAQUE .equals(request.getRequestParameters().get(TokenConstants.REQUEST_TOKEN_FORMAT)); boolean revocable = opaque || (claims.get(REVOCABLE) == null ? false : (Boolean) claims.get(REVOCABLE)); // TODO: Need to add a lookup by id so that the refresh token does not // need to contain a name UaaUser user = userDatabase.retrieveUserById(userid); ClientDetails client = clientDetailsService.loadClientByClientId(clientId); Integer refreshTokenIssuedAt = (Integer) claims.get(IAT); long refreshTokenIssueDate = refreshTokenIssuedAt.longValue() * 1000l; Integer refreshTokenExpiry = (Integer) claims.get(EXP); long refreshTokenExpireDate = refreshTokenExpiry.longValue() * 1000l; if (new Date(refreshTokenExpireDate).before(new Date())) { throw new InvalidTokenException("Invalid refresh token (expired): " + refreshTokenValue + " expired at " + new Date(refreshTokenExpireDate)); } // default request scopes to what is in the refresh token Set<String> requestedScopes = request.getScope(); if (requestedScopes.isEmpty()) { requestedScopes = new HashSet<>(tokenScopes); } // The user may not request scopes that were not part of the refresh // token if (tokenScopes.isEmpty() || !tokenScopes.containsAll(requestedScopes)) { throw new InvalidScopeException( "Unable to narrow the scope of the client authentication to " + requestedScopes + ".", new HashSet<>(tokenScopes)); } // from this point on, we only care about the scopes requested, not what // is in the refresh token // ensure all requested scopes are approved: either automatically or // explicitly by the user String grantType = claims.get(GRANT_TYPE).toString(); checkForApproval(userid, clientId, requestedScopes, getAutoApprovedScopes(grantType, tokenScopes, client)); // if we have reached so far, issue an access token Integer validity = client.getAccessTokenValiditySeconds(); String nonce = (String) claims.get(NONCE); @SuppressWarnings("unchecked") Map<String, String> additionalAuthorizationInfo = (Map<String, String>) claims.get(ADDITIONAL_AZ_ATTR); @SuppressWarnings("unchecked") Map<String, String> externalAttributes = (Map<String, String>) claims.get(EXTERNAL_ATTR); String revocableHashSignature = (String) claims.get(REVOCATION_SIGNATURE); if (hasText(revocableHashSignature)) { String clientSecretForHash = client.getClientSecret(); if (clientSecretForHash != null && clientSecretForHash.split(" ").length > 1) { clientSecretForHash = clientSecretForHash.split(" ")[1]; } String newRevocableHashSignature = UaaTokenUtils.getRevocableTokenSignature(client, clientSecretForHash, user); if (!revocableHashSignature.equals(newRevocableHashSignature)) { throw new TokenRevokedException(refreshTokenValue); } } Set<String> audience = new HashSet<>((ArrayList<String>) claims.get(AUD)); int zoneAccessTokenValidity = getZoneAccessTokenValidity(); CompositeAccessToken accessToken = createAccessToken(accessTokenId, user.getId(), user, (claims.get(AUTH_TIME) != null) ? new Date(((Long) claims.get(AUTH_TIME)) * 1000l) : null, validity != null ? validity.intValue() : zoneAccessTokenValidity, null, requestedScopes, clientId, audience /*request.createOAuth2Request(client).getResourceIds()*/, grantType, refreshTokenValue, nonce, additionalAuthorizationInfo, externalAttributes, new HashSet<>(), revocableHashSignature, false, null, //TODO populate response types null, revocable, null, null); DefaultExpiringOAuth2RefreshToken expiringRefreshToken = new DefaultExpiringOAuth2RefreshToken( refreshTokenValue, new Date(refreshTokenExpireDate)); return persistRevocableToken(accessTokenId, refreshTokenId, accessToken, expiringRefreshToken, clientId, user.getId(), opaque, revocable); }