diff --git a/pom.xml b/pom.xml index 3921015a8..27833900f 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ io.mosip mimoto - 0.2.0-SNAPSHOT + 1.2.0-SNAPSHOT mimoto Mobile server backend supporting Inji. @@ -529,14 +529,14 @@ true - ${project.build.outputDirectory}/build.json + ${project.build.outputDirectory}/git.properties - ^git.build.(time|version)$ + ^git.build.(time|version|host)$ + ^git.(branch|tags)$ ^git.commit.id.(abbrev|full)$ ^git.branch$ full - json diff --git a/src/main/java/io/mosip/mimoto/MimotoServiceApplication.java b/src/main/java/io/mosip/mimoto/MimotoServiceApplication.java index b89cf5fa0..425fa2d63 100644 --- a/src/main/java/io/mosip/mimoto/MimotoServiceApplication.java +++ b/src/main/java/io/mosip/mimoto/MimotoServiceApplication.java @@ -1,8 +1,5 @@ package io.mosip.mimoto; -import com.fasterxml.jackson.databind.ObjectMapper; - -import org.json.simple.JSONObject; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration; @@ -44,27 +41,7 @@ public ThreadPoolTaskScheduler taskScheduler() { return threadPoolTaskScheduler; } - public static JSONObject getGitProp() { - try { - return (new ObjectMapper()).readValue( - MimotoServiceApplication.class.getClassLoader().getResourceAsStream("build.json"), - JSONObject.class - ); - } catch (Exception e) { - System.err.println("Error when trying to read build.json file: " + e); - } - return new JSONObject(); - } - public static void main(String[] args) { - JSONObject gitProp = getGitProp(); - System.out.println( - String.format( - "Mimoto Service version: %s - revision: %s @ branch: %s | build @ %s", - gitProp.get("git.build.version"), - gitProp.get("git.commit.id.abbrev"), - gitProp.get("git.branch"), - gitProp.get("git.build.time"))); SpringApplication.run(MimotoServiceApplication.class, args); } diff --git a/src/main/java/io/mosip/mimoto/config/Config.java b/src/main/java/io/mosip/mimoto/config/Config.java index 51be07df1..7f59224ae 100644 --- a/src/main/java/io/mosip/mimoto/config/Config.java +++ b/src/main/java/io/mosip/mimoto/config/Config.java @@ -41,14 +41,7 @@ protected void configure(HttpSecurity http) throws Exception { if (!isCSRFEnable) { http = http.csrf().disable(); } - // http.authorizeRequests().antMatchers("*").authenticated().and().exceptionHandling() - // .authenticationEntryPoint(new AuthEntryPoint()).and().sessionManagement() - // .sessionCreationPolicy(SessionCreationPolicy.STATELESS); - // http.addFilterBefore(authFilter(), - // UsernamePasswordAuthenticationFilter.class); - - // FIXME: web security is disabled for all enpoints http.authorizeRequests().antMatchers("*").authenticated().anyRequest().permitAll().and().exceptionHandling(); if (isCORSEnable) { http.addFilterBefore(new CorsFilter(origins), AuthFilter.class); diff --git a/src/main/java/io/mosip/mimoto/controller/AttestationServiceController.java b/src/main/java/io/mosip/mimoto/controller/AttestationServiceController.java index ca4a52afb..cec9cdff6 100644 --- a/src/main/java/io/mosip/mimoto/controller/AttestationServiceController.java +++ b/src/main/java/io/mosip/mimoto/controller/AttestationServiceController.java @@ -1,7 +1,6 @@ package io.mosip.mimoto.controller; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -17,7 +16,6 @@ import io.mosip.mimoto.util.AttestationOnlineVerify; import io.mosip.mimoto.util.LoggerUtil; -@SpringBootApplication @RestController @RequestMapping(value = "/safetynet") public class AttestationServiceController { diff --git a/src/main/java/io/mosip/mimoto/controller/CredentialShareController.java b/src/main/java/io/mosip/mimoto/controller/CredentialShareController.java index aa2d9677a..b1c1fd326 100644 --- a/src/main/java/io/mosip/mimoto/controller/CredentialShareController.java +++ b/src/main/java/io/mosip/mimoto/controller/CredentialShareController.java @@ -82,7 +82,7 @@ public class CredentialShareController { * @throws Exception */ @PostMapping(path = "/callback/notify", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - @PreAuthenticateContentAndVerifyIntent(secret = "${mosip.event.secret}", callback = "/v1/mimoto/credentialshare/callback/notify", topic = "${mosip.event.topic}") + @PreAuthenticateContentAndVerifyIntent(secret = "${mosip.event.secret}", callback = "/credentialshare/callback/notify", topic = "${mosip.event.topic}") public ResponseEntity handleSubscribeEvent(@RequestBody EventModel eventModel) throws Exception { logger.info("Received websub event:: transaction id = " + eventModel.getEvent().getTransactionId()); diff --git a/src/main/java/io/mosip/mimoto/controller/MimotoServiceController.java b/src/main/java/io/mosip/mimoto/controller/MimotoServiceController.java new file mode 100644 index 000000000..f8591866c --- /dev/null +++ b/src/main/java/io/mosip/mimoto/controller/MimotoServiceController.java @@ -0,0 +1,24 @@ +package io.mosip.mimoto.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import io.mosip.mimoto.util.VersionInfo; + +@RestController +public class MimotoServiceController { + @Autowired + VersionInfo versionInfo; + + /** + * Return build properties with git revision and version information. + * + * @return + */ + @GetMapping("/info") + public ResponseEntity info() { + return ResponseEntity.ok().body(versionInfo.getVersionInfo()); + } +} diff --git a/src/main/java/io/mosip/mimoto/controller/ResidentServiceController.java b/src/main/java/io/mosip/mimoto/controller/ResidentServiceController.java index 19d727c82..3d2e04bbd 100644 --- a/src/main/java/io/mosip/mimoto/controller/ResidentServiceController.java +++ b/src/main/java/io/mosip/mimoto/controller/ResidentServiceController.java @@ -1,7 +1,6 @@ package io.mosip.mimoto.controller; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.core.env.Environment; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -27,7 +26,6 @@ import io.mosip.mimoto.util.DateUtils; import io.mosip.mimoto.util.LoggerUtil; -@SpringBootApplication @RestController public class ResidentServiceController { diff --git a/src/main/java/io/mosip/mimoto/util/VersionInfo.java b/src/main/java/io/mosip/mimoto/util/VersionInfo.java new file mode 100644 index 000000000..31852cf17 --- /dev/null +++ b/src/main/java/io/mosip/mimoto/util/VersionInfo.java @@ -0,0 +1,89 @@ +package io.mosip.mimoto.util; + +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +import javax.annotation.PostConstruct; + +import org.jboss.jandex.Main; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.info.BuildProperties; +import org.springframework.stereotype.Component; + +@Component +public class VersionInfo { + @Autowired + private BuildProperties buildProperties; + + @Value("${mosipbox.public.url}") + private String mosipHost; + + @Value("${mosip.event.hubUrl}") + private String websubUrl; + + private Properties gitProperties = new Properties(); + + public final String[] DEFAULT_GIT_PROPERTIES = { + "git.build.time", + "git.branch", + "git.tags", + "git.commit.id.abbrev", + }; + + @PostConstruct + public void initialize() { + try { + gitProperties.load(Main.class.getResourceAsStream("/git.properties"));; + + } catch (Exception e) { + System.err.println("Error when trying to read git.properties file: " + e); + } + System.out.println("=".repeat(160)); + System.out.println(getBuildString()); + System.out.println(getServiceString()); + System.out.println("=".repeat(160)); + } + + public Map getVersionInfo() { + Map versionInfo = new HashMap(); + + Map appInfo = new HashMap(); + appInfo.put("name", buildProperties.getName()); + appInfo.put("version", buildProperties.getVersion()); + versionInfo.put("application", appInfo); + + Map buildInfo = new HashMap(); + for (String prop : DEFAULT_GIT_PROPERTIES) { + buildInfo.put(prop, gitProperties.getProperty(prop)); + } + versionInfo.put("build", buildInfo); + + Map configInfo = new HashMap(); + configInfo.put("mosip.host", mosipHost); + configInfo.put("websub.url", websubUrl); + versionInfo.put("config", configInfo); + + return versionInfo; + } + + public String getBuildString() { + return String.format( + "%s build [version=%s, time=%s] | commit: %s @ branch: %s", + buildProperties.getName(), + buildProperties.getVersion(), + buildProperties.getTime(), + gitProperties.getProperty("git.commit.id.abbrev"), + gitProperties.getProperty("git.branch") + ); + } + + public String getServiceString() { + return String.format( + "MOSIP Host: %s | Websub URL: %s", + mosipHost, + websubUrl + ); + } +}