summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-1.x/modules/binding-jsonrpc-runtime
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-03-19 07:02:10 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-03-19 07:02:10 +0000
commitda1184f1f86b696f9725104b8a81d82ec5278c7a (patch)
tree78c6082919320052f714a14abcc688595665b9fd /branches/sca-java-1.x/modules/binding-jsonrpc-runtime
parent562b6310687d87a8efb5458eb45d2908e2d3ed6d (diff)
Adding support for LDAP Realm authentication policy
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@755858 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/modules/binding-jsonrpc-runtime')
-rw-r--r--branches/sca-java-1.x/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceServlet.java78
1 files changed, 45 insertions, 33 deletions
diff --git a/branches/sca-java-1.x/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceServlet.java b/branches/sca-java-1.x/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceServlet.java
index f260fe4a38..497b771d1c 100644
--- a/branches/sca-java-1.x/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceServlet.java
+++ b/branches/sca-java-1.x/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceServlet.java
@@ -26,6 +26,7 @@ import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.List;
+import javax.security.auth.Subject;
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -95,6 +96,12 @@ public class JSONRPCServiceServlet extends JSONRPCServlet {
} else {
try {
handleServiceRequest(request, response);
+
+ } catch(RuntimeException re) {
+ if (re.getCause() instanceof javax.security.auth.login.LoginException) {
+ response.setHeader("WWW-Authenticate", "BASIC realm=\"" + "ldap-realm" + "\"");
+ response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
+ }
} finally {
HttpSession session = request.getSession(false);
if (session != null) {
@@ -104,8 +111,7 @@ public class JSONRPCServiceServlet extends JSONRPCServlet {
}
}
- private void handleServiceRequest(HttpServletRequest request, HttpServletResponse response)
- throws IOException {
+ private void handleServiceRequest(HttpServletRequest request, HttpServletResponse response) throws IOException {
// Encode using UTF-8, although We are actually ASCII clean as
// all unicode data is JSON escaped using backslash u. This is
// less data efficient for foreign character sets but it is
@@ -238,42 +244,48 @@ public class JSONRPCServiceServlet extends JSONRPCServlet {
Operation jsonOperation = findOperation(method);
Object result = null;
- try {
- // Invoke the get operation on the service implementation
- Message requestMessage = messageFactory.createMessage();
- requestMessage.setOperation(jsonOperation);
- //store http request as a parameter to the message
- requestMessage.getHeaders().add(request);
-
- requestMessage.setBody(args);
+ // Invoke the get operation on the service implementation
+ Message requestMessage = messageFactory.createMessage();
+ requestMessage.setOperation(jsonOperation);
- //result = wire.invoke(jsonOperation, args);
- Message responseMessage = wire.getInvocationChain(jsonOperation).getHeadInvoker().invoke(requestMessage);
-
- if (!responseMessage.isFault()) {
- //successful execution of the invocation
- try {
- result = responseMessage.getBody();
- JSONObject jsonResponse = new JSONObject();
- jsonResponse.put("result", result);
- jsonResponse.putOpt("id", id);
- //get response to send to client
- return jsonResponse.toString().getBytes("UTF-8");
- } catch (Exception e) {
- throw new ServiceRuntimeException("Unable to create JSON response", e);
- }
+ requestMessage.getHeaders().add(request);
+
+ requestMessage.setBody(args);
+
+ //result = wire.invoke(jsonOperation, args);
+ Message responseMessage = null;
+ try {
+ responseMessage = wire.getInvocationChain(jsonOperation).getHeadInvoker().invoke(requestMessage);
+ } catch (RuntimeException re) {
+ if (re.getCause() instanceof javax.security.auth.login.LoginException) {
+ throw re;
} else {
- //exception thrown while executing the invocation
- Throwable exception = (Throwable)responseMessage.getBody();
- JSONRPCResult errorResult = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, exception );
+ //some other exception
+ JSONRPCResult errorResult = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, re);
return errorResult.toString().getBytes("UTF-8");
}
- } catch(RuntimeException e) {
- //some other exception
- JSONRPCResult errorResult = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, e);
- return errorResult.toString().getBytes("UTF-8");
}
+
+ if (!responseMessage.isFault()) {
+ //successful execution of the invocation
+ try {
+ result = responseMessage.getBody();
+ JSONObject jsonResponse = new JSONObject();
+ jsonResponse.put("result", result);
+ jsonResponse.putOpt("id", id);
+ //get response to send to client
+ return jsonResponse.toString().getBytes("UTF-8");
+ } catch (Exception e) {
+ throw new ServiceRuntimeException("Unable to create JSON response", e);
+ }
+ } else {
+ //exception thrown while executing the invocation
+ Throwable exception = (Throwable)responseMessage.getBody();
+ JSONRPCResult errorResult = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, exception );
+ return errorResult.toString().getBytes("UTF-8");
+ }
+
}
/**
@@ -300,5 +312,5 @@ public class JSONRPCServiceServlet extends JSONRPCServlet {
}
return result;
- }
+ }
}