Add Health Controller and global vars
This commit is contained in:
parent
c3c6d66d29
commit
eb3e6c82e7
2
pom.xml
2
pom.xml
|
@ -17,7 +17,7 @@
|
|||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<timestampLogincORE>${maven.build.timestamp}</timestampLogincORE>
|
||||
<timestampLoginCore>${maven.build.timestamp}</timestampLoginCore>
|
||||
<maven.build.timestamp.format>E MMM dd HH:mm:ss z yyyy</maven.build.timestamp.format>
|
||||
</properties>
|
||||
<dependencies>
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
package eu.dnetlib.authentication.configuration;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@ConfigurationProperties("api")
|
||||
public class APIProperties {
|
||||
|
||||
private String title;
|
||||
private String description;
|
||||
private String version;
|
||||
|
||||
public APIProperties() {
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
}
|
|
@ -13,15 +13,17 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties({Properties.class, APIProperties.class})
|
||||
@EnableConfigurationProperties({Properties.class, GlobalVars.class})
|
||||
@ComponentScan(basePackages = {"eu.dnetlib.authentication"})
|
||||
public class AuthenticationConfiguration {
|
||||
|
||||
private final Properties properties;
|
||||
private final GlobalVars globalVars;
|
||||
|
||||
@Autowired
|
||||
public AuthenticationConfiguration(Properties properties) {
|
||||
public AuthenticationConfiguration(Properties properties, GlobalVars globalVars) {
|
||||
this.properties = properties;
|
||||
this.globalVars = globalVars;
|
||||
}
|
||||
|
||||
public Map<String, String> getProperties() {
|
||||
|
@ -40,6 +42,15 @@ public class AuthenticationConfiguration {
|
|||
map.put("authentication.accessToken", properties.getAccessToken());
|
||||
map.put("authentication.redirect", properties.getRedirect());
|
||||
map.put("authentication.authorities-mapper", properties.getAuthoritiesMapper());
|
||||
if(GlobalVars.date != null) {
|
||||
map.put("Date of deploy", GlobalVars.date.toString());
|
||||
}
|
||||
if(globalVars.getBuildDate() != null) {
|
||||
map.put("Date of build", globalVars.getBuildDate());
|
||||
}
|
||||
if (globalVars.getVersion() != null) {
|
||||
map.put("Version", globalVars.getVersion());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package eu.dnetlib.authentication.configuration;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ConfigurationProperties("authentication.global-vars")
|
||||
public class GlobalVars {
|
||||
public static Date date = new Date();
|
||||
private Date buildDate;
|
||||
private String version;
|
||||
|
||||
public String getBuildDate() {
|
||||
if(buildDate == null) {
|
||||
return null;
|
||||
}
|
||||
return buildDate.toString();
|
||||
}
|
||||
|
||||
public void setBuildDate(Date buildDate) {
|
||||
this.buildDate = buildDate;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package eu.dnetlib.authentication.controllers;
|
||||
|
||||
import eu.dnetlib.authentication.configuration.AuthenticationConfiguration;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController(value = "/login-core/")
|
||||
public class HealthController {
|
||||
private final Logger log = LogManager.getLogger(this.getClass());
|
||||
private final AuthenticationConfiguration configuration;
|
||||
|
||||
@Autowired
|
||||
public HealthController(AuthenticationConfiguration configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
@RequestMapping(value = {"", "/health_check"}, method = RequestMethod.GET)
|
||||
public String hello() {
|
||||
log.debug("Hello from Login Core");
|
||||
return "Hello from Login Core!";
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAnyAuthority('PORTAL_ADMINISTRATOR')")
|
||||
@RequestMapping(value = "/health_check/advanced", method = RequestMethod.GET)
|
||||
public Map<String, String> checkEverything() {
|
||||
Map<String, String> response = configuration.getProperties();
|
||||
return response;
|
||||
}
|
||||
}
|
|
@ -14,3 +14,6 @@ authentication.accessToken=AccessToken
|
|||
authentication.redirect=http://mpagasas.di.uoa.gr:4600/reload
|
||||
|
||||
#authentication.authorities-mapper=eduperson_entitlement
|
||||
|
||||
authentication.global-vars.buildDate=@timestampLoginCore@
|
||||
authentication.global-vars.version=@project.version@
|
||||
|
|
Loading…
Reference in New Issue