List of usage examples for com.amazonaws.auth BasicAWSCredentials BasicAWSCredentials
public BasicAWSCredentials(String accessKey, String secretKey)
From source file:fr.eurecom.hybris.kvs.drivers.AmazonKvs.java
License:Apache License
public AmazonKvs(String id, final String accessKey, final String secretKey, String container, boolean enabled, int cost) throws IOException { super(id, container, enabled, cost); BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); this.s3 = new AmazonS3Client(credentials); this.tm = new TransferManager(credentials); TransferManagerConfiguration tmc = new TransferManagerConfiguration(); tmc.setMultipartUploadThreshold(30000000L); // 30 MB tmc.setMinimumUploadPartSize(10000000); // 10 MB this.tm.setConfiguration(tmc); this.createContainer(); }
From source file:fsi_admin.JAwsS3Conn.java
License:Open Source License
@SuppressWarnings({ "rawtypes", "unchecked" }) public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String ERROR = null, codErr = null; try {/*from w w w .j a v a 2s . c om*/ Properties parametros = new Properties(); Vector archivos = new Vector(); DiskFileUpload fu = new DiskFileUpload(); List items = fu.parseRequest(request); Iterator iter = items.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (item.isFormField()) parametros.put(item.getFieldName(), item.getString()); else archivos.addElement(item); } if (parametros.getProperty("SERVER") == null || parametros.getProperty("DATABASE") == null || parametros.getProperty("USER") == null || parametros.getProperty("PASSWORD") == null || parametros.getProperty("ACTION") == null) { System.out.println("No recibi parametros de conexin antes del archivo"); ERROR = "ERROR: El servidor no recibi todos los parametros de conexion (SERVER,DATABASE,USER,PASSWORD,ACTION) antes del archivo"; codErr = "3"; ingresarRegistroFallido(request.getRemoteAddr(), request.getRemoteHost(), parametros.getProperty("SERVER"), parametros.getProperty("USER"), parametros.getProperty("PASSWORD"), request, ERROR, 3); } //Hasta aqui se han enviado todos los parametros ninguno nulo if (ERROR == null) { StringBuffer msj = new StringBuffer(), S3BUKT = new StringBuffer(), S3USR = new StringBuffer(), S3PASS = new StringBuffer(); MutableBoolean COBRAR = new MutableBoolean(false); MutableDouble COSTO = new MutableDouble(0.0), SALDO = new MutableDouble(0.0); // Primero obtiene info del S3 if (!obtenInfoAWSS3(request.getRemoteAddr(), request.getRemoteHost(), parametros.getProperty("SERVER"), parametros.getProperty("DATABASE"), parametros.getProperty("USER"), parametros.getProperty("PASSWORD"), S3BUKT, S3USR, S3PASS, msj, COSTO, SALDO, COBRAR)) { System.out.println("El usuario y contrasea de servicio estan mal"); ERROR = msj.toString(); codErr = "2"; ingresarRegistroFallido(request.getRemoteAddr(), request.getRemoteHost(), parametros.getProperty("SERVER"), parametros.getProperty("USER"), parametros.getProperty("PASSWORD"), request, ERROR, 2); } else { AWSCredentials credentials = new BasicAWSCredentials(S3USR.toString(), S3PASS.toString()); AmazonS3 s3 = new AmazonS3Client(credentials); Region usWest2 = Region.getRegion(Regions.US_WEST_2); s3.setRegion(usWest2); //System.out.println("AwsConn:" + parametros.getProperty("NOMBRE") + ":parametros.getProperty(NOMBRE)"); String nombre = parametros.getProperty("SERVER") + parametros.getProperty("DATABASE") + parametros.getProperty("ID_MODULO") + parametros.getProperty("OBJIDS") + parametros.getProperty("IDSEP") + parametros.getProperty("NOMBRE"); //System.out.println("AwsConn_Nombre:" + nombre + ":nombre"); if (parametros.getProperty("ACTION").equals("SUBIR")) { Double TOTBITES = new Double(Double.parseDouble(parametros.getProperty("TOTBITES"))); Double TAMBITES = new Double(Double.parseDouble(parametros.getProperty("TAMBITES"))); if (COBRAR.booleanValue() && SALDO .doubleValue() < (COSTO.doubleValue() * (((TOTBITES + TAMBITES) / 1024) / 1024))) { System.out .println("El servicio S3 de subida tiene un costo que no alcanza en el saldo"); ERROR = "El servicio S3 de subida tiene un costo que no alcanza en el saldo"; codErr = "2"; ingresarRegistroFallido(request.getRemoteAddr(), request.getRemoteHost(), parametros.getProperty("SERVER"), parametros.getProperty("USER"), parametros.getProperty("PASSWORD"), request, ERROR, 2); } else { if (!subirArchivo(msj, s3, S3BUKT.toString(), nombre, archivos)) { System.out.println("No se permiti subir el archivo al s3"); ERROR = msj.toString(); codErr = "3"; ingresarRegistroFallido(request.getRemoteAddr(), request.getRemoteHost(), parametros.getProperty("SERVER"), parametros.getProperty("USER"), parametros.getProperty("PASSWORD"), request, ERROR, 3); } else { ingresarRegistroExitoso(parametros.getProperty("SERVER"), parametros.getProperty("DATABASE"), parametros.getProperty("ID_MODULO"), parametros.getProperty("OBJIDS"), parametros.getProperty("IDSEP"), parametros.getProperty("NOMBRE"), parametros.getProperty("TAMBITES")); } } } else if (parametros.getProperty("ACTION").equals("ELIMINAR")) { Double TOTBITES = new Double(Double.parseDouble(parametros.getProperty("TOTBITES"))); if (COBRAR.booleanValue() && SALDO.doubleValue() < (COSTO.doubleValue() * ((TOTBITES / 1024) / 1024))) { System.out .println("El servicio S3 de borrado tiene un costo que no alcanza en el saldo"); ERROR = "El servicio S3 de borrado tiene un costo que no alcanza en el saldo"; codErr = "2"; ingresarRegistroFallido(request.getRemoteAddr(), request.getRemoteHost(), parametros.getProperty("SERVER"), parametros.getProperty("USER"), parametros.getProperty("PASSWORD"), request, ERROR, 2); } else { if (!eliminarArchivo(msj, s3, S3BUKT.toString(), nombre)) { System.out.println("No se permiti eliminar el archivo del s3"); ERROR = msj.toString(); codErr = "3"; ingresarRegistroFallido(request.getRemoteAddr(), request.getRemoteHost(), parametros.getProperty("SERVER"), parametros.getProperty("USER"), parametros.getProperty("PASSWORD"), request, ERROR, 3); } else { eliminarRegistroExitoso(parametros.getProperty("SERVER"), parametros.getProperty("DATABASE"), parametros.getProperty("ID_MODULO"), parametros.getProperty("OBJIDS"), parametros.getProperty("IDSEP"), parametros.getProperty("NOMBRE")); } } } else if (parametros.getProperty("ACTION").equals("DESCARGAR")) { Double TOTBITES = new Double(Double.parseDouble(parametros.getProperty("TOTBITES"))); //System.out.println("COBRAR: " + COBRAR.booleanValue() + " SALDO: " + SALDO.doubleValue() + " COSTO: " + COSTO.doubleValue() + " TOTBITES: " + TOTBITES + " TOTMB: " + ((TOTBITES / 1024) / 1024) + " RES: " + (COSTO.doubleValue() * ((TOTBITES / 1024) / 1024))); if (COBRAR.booleanValue() && SALDO.doubleValue() < (COSTO.doubleValue() * ((TOTBITES / 1024) / 1024))) { System.out.println( "El servicio S3 de descarga tiene un costo que no alcanza en el saldo"); ERROR = "El servicio S3 de descarga tiene un costo que no alcanza en el saldo"; codErr = "2"; ingresarRegistroFallido(request.getRemoteAddr(), request.getRemoteHost(), parametros.getProperty("SERVER"), parametros.getProperty("USER"), parametros.getProperty("PASSWORD"), request, ERROR, 2); } else { if (!descargarArchivo(response, msj, s3, S3BUKT.toString(), nombre, parametros.getProperty("NOMBRE"))) { System.out.println("No se permiti descargar el archivo del s3"); ERROR = msj.toString(); codErr = "3"; ingresarRegistroFallido(request.getRemoteAddr(), request.getRemoteHost(), parametros.getProperty("SERVER"), parametros.getProperty("USER"), parametros.getProperty("PASSWORD"), request, ERROR, 3); } else return; } } if (ERROR == null) { //Devuelve la respuesta al cliente Element S3 = new Element("S3"); S3.setAttribute("Archivo", nombre); S3.setAttribute("MsjError", ""); Document Reporte = new Document(S3); Format format = Format.getPrettyFormat(); format.setEncoding("utf-8"); format.setTextMode(TextMode.NORMALIZE); XMLOutputter xmlOutputter = new XMLOutputter(format); ByteArrayOutputStream out = new ByteArrayOutputStream(); xmlOutputter.output(Reporte, out); byte[] data = out.toByteArray(); ByteArrayInputStream istream = new ByteArrayInputStream(data); String destino = "Archivo.xml"; JBajarArchivo fd = new JBajarArchivo(); fd.doDownload(response, getServletConfig().getServletContext(), istream, "text/xml", data.length, destino); } } } } catch (Exception e) { e.printStackTrace(); ERROR = "ERROR DE EXCEPCION EN SERVIDOR AWS S3: " + e.getMessage(); } //Genera el archivo XML de error para ser devuelto al Servidor if (ERROR != null) { Element SIGN_ERROR = new Element("SIGN_ERROR"); SIGN_ERROR.setAttribute("CodError", codErr); SIGN_ERROR.setAttribute("MsjError", ERROR); Document Reporte = new Document(SIGN_ERROR); Format format = Format.getPrettyFormat(); format.setEncoding("utf-8"); format.setTextMode(TextMode.NORMALIZE); XMLOutputter xmlOutputter = new XMLOutputter(format); ByteArrayOutputStream out = new ByteArrayOutputStream(); xmlOutputter.output(Reporte, out); byte[] data = out.toByteArray(); ByteArrayInputStream istream = new ByteArrayInputStream(data); String destino = "SIGN_ERROR.xml"; JBajarArchivo fd = new JBajarArchivo(); fd.doDownload(response, getServletConfig().getServletContext(), istream, "text/xml", data.length, destino); } }
From source file:gateway.controller.util.GatewayUtil.java
License:Apache License
/** * Initializing the Kafka Producer on Controller startup. *//*from ww w .j av a2 s . c om*/ @PostConstruct public void init() { // Kafka Producer. producer = KafkaClientFactory.getProducer(KAFKA_ADDRESS.split(":")[0], KAFKA_ADDRESS.split(":")[1]); // Connect to S3 Bucket. Only apply credentials if they are present. if ((AMAZONS3_ACCESS_KEY.isEmpty()) && (AMAZONS3_PRIVATE_KEY.isEmpty())) { s3Client = new AmazonS3Client(); } else { BasicAWSCredentials credentials = new BasicAWSCredentials(AMAZONS3_ACCESS_KEY, AMAZONS3_PRIVATE_KEY); s3Client = new AmazonS3Client(credentials); } }
From source file:glacierpipe.GlacierPipeMain.java
License:Apache License
public static void main(String[] args) throws IOException, ParseException { CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(OPTIONS, args); if (cmd.hasOption("help")) { try (PrintWriter writer = new PrintWriter(System.err)) { printHelp(writer);//from w ww.j a va2s . co m } System.exit(0); } else if (cmd.hasOption("upload")) { // Turn the CommandLine into Properties Properties cliProperties = new Properties(); for (Iterator<?> i = cmd.iterator(); i.hasNext();) { Option o = (Option) i.next(); String opt = o.getLongOpt(); opt = opt != null ? opt : o.getOpt(); String value = o.getValue(); value = value != null ? value : ""; cliProperties.setProperty(opt, value); } // Build up a configuration ConfigBuilder configBuilder = new ConfigBuilder(); // Archive name List<?> archiveList = cmd.getArgList(); if (archiveList.size() > 1) { throw new ParseException("Too many arguments"); } else if (archiveList.isEmpty()) { throw new ParseException("No archive name provided"); } configBuilder.setArchive(archiveList.get(0).toString()); // All other arguments on the command line configBuilder.setFromProperties(cliProperties); // Load any config from the properties file Properties fileProperties = new Properties(); try (InputStream in = new FileInputStream(configBuilder.propertiesFile)) { fileProperties.load(in); } catch (IOException e) { System.err.printf("Warning: unable to read properties file %s; %s%n", configBuilder.propertiesFile, e); } configBuilder.setFromProperties(fileProperties); // ... Config config = new Config(configBuilder); IOBuffer buffer = new MemoryIOBuffer(config.partSize); AmazonGlacierClient client = new AmazonGlacierClient( new BasicAWSCredentials(config.accessKey, config.secretKey)); client.setEndpoint(config.endpoint); // Actual upload try (InputStream in = new BufferedInputStream(System.in, 4096); PrintWriter writer = new PrintWriter(System.err); ObservableProperties configMonitor = config.reloadProperties ? new ObservableProperties(config.propertiesFile) : null; ProxyingThrottlingStrategy throttlingStrategy = new ProxyingThrottlingStrategy(config);) { TerminalGlacierPipeObserver observer = new TerminalGlacierPipeObserver(writer); if (configMonitor != null) { configMonitor.registerObserver(throttlingStrategy); } GlacierPipe pipe = new GlacierPipe(buffer, observer, config.maxRetries, throttlingStrategy); pipe.pipe(client, config.vault, config.archive, in); } catch (Exception e) { e.printStackTrace(System.err); } System.exit(0); } else { try (PrintWriter writer = new PrintWriter(System.err)) { writer.println("No action specified."); printHelp(writer); } System.exit(-1); } }
From source file:gobblin.aws.AWSClusterSecurityManager.java
License:Apache License
private void login() throws IOException { // Refresh login configuration details from config fetchLoginConfiguration();//from w ww .j ava 2s . co m // Primary AWS user login this.basicAWSCredentials = new BasicAWSCredentials(this.serviceAccessKey, this.serviceSecretKey); // If running on behalf of another AWS user, // .. assume role as configured if (this.clientAssumeRole) { AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest().withRoleSessionName(this.clientSessionId) .withExternalId(this.clientExternalId).withRoleArn(this.clientRoleArn); final AWSSecurityTokenServiceClient stsClient = new AWSSecurityTokenServiceClient( this.basicAWSCredentials); final AssumeRoleResult assumeRoleResult = stsClient.assumeRole(assumeRoleRequest); this.basicSessionCredentials = new BasicSessionCredentials( assumeRoleResult.getCredentials().getAccessKeyId(), assumeRoleResult.getCredentials().getSecretAccessKey(), assumeRoleResult.getCredentials().getSessionToken()); } this.lastRefreshTimeInMillis = System.currentTimeMillis(); }
From source file:goraci.Verify.java
License:Apache License
@SuppressWarnings({ "unchecked", "rawtypes" }) public void start(Path outputDir, int numReducers, boolean concurrent, String accessKey, String secretKey) throws GoraException, IOException, Exception { LOG.info("Running Verify with outputDir=" + outputDir + ", numReducers=" + numReducers); //DataStore<Long,CINode> store = DataStoreFactory.getDataStore(Long.class, CINode.class, new Configuration()); auth = new BasicAWSCredentials(accessKey, secretKey); DataStore<Long, cidynamonode> store = WSDataStoreFactory.createDataStore(DynamoDBStore.class, DynamoDBKey.class, cidynamonode.class, auth); job = new Job(getConf()); if (!job.getConfiguration().get("io.serializations") .contains("org.apache.hadoop.io.serializer.JavaSerialization")) { job.getConfiguration().set("io.serializations", job.getConfiguration().get("io.serializations") + ",org.apache.hadoop.io.serializer.JavaSerialization"); }//from ww w .j a v a2 s . c om job.setJobName("Link Verifier"); job.setNumReduceTasks(numReducers); job.setJarByClass(getClass()); Query query = store.newQuery(); //if (!concurrent) { // no concurrency filtering, only need prev field //query.setFields("prev"); //} else { //readFlushed(job.getCon figuration()); //} GoraMapper.initMapperJob(job, query, store, DynamoDBKey.class, VLongWritable.class, VerifyMapper.class, true); job.getConfiguration().setBoolean("mapred.map.tasks.speculative.execution", false); job.setReducerClass(VerifyReducer.class); job.setOutputFormatClass(TextOutputFormat.class); TextOutputFormat.setOutputPath(job, outputDir); store.close(); job.submit(); }
From source file:goraci.Walker.java
License:Apache License
private void setAuth(String accessKey, String secretKey) { auth = new BasicAWSCredentials(accessKey, secretKey); }
From source file:gr.abiss.calipso.fs.S3FilePersistenceServiceImpl.java
License:Open Source License
@PostConstruct public void postConstruct() { // create S3 credentials BasicAWSCredentials credentials = new BasicAWSCredentials(awsAccessKey, awsSecretAccessKey); // setup client this.s3Client = new AmazonS3Client(credentials); LOGGER.debug("Created S3 client"); }
From source file:grails.plugins.crm.content.aws.AmazonS3ClientFactory.java
License:Apache License
@Override public AmazonS3 getObject() { AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.setSignerOverride("AWSS3V4SignerType"); return AmazonS3ClientBuilder.standard() .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, region)) .withPathStyleAccessEnabled(true).withClientConfiguration(clientConfiguration) .withCredentials(new AWSStaticCredentialsProvider(credentials)).build(); }
From source file:hu.mta.sztaki.lpds.cloud.entice.imageoptimizer.iaashandler.amazontarget.EC2VirtualMachine.java
License:Apache License
@Override protected void parseVMCreatorParameters(Map<String, Vector<String>> parameters) { super.datacollectorDelay = 2000; // 2 seconds delay between polls disableUnparseableDateWarning();//from w ww.j a v a2 s . c o m if (parameters == null) throw new IllegalArgumentException("Missing parameters"); if (!parameters.containsKey(ACCESS_KEY) || parameters.get(ACCESS_KEY) == null || parameters.get(ACCESS_KEY).size() == 0 || parameters.get(ACCESS_KEY).get(0) == null) throw new IllegalArgumentException("Missing parameter: " + ACCESS_KEY); if (!parameters.containsKey(SECRET_KEY) || parameters.get(SECRET_KEY) == null || parameters.get(SECRET_KEY).size() == 0 || parameters.get(SECRET_KEY).get(0) == null) throw new IllegalArgumentException("Missing parameter: " + SECRET_KEY); this.accessKey = parameters.get(ACCESS_KEY).get(0); this.secretKey = parameters.get(SECRET_KEY).get(0); if (parameters.containsKey(ENDPOINT) && parameters.get(ENDPOINT) != null && parameters.get(ENDPOINT).size() > 0) this.endpoint = parameters.get(ENDPOINT).get(0); if (parameters.containsKey(INSTANCE_TYPE) && parameters.get(INSTANCE_TYPE) != null && parameters.get(INSTANCE_TYPE).size() > 0) this.instanceType = parameters.get(INSTANCE_TYPE).get(0); if (parameters.containsKey(LOGIN_NAME) && parameters.get(LOGIN_NAME) != null && parameters.get(LOGIN_NAME).size() > 0) super.loginName = parameters.get(LOGIN_NAME).get(0); AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey); ClientConfiguration clientConfiguration = new ClientConfiguration(); amazonEC2Client = new AmazonEC2Client(awsCredentials, clientConfiguration); amazonEC2Client.setEndpoint(endpoint); }