import org.springframework.web.client.RestTemplate;
@SpringBootApplication
-@ComponentScan(basePackages = {"org.onap.so.adapters.cnf"})
+@ComponentScan(basePackages = {"org.onap.so.adapters.cnf", "org.onap.so.security"})
@EnableAutoConfiguration(exclude = {LiquibaseAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class,
SecurityAutoConfiguration.class})
package org.onap.so.adapters.cnf.client;
import com.google.gson.Gson;
-import org.onap.so.adapters.cnf.BpmnInfraConfiguration;
+import org.onap.so.security.SoUserCredentialConfiguration;
+import org.onap.so.security.UserCredentials;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
private final static Gson gson = new Gson();
private final RestTemplate restTemplate;
- private final BpmnInfraConfiguration bpmnInfraConfiguration;
+ private final SoUserCredentialConfiguration userCredentialConfiguration;
+ private final String role = "ACTUATOR";
+ private final UserCredentials credentials;
@Autowired
- public SoCallbackClient(RestTemplate restTemplate, BpmnInfraConfiguration bpmnInfraConfiguration) {
+ public SoCallbackClient(RestTemplate restTemplate, SoUserCredentialConfiguration userCredentialConfiguration) {
this.restTemplate = restTemplate;
- this.bpmnInfraConfiguration = bpmnInfraConfiguration;
+ this.userCredentialConfiguration = userCredentialConfiguration;
+ if (!userCredentialConfiguration.getRoles().contains(role))
+ throw new RuntimeException("Missing authentication role: " + role);
+ credentials = userCredentialConfiguration.getUsercredentials().stream().filter(
+ creds -> role.equals(creds.getRole())).findAny().orElse(null);
}
public ResponseEntity<String> sendPostCallback(String url, Object body) {
acceptableMediaTypes.add(MediaType.APPLICATION_JSON);
headers.setAccept(acceptableMediaTypes);
headers.setContentType(MediaType.APPLICATION_JSON);
- headers.add(HttpHeaders.AUTHORIZATION, bpmnInfraConfiguration.getAuth());
+ headers.setBasicAuth(credentials.getUsername(), credentials.getPassword());
return new HttpEntity<>(gson.toJson(body), headers);
}
#logging:
# path: logs
-#spring:
-# datasource:
- # driver-class-name: org.mariadb.jdbc.Driver
-# jdbcUrl: jdbc:mariadb://192.168.235.44:30444/requestdb
- # username: root
- # password: secretpassword
+spring:
+ security:
+ usercredentials:
+ - username: ${ACTUATOR_USERNAME}
+ password: ${ACTUATOR_PASSWORD}
+ role: ACTUATOR
# jpa:
# show-sql: false
#management:
# security:
# enabled: false
- # basic:
-mso:
- adapters:
- requestDb:
- auth:
-# enabled: false
\ No newline at end of file
+ # basic:
\ No newline at end of file