Skip to content

Commit

Permalink
feat: Add pfx name
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenzo-ingenito committed Dec 11, 2024
1 parent fe50df6 commit e2d5ef8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public Map<String, Object> consumerConfigs() {
props.put("sasl.login.callback.handler.class", CustomAuthenticateCallbackHandler.class);
props.put("kafka.oauth.tenantId", kafkaPropsCfg.getTenantId());
props.put("kafka.oauth.appId", kafkaPropsCfg.getAppId());
props.put("kafka.oauth.pfxName", kafkaPropsCfg.getPfxName());
props.put("kafka.oauth.pwd", kafkaPropsCfg.getPwd());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public Map<String, Object> producerWithoutTransactionConfigs() {
props.put("sasl.login.callback.handler.class", CustomAuthenticateCallbackHandler.class);
props.put("kafka.oauth.tenantId", kafkaPropCFG.getTenantId());
props.put("kafka.oauth.appId", kafkaPropCFG.getAppId());
props.put("kafka.oauth.pfxName", kafkaPropCFG.getPfxName());
props.put("kafka.oauth.pwd", kafkaPropCFG.getPwd());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class KafkaPropertiesCFG {

@Value("${kafka.oauth.appId}")
private String appId;

@Value("${kafka.oauth.pfxName}")
private String pfxName;

@Value("${kafka.oauth.pwd}")
private String pwd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.microsoft.aad.msal4j.IAuthenticationResult;
import com.microsoft.aad.msal4j.IClientCredential;

import it.finanze.sanita.fse2.ms.gtw.statusmanager.exceptions.BusinessException;
import it.finanze.sanita.fse2.ms.gtw.statusmanager.utility.FileUtility;
import lombok.extern.slf4j.Slf4j;

Expand All @@ -39,8 +40,10 @@ public class CustomAuthenticateCallbackHandler implements AuthenticateCallbackHa

private String tenantId;

private String clientId;
private String appId;

private String pfxName;

private String pwd;

private ConfidentialClientApplication aadClient;
Expand All @@ -57,7 +60,8 @@ public void configure(Map<String, ?> configs, String mechanism, List<AppConfigur
ClientCredentialParameters.builder(Collections.singleton(sbUri + "/.default"))
.build();
this.tenantId = "https://login.microsoftonline.com/"+ Arrays.asList(configs.get("kafka.oauth.tenantId")).get(0).toString();
this.clientId = Arrays.asList(configs.get("kafka.oauth.appId")).get(0).toString();
this.appId = Arrays.asList(configs.get("kafka.oauth.appId")).get(0).toString();
this.pfxName = Arrays.asList(configs.get("kafka.oauth.pfxName")).get(0).toString();
this.pwd = Arrays.asList(configs.get("kafka.oauth.pwd")).get(0).toString();

}
Expand All @@ -84,12 +88,13 @@ private OAuthBearerToken getOAuthBearerToken() throws MalformedURLException, Int
if (this.aadClient == null) {
IClientCredential credential = null;
try{
InputStream certificato = new ByteArrayInputStream(FileUtility.getFileFromInternalResources("client_FSD-SA-0005.pfx"));
InputStream certificato = new ByteArrayInputStream(FileUtility.getFileFromInternalResources(pfxName));
credential = ClientCredentialFactory.createFromCertificate(certificato, this.pwd);
}catch(Exception ex) {
System.out.println("Stop");
} catch(Exception ex) {
log.error("Error while try to crate credential from certificate");
throw new BusinessException(ex);
}
this.aadClient = ConfidentialClientApplication.builder(this.clientId, credential)
this.aadClient = ConfidentialClientApplication.builder(this.appId, credential)
.authority(this.tenantId)
.build();
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ kafka.statusmanager.topic=MDS-SA-0004_FU_001_STATUS
kafka.statusmanager.eds.topic=MDS-SA-0004_FU_002_STATUS
kafka.oauth.tenantId=${TENANT_ID}
kafka.oauth.appId=${APP_ID}
kafka.oauth.pfxName=${PFX_NAME_RESOURCE_PATH}
kafka.oauth.pwd=${PWD}
####### KAFKA DEAD LETTER #####################
kafka.statusmanager.deadletter.topic=MDS-SA-0004_FU_001_STATUS-DLT
Expand Down

0 comments on commit e2d5ef8

Please sign in to comment.