Moved Maven multiproject setup
This commit is contained in:
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.owasp.webgoat.application;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
|
||||
/**
|
||||
* Singleton which is created on context startup
|
||||
*
|
||||
* @author rlawson
|
||||
*/
|
||||
public class Application {
|
||||
|
||||
private static final Application INSTANCE = new Application();
|
||||
|
||||
private Application() {
|
||||
|
||||
}
|
||||
|
||||
public static final Application getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private String version = "SNAPSHOT";
|
||||
private String build = "local";
|
||||
private String name = "WebGoat";
|
||||
|
||||
/**
|
||||
* @return the version
|
||||
*/
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param version the version to set
|
||||
*/
|
||||
public void setVersion(String version) {
|
||||
if (StringUtils.isNotBlank(version)) {
|
||||
this.version = version;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the build
|
||||
*/
|
||||
public String getBuild() {
|
||||
return build;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param build the build to set
|
||||
*/
|
||||
public void setBuild(String build) {
|
||||
if (StringUtils.isNotBlank(build)) {
|
||||
this.build = build;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
if (StringUtils.isNotBlank(name)) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this).
|
||||
append("name", name).
|
||||
append("version", version).
|
||||
append("build", build).
|
||||
toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.owasp.webgoat.application;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
/**
|
||||
* Web application lifecycle listener.
|
||||
*
|
||||
* @author rlawson
|
||||
*/
|
||||
public class WebGoatServletListener implements ServletContextListener {
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce) {
|
||||
ServletContext context = sce.getServletContext();
|
||||
context.log("WebGoat is starting");
|
||||
setApplicationVariables(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent sce) {
|
||||
ServletContext context = sce.getServletContext();
|
||||
context.log("WebGoat is stopping");
|
||||
}
|
||||
|
||||
private void setApplicationVariables(ServletContext context) {
|
||||
Application app = Application.getInstance();
|
||||
try {
|
||||
InputStream inputStream = context.getResourceAsStream("/META-INF/MANIFEST.MF");
|
||||
Manifest manifest = new Manifest(inputStream);
|
||||
Attributes attr = manifest.getMainAttributes();
|
||||
String name = attr.getValue("Specification-Title");
|
||||
String version = attr.getValue("Specification-Version");
|
||||
String build = attr.getValue("Implementation-Version");
|
||||
app.setName(name);
|
||||
app.setVersion(version);
|
||||
app.setBuild(build);
|
||||
} catch (IOException ioe) {
|
||||
context.log("Error setting application variables", ioe);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user