Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set java system property of AKSK porperly with springboot #100

Open
xpdable opened this issue Jan 20, 2023 · 2 comments
Open

How to set java system property of AKSK porperly with springboot #100

xpdable opened this issue Jan 20, 2023 · 2 comments

Comments

@xpdable
Copy link

xpdable commented Jan 20, 2023

I used to set env before my spingboot starts, and everything is fine.
Now I need to decrypt AKSK when the application starts, therefore I tried to set java system property in the event listener as below, but it seems does not work for the kafka client.
Does anyone have any sample of working with springboot?

public class AfterConfigListener implements SmartApplicationListener, Ordered {

    @Override
    public boolean supportsEventType(Class<? extends ApplicationEvent> aClass) {
        return (ApplicationEnvironmentPreparedEvent.class.isAssignableFrom(aClass)) ||
                ApplicationPreparedEvent.class.isAssignableFrom(aClass) ||
                ApplicationStartingEvent.class.isAssignableFrom(aClass);
    }

    @Override
    public void onApplicationEvent(ApplicationEvent applicationEvent) {
        if (applicationEvent instanceof ApplicationStartingEvent){
            System.setProperty("aws.accessKeyId","asfd");
            System.setProperty("aws.secretAccessKey","asdf/abcdefg");
        }
    }

    @Override
    public int getOrder(){
        return(ConfigFileApplicationListener.DEFAULT_ORDER + 1);
    }

}

application.yml:

spring:
  application:
    name: aws-msk-producer-demo
  kafka:
    listener:
      type: batch
    producer:
      ...
    properties:
      security.protocol: SASL_SSL
      sasl:
        mechanism: AWS_MSK_IAM
        jaas.config: software.amazon.msk.auth.iam.IAMLoginModule required;
        client.callback.handler.class: software.amazon.msk.auth.iam.IAMClientCallbackHandler

build.gradle:

plugins {
	id 'org.springframework.boot' version '2.7.2'
	id 'io.spring.dependency-management' version '1.0.12.RELEASE'
	id 'java'
}

version = '0.0.1'
sourceCompatibility = '11'

repositories {
	mavenCentral()
}

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter'
	implementation 'org.springframework.kafka:spring-kafka'
	implementation group: 'org.apache.kafka', name: 'kafka-clients', version: '3.2.0'
	implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.13.3'
	implementation group: 'software.amazon.msk', name: 'aws-msk-iam-auth', version: '1.1.4'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
	testImplementation 'org.springframework.kafka:spring-kafka-test'
}
@serhiikartashov
Copy link

+1

Copy link

We have noticed this issue has not received attention in 1 year. We will close this issue for now. If you think this is in error, please feel free to comment and reopen the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants