com.amazonaws.auth.AnonymousAWSCredentials Java Examples

The following examples show how to use com.amazonaws.auth.AnonymousAWSCredentials. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractAWSProcessor.java    From nifi with Apache License 2.0 6 votes vote down vote up
protected AWSCredentials getCredentials(final ProcessContext context) {
    final String accessKey = context.getProperty(ACCESS_KEY).evaluateAttributeExpressions().getValue();
    final String secretKey = context.getProperty(SECRET_KEY).evaluateAttributeExpressions().getValue();

    final String credentialsFile = context.getProperty(CREDENTIALS_FILE).getValue();

    if (credentialsFile != null) {
        try {
            return new PropertiesCredentials(new File(credentialsFile));
        } catch (final IOException ioe) {
            throw new ProcessException("Could not read Credentials File", ioe);
        }
    }

    if (accessKey != null && secretKey != null) {
        return new BasicAWSCredentials(accessKey, secretKey);
    }

    return new AnonymousAWSCredentials();

}
 
Example #2
Source File: CognitoHelper.java    From alexa-web-information-service-api-samples with MIT License 6 votes vote down vote up
/**
 * Verify the verification code sent on the user phone.
 *
 * @param username User for which we are submitting the verification code.
 * @param code     Verification code delivered to the user.
 * @return if the verification is successful.
 */
boolean VerifyAccessCode(String username, String code) {
    AnonymousAWSCredentials awsCreds = new AnonymousAWSCredentials();
    AWSCognitoIdentityProvider cognitoIdentityProvider = AWSCognitoIdentityProviderClientBuilder
            .standard()
            .withCredentials(new AWSStaticCredentialsProvider(awsCreds))
            .withRegion(Regions.fromName(REGION))
            .build();

    ConfirmSignUpRequest confirmSignUpRequest = new ConfirmSignUpRequest();
    confirmSignUpRequest.setUsername(username);
    confirmSignUpRequest.setConfirmationCode(code);
    confirmSignUpRequest.setClientId(CLIENTAPP_ID);

    try {
        ConfirmSignUpResult confirmSignUpResult = cognitoIdentityProvider.confirmSignUp(confirmSignUpRequest);
    } catch (Exception ex) {
        System.out.println(ex);
        return false;
    }
    return true;
}
 
Example #3
Source File: CognitoHelper.java    From alexa-web-information-service-api-samples with MIT License 6 votes vote down vote up
/**
 * Returns the AWS credentials
 *
 * @param idprovider the IDP provider for the login map
 * @param id         the username for the login map.
 * @return returns the credentials based on the access token returned from the user pool.
 */
Credentials GetCredentials(String idprovider, String id) {
    AnonymousAWSCredentials awsCreds = new AnonymousAWSCredentials();
    AmazonCognitoIdentity provider = AmazonCognitoIdentityClientBuilder
            .standard()
            .withCredentials(new AWSStaticCredentialsProvider(awsCreds))
            .withRegion(Regions.fromName(REGION))
            .build();

    GetIdRequest idrequest = new GetIdRequest();
    idrequest.setIdentityPoolId(FED_POOL_ID);
    idrequest.addLoginsEntry(idprovider, id);
    GetIdResult idResult = provider.getId(idrequest);

    GetCredentialsForIdentityRequest request = new GetCredentialsForIdentityRequest();
    request.setIdentityId(idResult.getIdentityId());
    request.addLoginsEntry(idprovider, id);

    GetCredentialsForIdentityResult result = provider.getCredentialsForIdentity(request);
    return result.getCredentials();
}
 
Example #4
Source File: AuthenticationHelper.java    From alexa-web-information-service-api-samples with MIT License 6 votes vote down vote up
/**
 * Method to orchestrate the SRP Authentication
 *
 * @param username Username for the SRP request
 * @param password Password for the SRP request
 * @return the JWT token if the request is successful else null.
 */
