Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

changes for mpjwt to support system properties.. OpenLiberty #395

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,13 @@ public Properties getDatasourceProperties() {

// Verify correct property configuration
if (dependency.contains(DERBY_GROUP_ID)) {
// If there's no DB name and there's no server name then we can create an embedded DB at a default location
if ((!datasourceProperties.containsKey(BoostProperties.DATASOURCE_DATABASE_NAME)) &&
(!datasourceProperties.containsKey(BoostProperties.DATASOURCE_SERVER_NAME))) {
// If there's no DB name and there's no server name then we can create an
// embedded DB at a default location
if ((!datasourceProperties.containsKey(BoostProperties.DATASOURCE_DATABASE_NAME))
&& (!datasourceProperties.containsKey(BoostProperties.DATASOURCE_SERVER_NAME))) {
datasourceProperties.put(BoostProperties.DATASOURCE_DATABASE_NAME, DERBY_DB);
// Though we want to auto-create our default location DB, I guess if someone already specified a property will honor it
// Though we want to auto-create our default location DB, I guess if someone
// already specified a property will honor it
// even though not sure how useful that would be.
if (!datasourceProperties.containsKey(BoostProperties.DATASOURCE_CREATE_DATABASE)) {
datasourceProperties.put(BoostProperties.DATASOURCE_CREATE_DATABASE, "create");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import java.util.Properties;
import org.microshed.boost.common.BoostException;
import org.microshed.boost.common.BoostLoggerI;
import org.microshed.boost.common.boosters.AbstractBoosterConfig.BoosterCoordinates;
Expand All @@ -22,12 +22,35 @@
@BoosterCoordinates(AbstractBoosterConfig.BOOSTERS_GROUP_ID + ":mp-jwt")
public class MPJWTBoosterConfig extends AbstractBoosterConfig {

protected Properties boostMPProperties;
// assuming properties will be configured with underscore
private final static String JWT_ISSUER = "mp_jwt_verify_issuer";
private final static String JWT_PUBLIC_KEY = "mp_jwt_verify_publickey";
private final static String JWT_PUBLIC_KEY_LOCATION = "mp_jwt_verify_publickey_location";

public MPJWTBoosterConfig(BoosterConfigParams params, BoostLoggerI logger) throws BoostException {
super(params.getProjectDependencies().get(getCoordinates(MPJWTBoosterConfig.class)));

boostMPProperties = new Properties();
Properties inputProp = params.getBoostProperties();
String issuer = inputProp.getProperty(JWT_ISSUER);
String publicKey = inputProp.getProperty(JWT_PUBLIC_KEY);
String publicKeyLoc = inputProp.getProperty(JWT_PUBLIC_KEY_LOCATION);
logger.info("Issuer = " + issuer);
logger.info("public key = " + publicKey);
logger.info("public key loc = " + publicKeyLoc);
if (issuer != null)
boostMPProperties.setProperty(JWT_ISSUER, issuer);
if (publicKey != null)
boostMPProperties.setProperty(JWT_PUBLIC_KEY, publicKey);
else if (publicKeyLoc != null)
boostMPProperties.setProperty(JWT_PUBLIC_KEY_LOCATION, publicKeyLoc);

}

@Override
public List<String> getDependencies() {
return new ArrayList<String>();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public final class BoostProperties {

// Boost specific
public static final String BOOST_PROP_PREFIX = "boost_";
public static final String BOOST_PROP_MP_PREFIX = "mp_";

// HTTP Endpoint properties
public static final String ENDPOINT_HOST = "boost_http_host";
Expand Down Expand Up @@ -64,10 +65,8 @@ public static Properties getConfiguredBoostProperties(Properties projectProperti
// system properties (set at command line)
for (Map.Entry<Object, Object> entry : projectProperties.entrySet()) {

if (entry.getKey().toString().startsWith(BOOST_PROP_PREFIX)) {

// logger.debug("Found boost property: " +
// entry.getKey() + ":" + entry.getValue());
if (entry.getKey().toString().startsWith(BOOST_PROP_PREFIX)
|| entry.getKey().toString().startsWith(BOOST_PROP_MP_PREFIX)) {

boostProperties.put(entry.getKey(), entry.getValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@

public class BoosterConfigParams {

Map<String, String> projectDependencies;
Map<String, String> projectDependencies;
Properties boostProperties;

public BoosterConfigParams(Map<String, String> projectDependencies, Properties boostProperties) {
this.projectDependencies = projectDependencies;
this.boostProperties = boostProperties;
this.projectDependencies = projectDependencies;
this.boostProperties = boostProperties;
}

public Map<String, String> getProjectDependencies() {
return this.projectDependencies;
}

public Properties getBoostProperties() {
return this.boostProperties;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
import org.microshed.boost.common.BoostException;

public abstract interface RuntimeI {

public void doPackage() throws BoostException;

public void doDebug(boolean clean) throws BoostException;

public void doRun(boolean clean) throws BoostException;

public void doStart(boolean clean, int verifyTimeout, int serverStartTimeout) throws BoostException;

public void doStop() throws BoostException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void checkPropertiesTest() throws Exception {

// AES hashed password changes so we're just going to look for the
// aes flag.

assertTrue("Incorrect boost_db_password found in generated config", LibertyConfigFileUtils
.findVariableInXml(variablesXml, DATASOURCE_PASSWORD).contains(AES_HASHED_PASSWORD_FLAG));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,22 @@

public class LibertyConfigFileUtils {

public static String findVariableInXml(String variablesXmlPath, String variableName)
throws Exception {
public static String findVariableInXml(String variablesXmlPath, String variableName) throws Exception {

String variableValue = null;

File variablesXml = new File(variablesXmlPath);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(variablesXml);

Element serverRoot = doc.getDocumentElement();

List<Element> variablesList = getDirectChildrenByTag(serverRoot, "variable");
for (Element variable : variablesList) {
if (variableName.equals(variable.getAttribute("name"))) {
variableValue = variable.getAttribute("defaultValue");
}
if (variableName.equals(variable.getAttribute("name"))) {
variableValue = variable.getAttribute("defaultValue");
}
}

return variableValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ public void handleProcessingException(ProcessingException ex) {
* - port number.
* @param path
* - Note that the path needs to start with a slash!!!
* @return String representation of the URI to the system properties
* service.
* @return String representation of the URI to the system properties service.
*/
// end::doc[]
public static String buildUrl(String protocol, String host, int port, String path) {
Expand Down
Loading