Commit 23283f5d authored by Francesco Scoccia's avatar Francesco Scoccia

RestAPI Plugin - Provide the possibility to use Custom Auth Filter

Added back the JERSEY_LOGGER. Now messages are shown in the UI. Have to
find a way to reload the wrapper after that the options have been saved,
so that a new wrapper can be used without enforcing reload via the
plugins menu
parent ed8c675b
...@@ -39,6 +39,8 @@ import org.jivesoftware.util.PropertyEventDispatcher; ...@@ -39,6 +39,8 @@ import org.jivesoftware.util.PropertyEventDispatcher;
import org.jivesoftware.util.PropertyEventListener; import org.jivesoftware.util.PropertyEventListener;
import org.jivesoftware.util.StringUtils; import org.jivesoftware.util.StringUtils;
import org.jivesoftware.openfire.plugin.rest.service.JerseyWrapper;
/** /**
* The Class RESTServicePlugin. * The Class RESTServicePlugin.
*/ */
...@@ -190,6 +192,16 @@ public class RESTServicePlugin implements Plugin, PropertyEventListener { ...@@ -190,6 +192,16 @@ public class RESTServicePlugin implements Plugin, PropertyEventListener {
} }
} }
/**
* Returns the loading status message.
*
* @return the loading status message.
*/
public String getLoadingStatusMessage() {
return JerseyWrapper.getLoadingStatusMessage();
}
/** /**
* Returns the secret key that only valid requests should know. * Returns the secret key that only valid requests should know.
* *
......
...@@ -2,6 +2,8 @@ package org.jivesoftware.openfire.plugin.rest.service; ...@@ -2,6 +2,8 @@ package org.jivesoftware.openfire.plugin.rest.service;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.lang.ClassNotFoundException; import java.lang.ClassNotFoundException;
import java.lang.Class; import java.lang.Class;
...@@ -16,8 +18,6 @@ import org.jivesoftware.util.JiveGlobals; ...@@ -16,8 +18,6 @@ import org.jivesoftware.util.JiveGlobals;
import com.sun.jersey.api.core.PackagesResourceConfig; import com.sun.jersey.api.core.PackagesResourceConfig;
import com.sun.jersey.spi.container.servlet.ServletContainer; import com.sun.jersey.spi.container.servlet.ServletContainer;
import org.apache.log4j.Logger;
/** /**
* The Class JerseyWrapper. * The Class JerseyWrapper.
*/ */
...@@ -26,6 +26,9 @@ public class JerseyWrapper extends ServletContainer { ...@@ -26,6 +26,9 @@ public class JerseyWrapper extends ServletContainer {
/** The Constant CUSTOM_AUTH_PROPERTY_NAME */ /** The Constant CUSTOM_AUTH_PROPERTY_NAME */
private static final String CUSTOM_AUTH_PROPERTY_NAME = "plugin.restapi.customAuthFilter"; private static final String CUSTOM_AUTH_PROPERTY_NAME = "plugin.restapi.customAuthFilter";
/** The Constant REST_AUTH_TYPE */
private static final String REST_AUTH_TYPE = "plugin.restapi.httpAuth";
/** The Constant AUTHFILTER. */ /** The Constant AUTHFILTER. */
private static final String AUTHFILTER = "org.jivesoftware.openfire.plugin.rest.AuthFilter"; private static final String AUTHFILTER = "org.jivesoftware.openfire.plugin.rest.AuthFilter";
...@@ -59,25 +62,29 @@ public class JerseyWrapper extends ServletContainer { ...@@ -59,25 +62,29 @@ public class JerseyWrapper extends ServletContainer {
/** The prc. */ /** The prc. */
private static PackagesResourceConfig prc; private static PackagesResourceConfig prc;
private static Logger LOGGER = Logger.getLogger(JerseyWrapper.class); /** The Constant JERSEY_LOGGER. */
private final static Logger JERSEY_LOGGER = Logger.getLogger("com.sun.jersey");
private static String loadingStatusMessage = null;
static { static {
// Check if custom AuthFilter is available // Check if custom AuthFilter is available
String customAuthFilterClassName = JiveGlobals.getProperty(CUSTOM_AUTH_PROPERTY_NAME); String customAuthFilterClassName = JiveGlobals.getProperty(CUSTOM_AUTH_PROPERTY_NAME);
String restAuthType = JiveGlobals.getProperty(REST_AUTH_TYPE);
String pickedAuthFilter = AUTHFILTER; String pickedAuthFilter = AUTHFILTER;
try { try {
if(customAuthFilterClassName != null) { if(customAuthFilterClassName != null && "custom".equals(restAuthType)) {
LOGGER.info("Trying to set a custom authentication filter for restAPI plugin with classname: " + customAuthFilterClassName);
Class.forName(customAuthFilterClassName, false, JerseyWrapper.class.getClassLoader()); Class.forName(customAuthFilterClassName, false, JerseyWrapper.class.getClassLoader());
pickedAuthFilter = customAuthFilterClassName; pickedAuthFilter = customAuthFilterClassName;
loadingStatusMessage = null;
} }
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
LOGGER.info("No custom auth filter found for restAPI plugin! Still using the default one"); loadingStatusMessage = "No custom auth filter found for restAPI plugin!";
} }
JERSEY_LOGGER.setLevel(Level.SEVERE);
config = new HashMap<String, Object>(); config = new HashMap<String, Object>();
config.put(RESOURCE_CONFIG_CLASS_KEY, RESOURCE_CONFIG_CLASS); config.put(RESOURCE_CONFIG_CLASS_KEY, RESOURCE_CONFIG_CLASS);
prc = new PackagesResourceConfig(SCAN_PACKAGE_DEFAULT); prc = new PackagesResourceConfig(SCAN_PACKAGE_DEFAULT);
...@@ -138,4 +145,14 @@ public class JerseyWrapper extends ServletContainer { ...@@ -138,4 +145,14 @@ public class JerseyWrapper extends ServletContainer {
// Release the excluded URL // Release the excluded URL
AuthCheckFilter.removeExclude(SERVLET_URL); AuthCheckFilter.removeExclude(SERVLET_URL);
} }
/*
* Returns the loading status message.
*
* @return the loading status message.
*/
public static String getLoadingStatusMessage() {
return loadingStatusMessage;
}
} }
...@@ -24,12 +24,19 @@ ...@@ -24,12 +24,19 @@
String allowedIPs = ParamUtils.getParameter(request, "allowedIPs"); String allowedIPs = ParamUtils.getParameter(request, "allowedIPs");
String customAuthFilterClassName = ParamUtils.getParameter(request, "customAuthFilterClassName"); String customAuthFilterClassName = ParamUtils.getParameter(request, "customAuthFilterClassName");
String loadingStatus = null;
RESTServicePlugin plugin = (RESTServicePlugin) XMPPServer.getInstance().getPluginManager() RESTServicePlugin plugin = (RESTServicePlugin) XMPPServer.getInstance().getPluginManager()
.getPlugin("restapi"); .getPlugin("restapi");
// Handle a save // Handle a save
Map errors = new HashMap(); Map errors = new HashMap();
if (save) { if (save) {
loadingStatus = plugin.getLoadingStatusMessage();
if (loadingStatus != null) {
errors.put("loadingStatus", loadingStatus);
}
if (errors.size() == 0) { if (errors.size() == 0) {
plugin.setEnabled(enabled); plugin.setEnabled(enabled);
plugin.setSecret(secret); plugin.setSecret(secret);
...@@ -79,6 +86,24 @@ ...@@ -79,6 +86,24 @@
} }
%> %>
<%
if (errors.get("loadingStatus") != null) {
%>
<div class="jive-error">
<table cellpadding="0" cellspacing="0" border="0">
<tbody>
<tr>
<td class="jive-icon"><img src="images/error-16x16.gif"
width="16" height="16" border="0"></td>
<td class="jive-icon-label"><%= loadingStatus %></td>
</tr>
</tbody>
</table>
</div>
<br>
<%
}
%>
<form action="rest-api.jsp?save" method="post"> <form action="rest-api.jsp?save" method="post">
<fieldset> <fieldset>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment