env container

main
Ermis Wieger 2024-08-19 09:56:19 +02:00
parent 30bb161948
commit ff3db5669a
10 changed files with 137 additions and 9 deletions

View File

@ -17,7 +17,23 @@
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.8</version> <version>2.7.8</version>
</parent> </parent>
<profiles>
<profile>
<id>local</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<spring.profiles.active>local</spring.profiles.active>
</properties>
</profile>
<profile>
<id>container</id>
<properties>
<spring.profiles.active>container</spring.profiles.active>
</properties>
</profile>
</profiles>
<properties> <properties>
<java.version>11</java.version> <java.version>11</java.version>
</properties> </properties>
@ -173,5 +189,6 @@
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
</project> </project>

View File

@ -8,11 +8,16 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.session.MapSessionRepository; import org.springframework.session.MapSessionRepository;
import javax.annotation.PostConstruct;
@SpringBootApplication @SpringBootApplication
public class ApiApplication extends SpringBootServletInitializer { public class ApiApplication extends SpringBootServletInitializer {
// @org.springframework.beans.factory.annotation.Value("${greeting.message}")
// private String greetingMessage;
public static void main(String[] args) { public static void main(String[] args) {
//System.out.println(greetingMessage);
SpringApplication.run(ApiApplication.class, args); SpringApplication.run(ApiApplication.class, args);
} }
@ -36,4 +41,16 @@ public class ApiApplication extends SpringBootServletInitializer {
public MapSessionRepository sessionRepository() { public MapSessionRepository sessionRepository() {
return new MapSessionRepository(new ConcurrentHashMap<>()); return new MapSessionRepository(new ConcurrentHashMap<>());
} }
// @Bean
// public String greetingMessage() {
// return greetingMessage;
// }
// @PostConstruct
// public void printEnvValues(){
// System.out.println("Print environment values");
// System.out.println("$$$$$$$"+greetingMessage);
// }
} }

View File

@ -0,0 +1,56 @@
package com.nttdata.calender;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Value;
/**
* Java API for Remedy
*/
@Service
public class ApplicationConfig {
@Value("${rssoActive}")
private Boolean rssoActive;
public Boolean getRssoActive() {
if(rssoActive==null)
return true;
return rssoActive;
}
@Value("${arserver}")
private String arserver;
public String getArserver() {
return arserver;
}
@Value("${arport}")
private Integer arport;
public Integer getArport() {
return arport;
}
@Value("${aruser}")
private String aruser;
public String getAruser() {
return aruser;
}
@Value("${arpassword}")
private String arpassword;
public String getArpassword() {
return arpassword;
}
}

View File

@ -24,6 +24,9 @@ import com.nttdata.calender.errorhandling.ErrorTypes.NotFoundError;
import com.nttdata.calender.states.State; import com.nttdata.calender.states.State;
import com.nttdata.calender.supportgroup.SupportGroup; import com.nttdata.calender.supportgroup.SupportGroup;
import org.springframework.beans.factory.annotation.Autowired;
import com.nttdata.calender.ApplicationConfig;
/** /**
* Java API for Remedy * Java API for Remedy
*/ */
@ -35,17 +38,24 @@ public class RemedyJavaAPI {
private static Logger applicationLogger = LogManager.getLogger("application"); private static Logger applicationLogger = LogManager.getLogger("application");
// TODO: work with form CTM:Support Group // TODO: work with form CTM:Support Group
private static final String QUALSTR = "\'Request ID\' != \"\""; private static final String QUALSTR = "\'Request ID\' != \"\"";
private ApplicationConfig appConfig;
// @org.springframework.beans.factory.annotation.Value("${greeting.message}")
// private String greetingMessage;
/** /**
* Sets up the Remedy API with the server and admin user/password. * Sets up the Remedy API with the server and admin user/password.
*/ */
public RemedyJavaAPI() throws ARException, NotFoundError {
public RemedyJavaAPI(ApplicationConfig appConfig) throws ARException, NotFoundError {
this.appConfig=appConfig;
System.out.println(appConfig.getRssoActive());
server = new ARServerUser(); server = new ARServerUser();
// server.setServer("itsm-app-dev.asfinag.at"); // server.setServer("itsm-app-dev.asfinag.at");
server.setServer("itsm-app-dev-neu.asfinag.at"); server.setServer(this.appConfig.getArserver());
server.setUser("changecalender_integration"); server.setUser(this.appConfig.getAruser());
server.setPassword("VXrvLm4q#8P#MXthfZNc"); server.setPassword(this.appConfig.getArpassword());
server.setPort(46262); server.setPort(this.appConfig.getArport());
// server.setPort(50000); // server.setPort(50000);
this.connect(); this.connect();
@ -75,6 +85,10 @@ public class RemedyJavaAPI {
* @throws ARException when the user is unknown * @throws ARException when the user is unknown
*/ */
public void impersonateUser(String userName) throws ARException { public void impersonateUser(String userName) throws ARException {
if(!this.appConfig.rssoActive)
server.impersonateUser("WuiQualityKV");
server.impersonateUser(userName); server.impersonateUser(userName);
} }

View File

@ -3,6 +3,7 @@ package com.nttdata.calender.api;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.method.HandlerMethod; import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.HandlerInterceptor;
@ -27,14 +28,21 @@ import java.util.List;
@Component @Component
public class RequestInterceptor implements HandlerInterceptor { public class RequestInterceptor implements HandlerInterceptor {
// @org.springframework.beans.factory.annotation.Value("${greeting.message}")
// private String greetingMessage;
@Autowired
private RemedyJavaAPI api; private RemedyJavaAPI api;
private static final String FORM_NAME = "ASF:CHG_CAL_Transactions"; private static final String FORM_NAME = "ASF:CHG_CAL_Transactions";
private static final Logger logger = LogManager.getLogger("application"); private static final Logger logger = LogManager.getLogger("application");
private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@Override @Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
api = new RemedyJavaAPI(); //api = new RemedyJavaAPI(greetingMessage);
String currentDateTime = LocalDateTime.now().format(dateTimeFormatter); String currentDateTime = LocalDateTime.now().format(dateTimeFormatter);
long transactionId = System.currentTimeMillis(); long transactionId = System.currentTimeMillis();
String out = String.format("Transaction ID = %d %s - handling request: %s", transactionId, currentDateTime, request.getRequestURI()); String out = String.format("Transaction ID = %d %s - handling request: %s", transactionId, currentDateTime, request.getRequestURI());

View File

@ -9,6 +9,7 @@ import org.springframework.web.servlet.HandlerInterceptor;
import com.bmc.thirdparty.org.springframework.beans.factory.annotation.Autowired; import com.bmc.thirdparty.org.springframework.beans.factory.annotation.Autowired;
import com.nttdata.calender.ApplicationConfig;
/** /**
* Interceptor for handling Rsso related operations. * Interceptor for handling Rsso related operations.
*/ */
@ -17,10 +18,12 @@ public class RssoInterceptor implements HandlerInterceptor {
private final static boolean DEBUG = true; private final static boolean DEBUG = true;
private final Rsso rsso; private final Rsso rsso;
private static final Logger applicationLogger = LogManager.getLogger("application"); private static final Logger applicationLogger = LogManager.getLogger("application");
private ApplicationConfig appConfig;
@Autowired @Autowired
public RssoInterceptor(Rsso rsso) { public RssoInterceptor(Rsso rsso, ApplicationConfig appConfig) {
this.rsso = rsso; this.rsso = rsso;
this.appConfig=appConfig;
} }
/** /**
@ -39,7 +42,7 @@ public class RssoInterceptor implements HandlerInterceptor {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception { throws Exception {
// Check if a session exists, create one if not // Check if a session exists, create one if not
if (DEBUG) { if (!this.appConfig.getRssoActive()) {
return true; return true;
} }

View File

@ -0,0 +1 @@
rssoActive=true

View File

@ -0,0 +1,6 @@
rssoActive=false
arserver=itsm-app-dev-neu.asfinag.at
# arserver=${test}
arport=46262
aruser=changecalender_integration
arpassword="VXrvLm4q#8P#MXthfZNc"

View File

@ -0,0 +1,5 @@
rssoActive=false
arserver=slwien4dev
arport=2000
aruser=Demo
arpassword=ars$adm1

View File

@ -1,3 +1,4 @@
#server.servlet.context-path=/test #server.servlet.context-path=/test
server.servlet.session.timeout=24h server.servlet.session.timeout=24h
# server.port=${PROBE_PORT:8080} # server.port=${PROBE_PORT:8080}
spring.profiles.active=@spring.profiles.active@