String PerformSRPAuthentication(String username, String password) {
    String authresult = null;

    InitiateAuthRequest initiateAuthRequest = initiateUserSrpAuthRequest(username);
    try {
        AnonymousAWSCredentials awsCreds = new AnonymousAWSCredentials();
        AWSCognitoIdentityProvider cognitoIdentityProvider = AWSCognitoIdentityProviderClientBuilder
                .standard()
                .withCredentials(new AWSStaticCredentialsProvider(awsCreds))
                .withRegion(Regions.fromName(this.region))
                .build();
        InitiateAuthResult initiateAuthResult = cognitoIdentityProvider.initiateAuth(initiateAuthRequest);
        if (ChallengeNameType.PASSWORD_VERIFIER.toString().equals(initiateAuthResult.getChallengeName())) {
            RespondToAuthChallengeRequest challengeRequest = userSrpAuthRequest(initiateAuthResult, password);
            RespondToAuthChallengeResult result = cognitoIdentityProvider.respondToAuthChallenge(challengeRequest);
            //System.out.println(result);
            System.out.println(CognitoJWTParser.getPayload(result.getAuthenticationResult().getIdToken()));
            authresult = result.getAuthenticationResult().getIdToken();
        }
    } catch (final Exception ex) {
        System.out.println("Exception" + ex);

    }
    return authresult;
}
 
Example #5
Source File: AbstractAWSProcessor.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
protected AWSCredentials getCredentials(final ProcessContext context) {
    final String accessKey = context.getProperty(ACCESS_KEY).evaluateAttributeExpressions().getValue();
    final String secretKey = context.getProperty(SECRET_KEY).evaluateAttributeExpressions().getValue();

    final String credentialsFile = context.getProperty(CREDENTIALS_FILE).getValue();

    if (credentialsFile != null) {
        try {
            return new PropertiesCredentials(new File(credentialsFile));
        } catch (final IOException ioe) {
            throw new ProcessException("Could not read Credentials File", ioe);
        }
    }

    if (accessKey != null && secretKey != null) {
        return new BasicAWSCredentials(accessKey, secretKey);
    }

    return new AnonymousAWSCredentials();

}
 
Example #6
Source File: MockAwsSqs.java    From aws-codecommit-trigger-plugin with Apache License 2.0 6 votes vote down vote up
private void start() throws IOException {
    System.out.println("starting mock sqs server");
    //this.port = findFreeLocalPort(); @see https://github.com/findify/sqsmock/pull/7
    this.api = new SQSService(this.port, 1);
    this.api.start();

    AWSCredentials credentials = new AnonymousAWSCredentials();
    this.sqsClient = new MockSQSClient(credentials);

    this.endpoint = String.format("http://localhost:%s", this.port);
    this.sqsClient.setEndpoint(endpoint);

    this.sqsUrl = this.sqsClient.createQueue(this.getClass().getSimpleName()).getQueueUrl();
    ((MockSQSClient)this.sqsClient).setQueueUrl(this.sqsUrl);

    this.started = true;
}
 
Example #7
Source File: TestWhiteListedBuckets.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
  this.s3Mock = new S3Mock.Builder().withPort(0).withInMemoryBackend().build();
  Http.ServerBinding binding = s3Mock.start();
  port = binding.localAddress().getPort();

  EndpointConfiguration endpoint = new EndpointConfiguration(String.format("http://localhost:%d", port), Region.US_EAST_1.toString());
  AmazonS3 client = AmazonS3ClientBuilder
    .standard()
    .withPathStyleAccessEnabled(true)
    .withEndpointConfiguration(endpoint)
    .withCredentials(new AWSStaticCredentialsProvider(new AnonymousAWSCredentials()))
    .build();

  client.createBucket("bucket-a");
  client.createBucket("bucket-b");
  client.createBucket("bucket-c");
}
 
Example #8
Source File: S3.java    From rdf-delta with Apache License 2.0 6 votes vote down vote up
public static AmazonS3 buildS3(LocalServerConfig configuration) {
    String region = configuration.getProperty(pRegion);
    String endpoint = configuration.getProperty(pEndpoint);
    String credentialsFile =  configuration.getProperty(pCredentialFile);
    String credentialsProfile =  configuration.getProperty(pCredentialProfile);

    AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard();
    if ( endpoint == null )
        builder.withRegion(region);
    else  {
        // Needed for S3mock
        builder.withPathStyleAccessEnabled(true);
        builder.withEndpointConfiguration(new EndpointConfiguration(endpoint, region));
        builder.withCredentials(new AWSStaticCredentialsProvider(new AnonymousAWSCredentials()));
    }
    if ( credentialsFile != null )
        builder.withCredentials(new ProfileCredentialsProvider(credentialsFile, credentialsProfile));
    return builder.build();
}
 
