01: package org.objectweb.salome_tmf.server;
02:
03: import javax.servlet.http.HttpServletRequest;
04:
05: import org.apache.axis.AxisFault;
06: import org.apache.axis.MessageContext;
07: import org.apache.axis.encoding.Base64;
08: import org.apache.axis.handlers.BasicHandler;
09: import org.apache.axis.transport.http.HTTPConstants;
10: import org.apache.axis.utils.Messages;
11: import org.apache.commons.logging.Log;
12: import org.apache.commons.logging.LogFactory;
13:
14: @SuppressWarnings("serial")
15: public class AxisAuthorizationHandler extends BasicHandler {
16:
17: protected static Log log = LogFactory
18: .getLog(AxisAuthorizationHandler.class);
19:
20: private final static String LOGIN = "LoginSalome";
21: private final static String[] SERVICE_OPERATIONS = {
22: "SQLConfig_getSalomeConf", "SQLProject_getAllProjects",
23: "SQLProject_getUsersOfProject",
24: "SQLProject_getAdminsOfProject",
25: "SQLPersonne_getUserByLogin", "SQLConfig_updateSalomeConf" };
26:
27: public static String SERVICE = null;
28: public static String OPERATION = null;
29:
30: public void invoke(MessageContext context) throws AxisFault {
31:
32: SERVICE = null;
33: OPERATION = null;
34:
35: if (log.isDebugEnabled()) {
36: log.debug("Enter: AxisAuthorizationHandler::invoke");
37: }
38:
39: String service = context.getTargetService();
40: String operation = null;
41:
42: if (context.getOperation() != null) {
43: operation = context.getOperation().getName();
44: }
45:
46: // affectation des valeurs d'appel
47: SERVICE = service;
48: OPERATION = operation;
49:
50: if (context != null && service != null && operation != null) {
51:
52: HttpServletRequest req = (HttpServletRequest) context
53: .getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
54: String auth = req.getHeader("Authorization");
55: // auth is not null otherwise authent filter not deployed.
56: if (auth == null) {
57: throw new AxisFault("Server.Unauthenticated", Messages
58: .getMessage("cantAuth00", ""), null, null);
59: }
60: auth = auth.substring(auth.indexOf(" "));
61: // Decodage
62: String decoded = new String(Base64.decode(auth));
63: // decoded contient username:password.
64: int index = decoded.indexOf(":");
65: String username = decoded.substring(0, index);
66:
67: if (username.equals(LOGIN)) {
68: boolean valid = false;
69: String servop = service + "_" + operation;
70:
71: for (int i = 0; i < SERVICE_OPERATIONS.length; i++) {
72: String so = SERVICE_OPERATIONS[i];
73: if (servop.equals(so)) {
74: valid = true;
75: break;
76: }
77: }
78: if (!valid) {
79: throw new AxisFault("Server.Unauthorized", Messages
80: .getMessage("notAuth00", username, servop),
81: null, null);
82: }
83: }
84: }
85: }
86: }
|