forked from apereo/cas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
streamline banner settings and include them in info endpoint
- Loading branch information
1 parent
7838806
commit a4bbf02
Showing
11 changed files
with
196 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
core/cas-server-core-util-api/src/main/java/org/apereo/cas/util/SystemUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package org.apereo.cas.util; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.vdurmont.semver4j.Semver; | ||
import org.apache.commons.io.FileUtils; | ||
import org.apache.commons.lang3.BooleanUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.boot.SpringBootVersion; | ||
import org.springframework.core.SpringVersion; | ||
|
||
import java.net.URL; | ||
import java.time.LocalDateTime; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
|
||
/** | ||
* This is {@link SystemUtils}. | ||
* | ||
* @author Misagh Moayyed | ||
* @since 5.3.0 | ||
*/ | ||
public final class SystemUtils { | ||
private static final ObjectMapper MAPPER = new ObjectMapper().findAndRegisterModules(); | ||
|
||
private static final String UPDATE_CHECK_MAVEN_URL = "https://search.maven.org/solrsearch/select?q=g:%22org.apereo.cas%22%20AND%20a:%22cas-server%22"; | ||
|
||
private SystemUtils() { | ||
} | ||
|
||
/** | ||
* Gets system info. | ||
* | ||
* @return the system info | ||
*/ | ||
public static Map<String, Object> getSystemInfo() { | ||
final Properties properties = System.getProperties(); | ||
|
||
final Map<String, Object> info = new LinkedHashMap<>(); | ||
info.put("CAS Version", StringUtils.defaultString(CasVersion.getVersion(), "Not Available")); | ||
info.put("CAS Commit Id", StringUtils.defaultString(CasVersion.getSpecificationVersion(), "Not Available")); | ||
info.put("CAS Build Date/Time", CasVersion.getDateTime()); | ||
info.put("Spring Boot Version", SpringBootVersion.getVersion()); | ||
info.put("Spring Version", SpringVersion.getVersion()); | ||
|
||
info.put("Java Home", properties.get("java.home")); | ||
info.put("Java Vendor", properties.get("java.vendor")); | ||
info.put("Java Version", properties.get("java.version")); | ||
|
||
final Runtime runtime = Runtime.getRuntime(); | ||
info.put("JVM Free Memory", FileUtils.byteCountToDisplaySize(runtime.freeMemory())); | ||
info.put("JVM Maximum Memory", FileUtils.byteCountToDisplaySize(runtime.maxMemory())); | ||
info.put("JVM Total Memory", FileUtils.byteCountToDisplaySize(runtime.totalMemory())); | ||
|
||
info.put("JCE Installed", StringUtils.capitalize(BooleanUtils.toStringYesNo(EncodingUtils.isJceInstalled()))); | ||
info.put("OS Architecture", properties.get("os.arch")); | ||
info.put("OS Name", properties.get("os.name")); | ||
info.put("OS Version", properties.get("os.version")); | ||
info.put("OS Date/Time", LocalDateTime.now()); | ||
info.put("OS Temp Directory", FileUtils.getTempDirectoryPath()); | ||
|
||
injectUpdateInfoIntoBannerIfNeeded(info); | ||
|
||
return info; | ||
} | ||
|
||
private static void injectUpdateInfoIntoBannerIfNeeded(final Map<String, Object> info) { | ||
try { | ||
final Properties properties = System.getProperties(); | ||
if (!properties.containsKey("CAS_UPDATE_CHECK_ENABLED")) { | ||
return; | ||
} | ||
|
||
final URL url = new URL(UPDATE_CHECK_MAVEN_URL); | ||
final Map results = MAPPER.readValue(url, Map.class); | ||
if (!results.containsKey("response")) { | ||
return; | ||
} | ||
final Map response = (Map) results.get("response"); | ||
if (!response.containsKey("numFound") && (int) response.get("numFound") != 1) { | ||
return; | ||
} | ||
|
||
final List docs = (List) response.get("docs"); | ||
if (docs.isEmpty()) { | ||
return; | ||
} | ||
|
||
final Map entry = (Map) docs.get(0); | ||
final String latestVersion = (String) entry.get("latestVersion"); | ||
if (StringUtils.isNotBlank(latestVersion)) { | ||
final String currentVersion = CasVersion.getVersion(); | ||
final Semver latestSem = new Semver(latestVersion); | ||
final Semver currentSem = new Semver(currentVersion); | ||
|
||
if (currentSem.isLowerThan(latestSem)) { | ||
final String updateString = String.format("[Latest Version: %s / Stable: %s]", latestVersion, | ||
StringUtils.capitalize(BooleanUtils.toStringYesNo(latestSem.isStable()))); | ||
info.put("Update Availability", updateString); | ||
} | ||
} | ||
|
||
} catch (final Exception e) { | ||
throw new RuntimeException(e.getMessage(), e); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...r-support-reports/src/main/java/org/apereo/cas/web/report/CasInfoEndpointContributor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.apereo.cas.web.report; | ||
|
||
import org.apereo.cas.util.SystemUtils; | ||
import org.springframework.boot.actuate.info.Info; | ||
import org.springframework.boot.actuate.info.InfoContributor; | ||
|
||
/** | ||
* This is {@link CasInfoEndpointContributor}. | ||
* | ||
* @author Misagh Moayyed | ||
* @since 5.3.0 | ||
*/ | ||
public class CasInfoEndpointContributor implements InfoContributor { | ||
@Override | ||
public void contribute(final Info.Builder builder) { | ||
builder.withDetails(SystemUtils.getSystemInfo()); | ||
} | ||
} |
Oops, something went wrong.