Example #9
Source File: CognitoHelper.java    From alexa-web-information-service-api-samples with MIT License 5 votes vote down vote up
/**
 * Sign up the user to the user pool
 *
 * @param username    User name for the sign up
 * @param password    Password for the sign up
 * @param email       email used to sign up
 * @param phonenumber phone number to sign up.
 * @return whether the call was successful or not.
 */
boolean SignUpUser(String username, String password, String email, String phonenumber) {
    AnonymousAWSCredentials awsCreds = new AnonymousAWSCredentials();
    AWSCognitoIdentityProvider cognitoIdentityProvider = AWSCognitoIdentityProviderClientBuilder
            .standard()
            .withCredentials(new AWSStaticCredentialsProvider(awsCreds))
            .withRegion(Regions.fromName(REGION))
            .build();

    SignUpRequest signUpRequest = new SignUpRequest();
    signUpRequest.setClientId(CLIENTAPP_ID);
    signUpRequest.setUsername(username);
    signUpRequest.setPassword(password);
    List<AttributeType> list = new ArrayList<>();

    AttributeType attributeType = new AttributeType();
    attributeType.setName("phone_number");
    attributeType.setValue(phonenumber);
    list.add(attributeType);

    AttributeType attributeType1 = new AttributeType();
    attributeType1.setName("email");
    attributeType1.setValue(email);
    list.add(attributeType1);

    signUpRequest.setUserAttributes(list);

    try {
        SignUpResult result = cognitoIdentityProvider.signUp(signUpRequest);
    } catch (Exception e) {
        System.out.println(e);
        return false;
    }
    return true;
}
 
Example #10
Source File: TestCredentialsProviderFactory.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testAnonymousCredentials() throws Throwable {
    final TestRunner runner = TestRunners.newTestRunner(MockAWSProcessor.class);
    runner.setProperty(CredentialPropertyDescriptors.USE_ANONYMOUS_CREDENTIALS, "true");
    runner.assertValid();

    Map<PropertyDescriptor, String> properties = runner.getProcessContext().getProperties();
    final CredentialsProviderFactory factory = new CredentialsProviderFactory();
    final AWSCredentialsProvider credentialsProvider = factory.getCredentialsProvider(properties);
    Assert.assertNotNull(credentialsProvider);
    final AWSCredentials creds = credentialsProvider.getCredentials();
    assertEquals("credentials should be equal", AnonymousAWSCredentials.class, creds.getClass());
}
 
Example #11
Source File: TestAWSCredentials.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testAnonymousByDefault() {
    runner.assertValid();
    runner.run(1);

    assertEquals(AnonymousAWSCredentials.class, awsCredentials.getClass());
    assertNull(awsCredentialsProvider);
}
 
Example #12
Source File: DefaultGeoWaveAWSCredentialsProvider.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public AWSCredentials getCredentials() {
  try {
    return super.getCredentials();
  } catch (final SdkClientException exception) {

  }
  // fall back to anonymous credentials
  return new AnonymousAWSCredentials();
}
 
Example #13
Source File: AwsSdkAnonymousTest.java    From s3proxy with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    TestUtils.S3ProxyLaunchInfo info = TestUtils.startS3Proxy(
            "s3proxy-anonymous.conf");
    awsCreds = new AnonymousAWSCredentials();
    context = info.getBlobStore().getContext();
    s3Proxy = info.getS3Proxy();
    s3Endpoint = info.getSecureEndpoint();
    servicePath = info.getServicePath();
    s3EndpointConfig = new EndpointConfiguration(
            s3Endpoint.toString() + servicePath, "us-east-1");
    client = AmazonS3ClientBuilder.standard()
            .withCredentials(new AWSStaticCredentialsProvider(awsCreds))
            .withEndpointConfiguration(s3EndpointConfig)
            .build();

    containerName = createRandomContainerName();
    info.getBlobStore().createContainerInLocation(null, containerName);

    blobStoreType = context.unwrap().getProviderMetadata().getId();
    if (Quirks.OPAQUE_ETAG.contains(blobStoreType)) {
        System.setProperty(
                SkipMd5CheckStrategy
                        .DISABLE_GET_OBJECT_MD5_VALIDATION_PROPERTY,
                "true");
        System.setProperty(
                SkipMd5CheckStrategy
                        .DISABLE_PUT_OBJECT_MD5_VALIDATION_PROPERTY,
                "true");
    }
}
 
