Permalink
Browse files

Fixed some auth related issues found while testing the distro.

  • Loading branch information...
1 parent 07a1c7b commit ce1796ff74d71eec0faf87c48f6803a13e6fcc17 @EricWittmann EricWittmann committed Mar 22, 2013
View
@@ -105,6 +105,7 @@
<commons.lang3.version>3.1</commons.lang3.version>
<commons.config.version>1.8</commons.config.version>
<commons.compress.version>1.4.1</commons.compress.version>
+ <commons.codec.version>1.5</commons.codec.version>
<jline.version>2.9</jline.version>
<joda-time.version>2.1</joda-time.version>
</properties>
@@ -230,6 +231,11 @@
<version>${commons.io.version}</version>
</dependency>
<dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>${commons.codec.version}</version>
+ </dependency>
+ <dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>${commons.config.version}</version>
@@ -88,6 +88,12 @@
<replacetoken>&lt;remote-destination host="localhost" port="25"/&gt;</replacetoken>
<replacevalue>&lt;remote-destination host="smtp.mailinator.com" port="25"/&gt;</replacevalue>
</replace>
+ <!-- Enable remote debugging -->
+ <echo>Enabling JBoss remote debugging</echo>
+ <replace file="${sramp.jboss.home}/bin/standalone.conf">
+ <replacetoken>#JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"</replacetoken>
+ <replacevalue>JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"</replacevalue>
+ </replace>
</target>
<target name="configure" depends="patch.jbpm-gwt-console-server,deploy.sramp">
@@ -30,45 +30,46 @@
/**
- *
+ *
*
*/
public class SRAMPMonitor extends TimerTask {
private Logger log = LoggerFactory.getLogger(this.getClass());
private Timer timer = null;
Governance governance = new Governance();
-
+
private long interval = governance.getQueryInterval();
private long acceptableLagTime = governance.getAcceptableLagtime();
-
+
public SRAMPMonitor() throws ConfigurationException {
super();
timer = new Timer(true);
timer.scheduleAtFixedRate(this, 0, interval);
}
-
+
@Override
public boolean cancel() {
timer.cancel();
return super.cancel();
}
-
-
- public synchronized void run()
+
+
+ @Override
+ public synchronized void run()
{
try {
if (firedOnTime(scheduledExecutionTime()) && isAppserverReady()) {
long startTime = System.currentTimeMillis();
-
+
QueryExecutor queryExecutor = new QueryExecutor();
queryExecutor.execute();
-
+
long endTime = System.currentTimeMillis();
-
+
if ((endTime-startTime) > interval) {
log.debug("Notification background task duration exceeds the JUDDI_NOTIFICATION_INTERVAL" +
- " of " + interval + ". Notification background task took "
+ " of " + interval + ". Notification background task took "
+ (endTime - startTime) + " milliseconds.");
} else {
log.debug("Notification background task took " + (endTime - startTime) + " milliseconds.");
@@ -91,7 +92,7 @@ public synchronized void run()
* is under load. The acceptableLagTime is configurable using the "juddi.notification.acceptable.lagtime"
* property and is defaulted to 1000ms. A negative value means that you do not care about the lag time
* and you simply always want to go do the notification work.
- *
+ *
* @param scheduleExecutionTime
* @return true if the server is within the acceptable latency lag.
*/
@@ -107,10 +108,10 @@ private boolean firedOnTime(long scheduleExecutionTime) {
return false;
}
}
-
+
/**
* Checks if we can ready the S-RAMP repository as well as the BPM API.
- *
+ *
* @return
* @throws MalformedURLException
*/
@@ -127,7 +128,7 @@ private boolean isAppserverReady() throws MalformedURLException {
}
return isReady;
}
-
+
/**
* Returns true if the given URL can be accessed.
* @param checkUrl
@@ -136,7 +137,7 @@ public boolean urlExists(String checkUrl) {
try {
URL checkURL = new URL(checkUrl);
HttpURLConnection checkConnection = (HttpURLConnection) checkURL.openConnection();
- checkConnection.setRequestMethod("GET");
+ checkConnection.setRequestMethod("HEAD");
checkConnection.setConnectTimeout(10000);
checkConnection.setReadTimeout(10000);
checkConnection.connect();
@@ -145,6 +146,6 @@ public boolean urlExists(String checkUrl) {
return false;
}
}
-
+
}
@@ -5,6 +5,7 @@
<module name="org.picketlink" />
<module name="org.jboss.as.web" />
<module name="org.apache.httpcomponents" />
+ <module name="org.apache.commons.codec" />
<module name="org.overlord.commons.overlord-commons-auth" />
</dependencies>
</deployment>
@@ -4,7 +4,7 @@
<listener>
<listener-class>org.overlord.sramp.server.SrampLifeCycle</listener-class>
</listener>
-
+
<servlet>
<servlet-name>Resteasy</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
@@ -17,11 +17,15 @@
<servlet-name>Resteasy</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
-
+
<security-constraint>
<web-resource-collection>
<web-resource-name>S-RAMP</web-resource-name>
<url-pattern>/*</url-pattern>
+ <http-method>GET</http-method>
+ <http-method>POST</http-method>
+ <http-method>PUT</http-method>
+ <http-method>DELETE</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>overlorduser</role-name>
@@ -36,4 +40,5 @@
<security-role>
<role-name>overlorduser</role-name>
</security-role>
+
</web-app>
@@ -1,28 +1,34 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.overlord.sramp</groupId>
- <artifactId>s-ramp</artifactId>
- <version>0.1.2-SNAPSHOT</version>
- <relativePath>../pom.xml</relativePath>
- </parent>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.overlord.sramp</groupId>
+ <artifactId>s-ramp</artifactId>
+ <version>0.1.2-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
- <artifactId>s-ramp-workitems</artifactId>
- <name>S-RAMP Governance Workitems</name>
+ <artifactId>s-ramp-workitems</artifactId>
+ <name>S-RAMP Governance Workitems</name>
<packaging>jar</packaging>
- <description>S-RAMP Governance governance workitems.</description>
- <dependencies>
- <dependency>
- <groupId>org.drools</groupId>
- <artifactId>knowledge-api</artifactId>
- <version>5.5.0.Final</version>
+ <description>S-RAMP Governance governance workitems.</description>
+ <dependencies>
+ <dependency>
+ <groupId>org.drools</groupId>
+ <artifactId>knowledge-api</artifactId>
+ <version>5.5.0.Final</version>
<scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <scope>provided</scope>
- </dependency>
- </dependencies>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
</project>
@@ -1,12 +1,15 @@
package org.overlord.sramp.workitem;
+import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Map;
+import java.util.Properties;
+import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.IOUtils;
import org.drools.runtime.process.WorkItem;
import org.drools.runtime.process.WorkItemHandler;
@@ -17,30 +20,38 @@
public class HttpClientWorkItemHandler implements WorkItemHandler {
Logger log = LoggerFactory.getLogger(this.getClass());
+
+ /**
+ * Constructor.
+ */
+ public HttpClientWorkItemHandler() {
+ }
+
/**
* Calls an HTTP endpoint. The address of the endpoint should be set in the
* parameter map passed into the workItem by the BPMN workflow. Both
* this parameters 'Url' as well as the method 'Method' are required
* parameters.
*/
+ @Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
try {
// extract required parameters
- String urlStr = (String) workItem.getParameter("Url");
+ String urlStr = (String) workItem.getParameter("Url");
String method = (String) workItem.getParameter("Method");
if (urlStr==null || method==null) {
throw new Exception("Url and Method are required parameters");
}
urlStr = urlStr.toLowerCase();
Map<String,Object> params = workItem.getParameters();
-
+
// optional timeout config parameters, defaulted to 60 seconds
Integer connectTimeout = (Integer) params.get("ConnectTimeout");
if (connectTimeout==null) connectTimeout = 60000;
Integer readTimeout = (Integer) params.get("ReadTimeout");
if (readTimeout==null) readTimeout = 60000;
-
+
// replace tokens in the urlStr, the replacement value of the token
// should be set in the parameters Map
for (String key : params.keySet()) {
@@ -56,14 +67,15 @@ public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
}
if (urlStr.contains("{")) throw new Exception("Url contains more tokens, " +
"please check the workflow and pass in the correct parameters. Url=" + urlStr);
-
+
// call http endpoint
log.info("Calling " + method + " TO: " + urlStr );
URL url = new URL(urlStr);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod(method);
connection.setConnectTimeout(connectTimeout);
connection.setReadTimeout(readTimeout);
+ addAuthorization(connection);
connection.connect();
int responseCode = connection.getResponseCode();
if (responseCode >= 200 && responseCode < 300) {
@@ -85,6 +97,46 @@ public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
}
+ /**
+ * Adds Authorization config to the connection prior to the request
+ * being sent to the server.
+ * @param connection
+ */
+ private void addAuthorization(HttpURLConnection connection) {
+ String propFile = "jbpm.console.properties";
+ String dfltPropFile = "default.jbpm.console.properties";
+
+ InputStream resourceIS = null;
+ InputStream dfltResourceIS = null;
+ try {
+ Properties props = new Properties();
+ resourceIS = getClass().getClassLoader().getResourceAsStream(propFile);
+ dfltResourceIS = getClass().getClassLoader().getResourceAsStream(dfltPropFile);
+ if (resourceIS == null && dfltResourceIS == null) {
+ log.warn("Failed to find either jbpm.console.properties or default.jbpm.console.properties (or both) on the classpath.");
+ } else {
+ if (dfltResourceIS != null)
+ props.load(dfltResourceIS);
+ if (resourceIS != null)
+ props.load(resourceIS);
+ String username = props.getProperty("guvnor.usr");
+ String password = props.getProperty("guvnor.pwd");
+ if (username != null && password != null) {
+ String b64Auth = Base64.encodeBase64String((username + ":" + password).getBytes());
+ connection.setRequestProperty("Authorization", "Basic " + b64Auth);
+ } else {
+ log.warn("No username (guvnor.usr) and/or password (guvnor.pwd) found in the jbpm console properties file.");
+ }
+ }
+ } catch (IOException e) {
+ IOUtils.closeQuietly(resourceIS);
+ IOUtils.closeQuietly(dfltResourceIS);
+ }
+
+ }
+
+
+ @Override
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
// Do nothing, notifications cannot be aborted

0 comments on commit ce1796f

Please sign in to comment.