List of usage examples for java.util Set toString
public String toString()
From source file:org.everit.jira.hr.admin.SchemeUsersComponent.java
private void processEdit(final HttpServletRequest req, final HttpServletResponse resp) { long recordId = Long.parseLong(req.getParameter("record-id")); long schemeId = Long.parseLong(req.getParameter("schemeId")); String userName = req.getParameter("user"); Date startDate = Date.valueOf(req.getParameter("start-date")); Date endDate = Date.valueOf(req.getParameter("end-date")); Date endDateExcluded = DateUtil.addDays(endDate, 1); Long userId = getUserId(userName); if (userId == null) { renderAlert("User does not exist", "error", resp); resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return;// w ww .j ava 2s. c om } if (startDate.compareTo(endDate) > 0) { renderAlert("Start date must not be after end date", "error", resp); resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } Set<String> schemeNamesWithOverlappingTimeRange = getSchemeNamesWithOverlappingTimeRange(userId, startDate, endDateExcluded, recordId); if (!schemeNamesWithOverlappingTimeRange.isEmpty()) { renderAlert( "The user is assigned overlapping with the specified date range to the" + " following scheme(s): " + schemeNamesWithOverlappingTimeRange.toString(), "error", resp); resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } update(recordId, schemeId, userId, startDate, endDateExcluded); try (PartialResponseBuilder prb = new PartialResponseBuilder(resp)) { renderAlertOnPrb("Updating user successful", "info", prb, resp.getLocale()); prb.replace("#scheme-user-table", render(req, resp.getLocale(), "scheme-user-table")); } }
From source file:org.wso2.carbon.la.database.internal.LADatabaseService.java
@Override public void insertLogStreamMetadata(String logStream, Set<String> fields, int tenantId, String username) throws DatabaseHandlerException { Connection connection = null; PreparedStatement updateLogStreamFields = null; try {//from w ww . j a v a 2 s . com connection = dbh.getDataSource().getConnection(); connection.setAutoCommit(false); updateLogStreamFields = connection.prepareStatement(SQLQueries.INSERT_LOG_STREAM_FIELDS); updateLogStreamFields.setString(1, fields.toString()); updateLogStreamFields.setString(2, logStream); updateLogStreamFields.setInt(3, tenantId); updateLogStreamFields.setString(4, username); updateLogStreamFields.execute(); connection.commit(); if (logger.isDebugEnabled()) { logger.debug("Successfully inserted the log stream"); } } catch (SQLException e) { LADatabaseUtils.rollBack(connection); throw new DatabaseHandlerException( "Error occurred while inserting the field list of log stream: " + e.getMessage(), e); } finally { // enable auto commit LADatabaseUtils.enableAutoCommit(connection); // close the database resources LADatabaseUtils.closeDatabaseResources(connection, updateLogStreamFields); } }
From source file:org.wso2.carbon.la.database.internal.LADatabaseService.java
@Override public void updateLogStreamMetadata(String logStreamId, Set<String> fields, int tenantId, String username) throws DatabaseHandlerException { Connection connection = null; PreparedStatement updateLogStreamFields = null; try {/* w w w. jav a 2 s . c om*/ connection = dbh.getDataSource().getConnection(); connection.setAutoCommit(false); updateLogStreamFields = connection.prepareStatement(SQLQueries.UPDATE_LOG_STREAM_FIELDS); updateLogStreamFields.setString(1, fields.toString()); updateLogStreamFields.setString(2, logStreamId); updateLogStreamFields.setInt(3, tenantId); updateLogStreamFields.setString(4, username); updateLogStreamFields.execute(); connection.commit(); if (logger.isDebugEnabled()) { logger.debug("Successfully updated the log stream"); } } catch (SQLException e) { LADatabaseUtils.rollBack(connection); throw new DatabaseHandlerException( "Error occurred while updating the field list of log stream: " + e.getMessage(), e); } finally { // enable auto commit LADatabaseUtils.enableAutoCommit(connection); // close the database resources LADatabaseUtils.closeDatabaseResources(connection, updateLogStreamFields); } }
From source file:org.sipfoundry.sipxconfig.cfgmgt.RegisteredLocationResolver.java
Set<String> loadRegisteredIps() { final Set<String> ips = new HashSet<String>(); if (!m_csvFile.exists()) { LOG.error("Cannot determine registered systems, missing file " + m_csvFile.getAbsolutePath()); return ips; }/*from w ww. ja v a2 s .c om*/ FileReader r = null; try { r = new FileReader(m_csvFile); CsvParserImpl parser = new CsvParserImpl(); parser.setSkipHeaderLine(false); Closure addRow = new Closure() { @Override public void execute(Object arg0) { String[] data = ((String[]) arg0); String ip = data[3].trim(); ips.add(ip); } }; parser.parse(r, addRow); LOG.info("Loaded registered systems " + ips.toString()); } catch (FileNotFoundException e) { LOG.error("Could not read lastseen CSV file", e); } finally { IOUtils.closeQuietly(r); } return ips; }
From source file:org.acegisecurity.securechannel.ChannelProcessingFilter.java
public void afterPropertiesSet() throws Exception { Assert.notNull(filterInvocationDefinitionSource, "filterInvocationDefinitionSource must be specified"); Assert.notNull(channelDecisionManager, "channelDecisionManager must be specified"); Iterator iter = this.filterInvocationDefinitionSource.getConfigAttributeDefinitions(); if (iter == null) { if (logger.isWarnEnabled()) { logger.warn(//from w w w .j a v a2 s . co m "Could not validate configuration attributes as the FilterInvocationDefinitionSource did " + "not return a ConfigAttributeDefinition Iterator"); } return; } Set set = new HashSet(); while (iter.hasNext()) { ConfigAttributeDefinition def = (ConfigAttributeDefinition) iter.next(); Iterator attributes = def.getConfigAttributes(); while (attributes.hasNext()) { ConfigAttribute attr = (ConfigAttribute) attributes.next(); if (!this.channelDecisionManager.supports(attr)) { set.add(attr); } } } if (set.size() == 0) { if (logger.isInfoEnabled()) { logger.info("Validated configuration attributes"); } } else { throw new IllegalArgumentException("Unsupported configuration attributes: " + set.toString()); } }
From source file:gov.nih.nci.caarray.application.translation.geosoft.GeoSoftExporterBeanTest.java
@Test public void testExportArchiveZip() throws Exception { final Project p = makeGoodProject(); final List<PackagingInfo> infos = this.bean.getAvailablePackagingInfos(p); final PackagingInfo zipPi = Iterables.find(infos, new Predicate<PackagingInfo>() { @Override/* ww w.ja va 2 s. c om*/ public boolean apply(PackagingInfo t) { return t.getMethod() == PackagingInfo.PackagingMethod.ZIP; } }); final File f = File.createTempFile("test", zipPi.getName()); final FileOutputStream fos = new FileOutputStream(f); this.bean.export(p, "http://example.com/my_experiemnt", PackagingInfo.PackagingMethod.ZIP, fos); fos.close(); final ZipFile zf = new ZipFile(f); final Enumeration<ZipArchiveEntry> en = zf.getEntries(); final Set<String> entries = new HashSet<String>(); entries.addAll(java.util.Arrays.asList("test-exp-id.soft.txt", "raw_file.data", "derived_file.data", "supplimental.data")); while (en.hasMoreElements()) { final ZipArchiveEntry ze = en.nextElement(); assertTrue(ze.getName() + " unexpected", entries.remove(ze.getName())); } assertTrue(entries.toString() + " not found", entries.isEmpty()); }
From source file:com.oneops.transistor.util.CloudUtil.java
private Map<String, TreeSet<String>> getMissingCloudServices(long manifestPlatCiId, Set<String> requiredServices) { Map<String, TreeSet<String>> missingCloud2Services = new TreeMap<>(); //get clouds/* w w w . ja v a 2 s .c om*/ List<CmsRfcRelation> cloudRelations = getCloudsForPlatform(manifestPlatCiId); // get services for all clouds cloudRelations.forEach(cloudRelation -> { Set<String> cloudServices = getCloudServices(cloudRelation); String cloud = cloudRelation.getToRfcCi().getCiName(); //check if service is configured requiredServices.stream().filter(s -> !cloudServices.contains(s)) .forEach(s -> missingCloud2Services.computeIfAbsent(cloud, k -> new TreeSet<>()).add(s)); logger.debug("cloud: " + cloud + " required services:: " + requiredServices.toString() + " missingServices " + missingCloud2Services.keySet()); }); return missingCloud2Services; }
From source file:org.trpr.platform.batch.impl.spring.admin.SimpleJobConfigurationService.java
/** * Interface method implementation. After setting an XML File, also saves the previous file. * @see org.trpr.platform.batch.spi.spring.admin.JobConfigurationService#setJobconfig(String, byte[]) *///ww w . j a v a2 s . co m @Override public void setJobConfig(List<String> jobNames, Resource jobConfigFile) throws PlatformException { if (this.jobXMLFile.isEmpty()) this.scanXMLFiles(); String destPath = null; //Check if jobName has been changed try { //Using sets to comapare whether the two list of jobNames are equal Set<String> jobNamesUserSet = new HashSet<String>(); Set<String> jobNamesFileSet = new HashSet<String>(); jobNamesUserSet.addAll(jobNames); jobNamesFileSet.addAll(ConfigFileUtils.getJobName(jobConfigFile)); if (!jobNamesUserSet.equals(jobNamesFileSet)) { throw new PlatformException("The Job Name cannot be changed. Expecting: " + jobNamesUserSet.toString() + " Got: " + jobNamesFileSet.toString()); } //Take first jobName to check whether it is a new Job String jobName = jobNames.get(0); //Code for overwriting file to location if (this.getJobConfigURI(jobName) == null) { //NEW JOB destPath = this.getJobStoreURI(jobName).getPath() + SimpleJobConfigurationService.SPRING_BATCH_FILE; } else { //Already deployed job. Store the previous file destPath = this.getJobConfigURI(jobName).getPath(); this.createPrevConfigFile(jobName); } this.upload(ConfigFileUtils.getContents(jobConfigFile).getBytes(), destPath); for (String allJobName : jobNames) { this.jobXMLFile.put(allJobName, new File(destPath).toURI()); } LOGGER.info("Uploaded job config to " + destPath); } catch (IOException ioe) { LOGGER.error("Error creating job configuration file for : " + jobNames.toString() + " in location : " + destPath); throw new PlatformException("Error creating job configuration file for : " + jobNames.toString() + " in location : " + destPath, ioe); } }
From source file:org.cloudfoundry.identity.uaa.client.ClientAdminEndpointsValidator.java
public ClientDetails validate(ClientDetails prototype, boolean create, boolean checkAdmin) throws InvalidClientDetailsException { BaseClientDetails client = new BaseClientDetails(prototype); if (prototype instanceof BaseClientDetails) { Set<String> scopes = ((BaseClientDetails) prototype).getAutoApproveScopes(); if (scopes != null) { client.setAutoApproveScopes(((BaseClientDetails) prototype).getAutoApproveScopes()); }/*from w w w . ja v a 2 s .co m*/ } client.setAdditionalInformation(prototype.getAdditionalInformation()); String clientId = client.getClientId(); if (create && reservedClientIds.contains(clientId)) { throw new InvalidClientDetailsException("Not allowed: " + clientId + " is a reserved client_id"); } Set<String> requestedGrantTypes = client.getAuthorizedGrantTypes(); if (requestedGrantTypes.isEmpty()) { throw new InvalidClientDetailsException( "An authorized grant type must be provided. Must be one of: " + VALID_GRANTS.toString()); } checkRequestedGrantTypes(requestedGrantTypes); if ((requestedGrantTypes.contains("authorization_code") || requestedGrantTypes.contains("password")) && !requestedGrantTypes.contains("refresh_token")) { logger.debug("requested grant type missing refresh_token: " + clientId); requestedGrantTypes.add("refresh_token"); } if (checkAdmin && !(securityContextAccessor.isAdmin() || securityContextAccessor.getScopes().contains("clients.admin"))) { // Not admin, so be strict with grant types and scopes for (String grant : requestedGrantTypes) { if (NON_ADMIN_INVALID_GRANTS.contains(grant)) { throw new InvalidClientDetailsException( grant + " is not an allowed grant type for non-admin caller."); } } if (requestedGrantTypes.contains("implicit") && requestedGrantTypes.contains("authorization_code")) { throw new InvalidClientDetailsException( "Not allowed: implicit grant type is not allowed together with authorization_code"); } String callerId = securityContextAccessor.getClientId(); ClientDetails caller = null; try { caller = clientDetailsService.retrieve(callerId); } catch (Exception e) { // best effort to get the caller, but the caller might not belong to this zone. } if (callerId != null && caller != null) { // New scopes are allowed if they are for the caller or the new // client. String callerPrefix = callerId + "."; String clientPrefix = clientId + "."; Set<String> validScope = caller.getScope(); for (String scope : client.getScope()) { if (scope.startsWith(callerPrefix) || scope.startsWith(clientPrefix)) { // Allowed continue; } if (!validScope.contains(scope)) { throw new InvalidClientDetailsException(scope + " is not an allowed scope for caller=" + callerId + ". Must have prefix in [" + callerPrefix + "," + clientPrefix + "] or be one of: " + validScope.toString()); } } } else { // New scopes are allowed if they are for the caller or the new // client. String clientPrefix = clientId + "."; for (String scope : client.getScope()) { if (!scope.startsWith(clientPrefix)) { throw new InvalidClientDetailsException( scope + " is not an allowed scope for null caller and client_id=" + clientId + ". Must start with '" + clientPrefix + "'"); } } } Set<String> validAuthorities = new HashSet<String>(NON_ADMIN_VALID_AUTHORITIES); if (requestedGrantTypes.contains("client_credentials")) { // If client_credentials is used then the client might be a // resource server validAuthorities.add("uaa.resource"); } for (String authority : AuthorityUtils.authorityListToSet(client.getAuthorities())) { if (!validAuthorities.contains(authority)) { throw new InvalidClientDetailsException(authority + " is not an allowed authority for caller=" + callerId + ". Must be one of: " + validAuthorities.toString()); } } } if (client.getAuthorities().isEmpty()) { client.setAuthorities(AuthorityUtils.commaSeparatedStringToAuthorityList("uaa.none")); } // The UAA does not allow or require resource ids to be registered // because they are determined dynamically client.setResourceIds(Collections.singleton("none")); if (client.getScope().isEmpty()) { client.setScope(Collections.singleton("uaa.none")); } if (requestedGrantTypes.contains("implicit")) { if (StringUtils.hasText(client.getClientSecret())) { throw new InvalidClientDetailsException("Implicit grant should not have a client_secret"); } } if (create) { // Only check for missing secret if client is being created. if ((requestedGrantTypes.contains("client_credentials") || requestedGrantTypes.contains("authorization_code")) && !StringUtils.hasText(client.getClientSecret())) { throw new InvalidClientDetailsException( "Client secret is required for client_credentials and authorization_code grant types"); } } return client; }
From source file:org.cloudfoundry.identity.uaa.oauth.ClientAdminEndpointsValidator.java
public ClientDetails validate(ClientDetails prototype, boolean create, boolean checkAdmin) throws InvalidClientDetailsException { BaseClientDetails client = new BaseClientDetails(prototype); if (prototype instanceof BaseClientDetails) { Set<String> scopes = ((BaseClientDetails) prototype).getAutoApproveScopes(); if (scopes != null) { client.setAutoApproveScopes(((BaseClientDetails) prototype).getAutoApproveScopes()); }/*from w ww.ja v a 2 s.c om*/ } client.setAdditionalInformation(prototype.getAdditionalInformation()); String clientId = client.getClientId(); if (create && reservedClientIds.contains(clientId)) { throw new InvalidClientDetailsException("Not allowed: " + clientId + " is a reserved client_id"); } Set<String> requestedGrantTypes = client.getAuthorizedGrantTypes(); if (requestedGrantTypes.isEmpty()) { throw new InvalidClientDetailsException( "An authorized grant type must be provided. Must be one of: " + VALID_GRANTS.toString()); } for (String grant : requestedGrantTypes) { if (!VALID_GRANTS.contains(grant)) { throw new InvalidClientDetailsException( grant + " is not an allowed grant type. Must be one of: " + VALID_GRANTS.toString()); } } if ((requestedGrantTypes.contains("authorization_code") || requestedGrantTypes.contains("password")) && !requestedGrantTypes.contains("refresh_token")) { logger.debug("requested grant type missing refresh_token: " + clientId); requestedGrantTypes.add("refresh_token"); } if (checkAdmin && !(securityContextAccessor.isAdmin() || UaaStringUtils .getStringsFromAuthorities(securityContextAccessor.getAuthorities()).contains("clients.admin"))) { // Not admin, so be strict with grant types and scopes for (String grant : requestedGrantTypes) { if (NON_ADMIN_INVALID_GRANTS.contains(grant)) { throw new InvalidClientDetailsException( grant + " is not an allowed grant type for non-admin caller."); } } if (requestedGrantTypes.contains("implicit") && requestedGrantTypes.contains("authorization_code")) { throw new InvalidClientDetailsException( "Not allowed: implicit grant type is not allowed together with authorization_code"); } String callerId = securityContextAccessor.getClientId(); ClientDetails caller = null; try { caller = clientDetailsService.retrieve(callerId); } catch (Exception e) { // best effort to get the caller, but the caller might not belong to this zone. } if (callerId != null && caller != null) { // New scopes are allowed if they are for the caller or the new // client. String callerPrefix = callerId + "."; String clientPrefix = clientId + "."; Set<String> validScope = caller.getScope(); for (String scope : client.getScope()) { if (scope.startsWith(callerPrefix) || scope.startsWith(clientPrefix)) { // Allowed continue; } if (!validScope.contains(scope)) { throw new InvalidClientDetailsException(scope + " is not an allowed scope for caller=" + callerId + ". Must have prefix in [" + callerPrefix + "," + clientPrefix + "] or be one of: " + validScope.toString()); } } } else { // New scopes are allowed if they are for the caller or the new // client. String clientPrefix = clientId + "."; for (String scope : client.getScope()) { if (!scope.startsWith(clientPrefix)) { throw new InvalidClientDetailsException( scope + " is not an allowed scope for null caller and client_id=" + clientId + ". Must start with '" + clientPrefix + "'"); } } } Set<String> validAuthorities = new HashSet<String>(NON_ADMIN_VALID_AUTHORITIES); if (requestedGrantTypes.contains("client_credentials")) { // If client_credentials is used then the client might be a // resource server validAuthorities.add("uaa.resource"); } for (String authority : AuthorityUtils.authorityListToSet(client.getAuthorities())) { if (!validAuthorities.contains(authority)) { throw new InvalidClientDetailsException(authority + " is not an allowed authority for caller=" + callerId + ". Must be one of: " + validAuthorities.toString()); } } } if (client.getAuthorities().isEmpty()) { client.setAuthorities(AuthorityUtils.commaSeparatedStringToAuthorityList("uaa.none")); } // The UAA does not allow or require resource ids to be registered // because they are determined dynamically client.setResourceIds(Collections.singleton("none")); if (client.getScope().isEmpty()) { client.setScope(Collections.singleton("uaa.none")); } if (requestedGrantTypes.contains("implicit")) { if (StringUtils.hasText(client.getClientSecret())) { throw new InvalidClientDetailsException("Implicit grant should not have a client_secret"); } } if (create) { // Only check for missing secret if client is being created. if ((requestedGrantTypes.contains("client_credentials") || requestedGrantTypes.contains("authorization_code")) && !StringUtils.hasText(client.getClientSecret())) { throw new InvalidClientDetailsException( "Client secret is required for client_credentials and authorization_code grant types"); } } return client; }