Example #14
Source File: AWSUtil.java    From datacollector with Apache License 2.0 5 votes vote down vote up
public static AWSCredentialsProvider getCredentialsProvider(AWSConfig config) throws StageException {
  AWSCredentialsProvider credentialsProvider = DefaultAWSCredentialsProviderChain.getInstance();
  if (config.credentialMode == AWSCredentialMode.WITH_CREDENTIALS) {
    if (!StringUtils.isEmpty(config.awsAccessKeyId.get()) && !StringUtils.isEmpty(config.awsSecretAccessKey.get())) {
      credentialsProvider = new AWSStaticCredentialsProvider(
          new BasicAWSCredentials(config.awsAccessKeyId.get(), config.awsSecretAccessKey.get())
      );
    }
  } else if (config.credentialMode == AWSCredentialMode.WITH_ANONYMOUS_CREDENTIALS) {
    credentialsProvider = new AWSStaticCredentialsProvider(new AnonymousAWSCredentials());
  }
  return credentialsProvider;
}
 
Example #15
Source File: TerrapinUtilTest.java    From terrapin with Apache License 2.0 5 votes vote down vote up
@Test
@PrepareForTest(TerrapinUtil.class)
public void testGetS3FileList() throws Exception {
  AmazonS3Client s3Client = mock(AmazonS3Client.class);
  ObjectListing objectListing = mock(ObjectListing.class);
  S3ObjectSummary summary1 = new S3ObjectSummary();
  S3ObjectSummary summary2 = new S3ObjectSummary();
  S3ObjectSummary summary3 = new S3ObjectSummary();
  summary1.setKey("/abc/123");
  summary2.setKey("/abc/456");
  summary3.setKey("/def/123");
  summary1.setSize(32432);
  summary2.setSize(213423);
  summary3.setSize(2334);
  List<S3ObjectSummary> summaries = ImmutableList.of(summary1, summary2, summary3);
  whenNew(AmazonS3Client.class).withAnyArguments().thenReturn(s3Client);
  when(s3Client.listObjects(any(ListObjectsRequest.class))).thenReturn(objectListing);
  when(objectListing.getObjectSummaries()).thenReturn(summaries);

  List<Pair<Path, Long>> results = TerrapinUtil.getS3FileList(new AnonymousAWSCredentials(),
      "bucket", "/abc");

  assertEquals(2, results.size());
  assertTrue(results.get(0).getLeft().toString().endsWith(summary1.getKey()));
  assertEquals(new Long(summary1.getSize()), results.get(0).getRight());
  assertTrue(results.get(1).getLeft().toString().endsWith(summary2.getKey()));
  assertEquals(new Long(summary2.getSize()), results.get(1).getRight());
}
 
Example #16
Source File: S3FileSystemTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void beforeClass() {
  api = new S3Mock.Builder().withInMemoryBackend().build();
  Http.ServerBinding binding = api.start();

  EndpointConfiguration endpoint =
      new EndpointConfiguration(
          "http://localhost:" + binding.localAddress().getPort(), "us-west-2");
  client =
      AmazonS3ClientBuilder.standard()
          .withPathStyleAccessEnabled(true)
          .withEndpointConfiguration(endpoint)
          .withCredentials(new AWSStaticCredentialsProvider(new AnonymousAWSCredentials()))
          .build();
}
 
Example #17
Source File: KinesisSenderTest.java    From zipkin-aws with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
  sender =
      KinesisSender.newBuilder()
          .streamName("test")
          .endpointConfiguration(
              new EndpointConfiguration(server.url("/").toString(), "us-east-1"))
          .credentialsProvider(new AWSStaticCredentialsProvider(new AnonymousAWSCredentials()))
          .build();
}
 
