public boolean handleRequest(MessageContext messageContext) { org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) messageContext).getAxis2MessageContext(); Object headers = axis2MessageContext.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); if (headers != null && headers instanceof Map) { Map headersMap = (Map) headers; if (headersMap.get("Authorization") == null) { headersMap.clear(); axis2MessageContext.setProperty("HTTP_SC", "401"); headersMap.put("WWW-Authenticate", "Basic realm=\"WSO2 ESB\""); axis2MessageContext.setProperty("NO_ENTITY_BODY", new Boolean("true")); messageContext.setProperty("RESPONSE", "true"); messageContext.setTo(null); Axis2Sender.sendBack(messageContext); return false; } else { String authHeader = (String) headersMap.get("Authorization"); String credentials = authHeader.substring(6).trim(); if (processSecurity(credentials, messageContext)) { return true; } else { headersMap.clear(); axis2MessageContext.setProperty("HTTP_SC", "403"); axis2MessageContext.setProperty("NO_ENTITY_BODY", new Boolean("true")); messageContext.setProperty("RESPONSE", "true"); messageContext.setTo(null); Axis2Sender.sendBack(messageContext); return false; } } } return true; }
public boolean handleRequest_old(MessageContext messageContext) { System.out.println("Entro nel handler"); org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) messageContext).getAxis2MessageContext(); Object headers = axis2MessageContext.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); if (headers != null && headers instanceof Map) { Map headersMap = (Map) headers; if (headersMap.get("Authorization") == null) { System.out.println("TRUE1"); // non ho fornito nessun tipo di autenticazione return true; } else { String authHeader = (String) headersMap.get("Authorization"); String credentials = authHeader.substring(6).trim(); if (processSecurity(credentials, messageContext)) { System.out.println("TRUE2"); return true; } else { headersMap.clear(); axis2MessageContext.setProperty("HTTP_SC", "403"); axis2MessageContext.setProperty("NO_ENTITY_BODY", new Boolean("true")); messageContext.setProperty("RESPONSE", "true"); messageContext.setTo(null); Axis2Sender.sendBack(messageContext); System.out.println("FALSE"); return false; } } } System.out.println("TRU0E3"); return true; }