Merged PR 21421: env-fix-backend

main
ermis.wieger 2024-08-20 10:37:57 +00:00
commit 95ae2e46af
12 changed files with 125 additions and 14 deletions

View File

@ -17,7 +17,23 @@
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.8</version>
</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>
<java.version>11</java.version>
</properties>
@ -173,5 +189,6 @@
</plugin>
</plugins>
</build>
</project>

View File

@ -8,10 +8,14 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.session.MapSessionRepository;
import javax.annotation.PostConstruct;
@SpringBootApplication
public class ApiApplication extends SpringBootServletInitializer {
// @org.springframework.beans.factory.annotation.Value("${greeting.message}")
// private String greetingMessage;
public static void main(String[] args) {
SpringApplication.run(ApiApplication.class, args);
}

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(this.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.supportgroup.SupportGroup;
import org.springframework.beans.factory.annotation.Autowired;
import com.nttdata.calender.ApplicationConfig;
/**
* Java API for Remedy
*/
@ -35,17 +38,24 @@ public class RemedyJavaAPI {
private static Logger applicationLogger = LogManager.getLogger("application");
// TODO: work with form CTM:Support Group
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.
*/
public RemedyJavaAPI() throws ARException, NotFoundError {
public RemedyJavaAPI(ApplicationConfig appConfig) throws ARException, NotFoundError {
this.appConfig=appConfig;
System.out.println(appConfig.getRssoActive());
server = new ARServerUser();
// server.setServer("itsm-app-dev.asfinag.at");
server.setServer("itsm-app-dev-neu.asfinag.at");
server.setUser("changecalender_integration");
server.setPassword("VXrvLm4q#8P#MXthfZNc");
server.setPort(46262);
server.setServer(this.appConfig.getArserver());
server.setUser(this.appConfig.getAruser());
server.setPassword(this.appConfig.getArpassword());
server.setPort(this.appConfig.getArport());
// server.setPort(50000);
this.connect();

View File

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

View File

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

View File

@ -49,8 +49,8 @@ public class Approval {
public String update(ApprovalUpdateRequest request) throws ARException {
// Clear the list before processing a new request
listOfFieldValues.clear();
remedyJavaAPI.impersonateUser("WuiQualityKV");
//remedyJavaAPI.impersonateUser("WuiQualityKV");
String action = "APPROVAL";
var queryUpdate = new Query.QueryBuilder("ASF:CHG_CAL_Interactions")

View File

@ -58,7 +58,7 @@ public class Presets {
this.presets = new ArrayList<>();
this.listOfFieldValues = new ArrayList<>();
api.impersonateUser("WuiQualityKV");
//api.impersonateUser("WuiQualityKV");
}
/**

View File

@ -51,7 +51,7 @@ public class SupportGroup {
*/
public void querySupportGroups(RemedyJavaAPI api) throws ARException, NotFoundError {
api.impersonateUser("WuiQualityKV");
//api.impersonateUser("WuiQualityKV");
applicationLogger.info("\n\n\nRequest: querySupportGroups (Initial)\nUser: " + api.getUser() + "\nAdmin? "
+ (api.isAdministrator() ? "Yes" : "No"));
@ -112,7 +112,7 @@ public class SupportGroup {
* @throws ARException if an error occurs during the query
*/
public void queryUserSupportGroup(RemedyJavaAPI api) throws ARException {
api.impersonateUser("WuiQualityKV");
//api.impersonateUser("WuiQualityKV");
var querySupportGroups = new Query.QueryBuilder("CTM:Support Group Association")
.addFieldId("SupportGroupId", 1000000079).build();

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

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