Example #18
Source File: CloudwatchLogsLogEventPutter.java    From cloudwatchlogs-java-appender with Apache License 2.0 5 votes vote down vote up
static AWSLogs createLogsClient(CloudwatchLogsConfig config) {
    AWSLogsClientBuilder builder = AWSLogsClientBuilder.standard();
    if (config.getEndpoint() != null) {
        // Non-AWS mock endpoint
        builder.setCredentials(new AWSStaticCredentialsProvider(new AnonymousAWSCredentials()));
        builder.setEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(config.getEndpoint(), config.getRegion()));
    } else {
        builder.setRegion(config.getRegion());
    }
    return builder.build();
}
 
Example #19
Source File: AWSRequestSigningApacheInterceptorTest.java    From aws-request-signing-apache-interceptor with Apache License 2.0 5 votes vote down vote up
private static AWSRequestSigningApacheInterceptor createInterceptor() {
    AWSCredentialsProvider anonymousCredentialsProvider =
            new AWSStaticCredentialsProvider(new AnonymousAWSCredentials());
    return new AWSRequestSigningApacheInterceptor("servicename",
            new AddHeaderSigner("Signature", "wuzzle"),
            anonymousCredentialsProvider);

}
 
Example #20
Source File: TestCredentialsProviderFactory.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testAnonymousCredentials() throws Throwable {
    final TestRunner runner = TestRunners.newTestRunner(MockAWSProcessor.class);
    runner.setProperty(CredentialPropertyDescriptors.USE_ANONYMOUS_CREDENTIALS, "true");
    runner.assertValid();

    Map<PropertyDescriptor, String> properties = runner.getProcessContext().getProperties();
    final CredentialsProviderFactory factory = new CredentialsProviderFactory();
    final AWSCredentialsProvider credentialsProvider = factory.getCredentialsProvider(properties);
    Assert.assertNotNull(credentialsProvider);
    final AWSCredentials creds = credentialsProvider.getCredentials();
    assertEquals("credentials should be equal", AnonymousAWSCredentials.class, creds.getClass());
}
 
Example #21
Source File: TruckParkAppIntegrationTest.java    From data-highway with Apache License 2.0 5 votes vote down vote up
@Primary
@Bean
AmazonS3 testS3(@Value("${s3.port}") int port) {
  return AmazonS3Client
      .builder()
      .withCredentials(new AWSStaticCredentialsProvider(new AnonymousAWSCredentials()))
      .withEndpointConfiguration(new EndpointConfiguration("http://127.0.0.1:" + port, "us-west-2"))
      .build();
}
 
Example #22
Source File: AnonymousAWSCredentialsProvider.java    From big-c with Apache License 2.0 4 votes vote down vote up
public AWSCredentials getCredentials() {
  return new AnonymousAWSCredentials();
}
 
Example #23
Source File: AnonymousAWSCredentialsProvider.java    From hadoop with Apache License 2.0 4 votes vote down vote up
public AWSCredentials getCredentials() {
  return new AnonymousAWSCredentials();
}
 
Example #24
Source File: AnonymousAWSCredentialsProvider.java    From components with Apache License 2.0 4 votes vote down vote up
public AWSCredentials getCredentials() {
    return new AnonymousAWSCredentials();
}
 
Example #25
Source File: AnonymousAWSCredentialsProvider.java    From tajo with Apache License 2.0 4 votes vote down vote up
public AWSCredentials getCredentials() {
  return new AnonymousAWSCredentials();
}
 
Example #26
Source File: MockQueueGenerator.java    From spring-boot-aws-mock with MIT License 4 votes vote down vote up
public static AmazonSQSAsync getSqsClient(String sqsEndPoint) {
    return AmazonSQSAsyncClientBuilder.standard()
                .withCredentials(new AWSStaticCredentialsProvider(new AnonymousAWSCredentials()))
                .withEndpointConfiguration(new EndpointConfiguration(sqsEndPoint, ""))
                .build();
}
 
Example #27
Source File: AnonymousCredentialsStrategy.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public AWSCredentialsProvider getCredentialsProvider(Map<PropertyDescriptor, String> properties) {
    AnonymousAWSCredentials creds = new AnonymousAWSCredentials();
    return new StaticCredentialsProvider(creds);
}
 
Example #28
Source File: AnonymousCredentialsStrategy.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@Override
public AWSCredentialsProvider getCredentialsProvider(Map<PropertyDescriptor, String> properties) {
    AnonymousAWSCredentials creds = new AnonymousAWSCredentials();
    return new StaticCredentialsProvider(creds);
}