Search in sources :

Example 6 with Path

use of com.predic8.membrane.core.config.Path in project service-proxy by membrane.

the class MessageAnalyserTest method getRequest.

private Exchange getRequest(String path) throws IOException {
    Exchange exc = new Exchange(null);
    Request req = new Request();
    req.create("POST", "http://test", "HTTP/", new Header(), getClass().getClassLoader().getResourceAsStream(path));
    exc.setRequest(req);
    return exc;
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Header(com.predic8.membrane.core.http.Header) Request(com.predic8.membrane.core.http.Request)

Example 7 with Path

use of com.predic8.membrane.core.config.Path in project service-proxy by membrane.

the class WADLInterceptorTest method testDefaultSettings.

@Test
public void testDefaultSettings() throws Exception {
    Exchange exc = getExchange();
    assertEquals(interceptor.handleResponse(exc), Outcome.CONTINUE);
    assertAttribute(exc, "//wadl:resources/@base", "http://thomas-bayer.com:3011/search/V1/");
    assertAttribute(exc, "//wadl:resource/@path", "newsSearch");
    assertAttribute(exc, "//wadl:grammars/wadl:include[1]/@href", "http://thomas-bayer.com:3011/search.xsd");
    assertAttribute(exc, "//wadl:grammars/wadl:include[2]/@href", "http://thomas-bayer.com:3011/error/Error.xsd");
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Test(org.junit.Test)

Example 8 with Path

use of com.predic8.membrane.core.config.Path in project service-proxy by membrane.

the class QuickstartSOAPTest method doit.

@Test
public void doit() throws IOException, InterruptedException {
    File baseDir = getExampleDir("quickstart-soap");
    Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
    try {
        ProxiesXmlUtil pxu = new ProxiesXmlUtil(new File(baseDir, "proxies.xml"));
        pxu.updateWith("<spring:beans xmlns=\"http://membrane-soa.org/proxies/1/\"\r\n" + "	xmlns:spring=\"http://www.springframework.org/schema/beans\"\r\n" + "	xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + "	xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd\r\n" + "					    http://membrane-soa.org/proxies/1/ http://membrane-soa.org/schemas/proxies-1.xsd\">\r\n" + "\r\n" + "	<router>\r\n" + "	\r\n" + "	<soapProxy port=\"2000\" wsdl=\"http://www.thomas-bayer.com/axis2/services/BLZService?wsdl\">\r\n" + "		<path>/MyBLZService</path>\r\n" + "	</soapProxy>\r\n" + "	\r\n" + "	<serviceProxy port=\"9000\">\r\n" + "		<basicAuthentication>\r\n" + "			<user name=\"admin\" password=\"membrane\" />\r\n" + "		</basicAuthentication>	\r\n" + "		<adminConsole />\r\n" + "	</serviceProxy>\r\n" + "	\r\n" + "	</router>\r\n" + "</spring:beans>", sl);
        String endpoint = "http://localhost:2000/MyBLZService";
        String result = getAndAssert200(endpoint + "?wsdl");
        assertContains("wsdl:documentation", result);
        // assert that rewriting did take place
        assertContains("localhost:2000/MyBLZService", result);
        result = AssertUtils.postAndAssert200(endpoint, "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:blz=\"http://thomas-bayer.com/blz/\">\r\n" + "   <soapenv:Header/>\r\n" + "   <soapenv:Body>\r\n" + "      <blz:getBank>\r\n" + "         <blz:blz>37050198</blz:blz>\r\n" + "      </blz:getBank>\r\n" + "   </soapenv:Body>\r\n" + "</soapenv:Envelope>");
        assertContains("Sparkasse", result);
        AssertUtils.setupHTTPAuthentication("localhost", 9000, "admin", "membrane");
        result = getAndAssert200("http://localhost:9000/admin/");
        result.contains("BLZService");
        String invalidRequest = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:blz=\"http://thomas-bayer.com/blz/\">\r\n" + "   <soapenv:Header/>\r\n" + "   <soapenv:Body>\r\n" + "      <blz:getBank>\r\n" + "         <blz:blz>37050198</blz:blz>\r\n" + "         <foo />\r\n" + "      </blz:getBank>\r\n" + "   </soapenv:Body>\r\n" + "</soapenv:Envelope>";
        result = postAndAssert(500, endpoint, invalidRequest);
        assertContains(".java:", result);
        AssertUtils.closeConnections();
        AssertUtils.setupHTTPAuthentication("localhost", 9000, "admin", "membrane");
        pxu.updateWith("<spring:beans xmlns=\"http://membrane-soa.org/proxies/1/\"\r\n" + "	xmlns:spring=\"http://www.springframework.org/schema/beans\"\r\n" + "	xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + "	xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd\r\n" + "					    http://membrane-soa.org/proxies/1/ http://membrane-soa.org/schemas/proxies-1.xsd\">\r\n" + "\r\n" + "	<router>\r\n" + "	\r\n" + "	<soapProxy port=\"2000\" wsdl=\"http://www.thomas-bayer.com/axis2/services/BLZService?wsdl\">\r\n" + "		<path>/MyBLZService</path>\r\n" + "		<soapStackTraceFilter/>\r\n" + "	</soapProxy>\r\n" + "	\r\n" + "	<serviceProxy port=\"9000\">\r\n" + "		<basicAuthentication>\r\n" + "			<user name=\"admin\" password=\"membrane\" />\r\n" + "		</basicAuthentication>	\r\n" + "		<adminConsole />\r\n" + "	</serviceProxy>\r\n" + "	\r\n" + "	</router>\r\n" + "</spring:beans>", sl);
        result = postAndAssert(500, endpoint, invalidRequest);
        assertContainsNot(".java:", result);
        AssertUtils.closeConnections();
        AssertUtils.setupHTTPAuthentication("localhost", 9000, "admin", "membrane");
        pxu.updateWith("<spring:beans xmlns=\"http://membrane-soa.org/proxies/1/\"\r\n" + "	xmlns:spring=\"http://www.springframework.org/schema/beans\"\r\n" + "	xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + "	xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd\r\n" + "					    http://membrane-soa.org/proxies/1/ http://membrane-soa.org/schemas/proxies-1.xsd\">\r\n" + "\r\n" + "	<router>\r\n" + "	\r\n" + "	<soapProxy port=\"2000\" wsdl=\"http://www.thomas-bayer.com/axis2/services/BLZService?wsdl\">\r\n" + "		<path>/MyBLZService</path>\r\n" + "		<soapStackTraceFilter/>\r\n" + "		<validator/>\r\n" + "	</soapProxy>\r\n" + "	\r\n" + "	<serviceProxy port=\"9000\">\r\n" + "		<basicAuthentication>\r\n" + "			<user name=\"admin\" password=\"membrane\" />\r\n" + "		</basicAuthentication>	\r\n" + "		<adminConsole />\r\n" + "	</serviceProxy>\r\n" + "	\r\n" + "	</router>\r\n" + "</spring:beans>", sl);
        result = postAndAssert(400, endpoint, invalidRequest);
        assertContains("Validation failed", result);
        result = getAndAssert200("http://localhost:9000/admin/service-proxy/show?name=BLZService%3A2000");
        result.contains("1 of 1 messages have been invalid");
        result = getAndAssert200(endpoint);
        assertContains("Target Namespace", result);
        result = getAndAssert200(endpoint + "/operation/BLZServiceSOAP11Binding/BLZServicePortType/getBank");
        assertContains("blz&gt;?XXX?", result);
        AssertUtils.closeConnections();
        pxu.updateWith("<spring:beans xmlns=\"http://membrane-soa.org/proxies/1/\"\r\n" + "	xmlns:spring=\"http://www.springframework.org/schema/beans\"\r\n" + "	xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + "	xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd\r\n" + "					    http://membrane-soa.org/proxies/1/ http://membrane-soa.org/schemas/proxies-1.xsd\">\r\n" + "\r\n" + "	<router>\r\n" + "	\r\n" + "	<soapProxy port=\"2000\" wsdl=\"http://www.thomas-bayer.com/axis2/services/BLZService?wsdl\">\r\n" + "		<path>/MyBLZService</path>\r\n" + "		<soapStackTraceFilter/>\r\n" + "		<validator/>\r\n" + "	</soapProxy>\r\n" + "	\r\n" + "	<serviceProxy port=\"9000\">\r\n" + "		<basicAuthentication>\r\n" + "			<user name=\"admin\" password=\"membrane\" />\r\n" + "		</basicAuthentication>	\r\n" + "		<adminConsole />\r\n" + "	</serviceProxy>\r\n" + "	\r\n" + "	<serviceProxy port=\"2000\">\r\n" + "		<index />\r\n" + "	</serviceProxy>\r\n" + "	\r\n" + "	</router>\r\n" + "</spring:beans>", sl);
        result = getAndAssert200("http://localhost:2000");
        assertContains("/MyBLZService", result);
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) ProxiesXmlUtil(com.predic8.membrane.examples.ProxiesXmlUtil) File(java.io.File) Test(org.junit.Test)

Example 9 with Path

use of com.predic8.membrane.core.config.Path in project service-proxy by membrane.

the class LoginDialog method handleLoginRequest.

public void handleLoginRequest(Exchange exc) throws Exception {
    Session s = sessionManager.getSession(exc);
    String uri = exc.getRequest().getUri().substring(path.length() - 1);
    if (uri.indexOf('?') >= 0)
        uri = uri.substring(0, uri.indexOf('?'));
    exc.getDestinations().set(0, uri);
    if (uri.equals("/logout")) {
        if (s != null)
            s.clear();
        exc.setResponse(Response.redirect(path, false).body("").build());
    } else if (uri.equals("/consent")) {
        if (exc.getRequest().getMethod().equals("POST"))
            processConsentPageResult(exc, s);
        else
            showConsentPage(exc, s);
    } else if (uri.equals("/")) {
        if (s == null || !s.isPreAuthorized()) {
            if (exc.getRequest().getMethod().equals("POST")) {
                Map<String, String> userAttributes;
                Map<String, String> params = URLParamUtil.getParams(uriFactory, exc);
                String username = params.get("username");
                if (username == null) {
                    showPage(exc, 0, "error", "INVALID_PASSWORD");
                    return;
                }
                if (accountBlocker != null && accountBlocker.isBlocked(username)) {
                    showPage(exc, 0, "error", "ACCOUNT_BLOCKED");
                    return;
                }
                try {
                    userAttributes = userDataProvider.verify(params);
                } catch (NoSuchElementException e) {
                    List<String> params2 = Lists.newArrayList("error", "INVALID_PASSWORD");
                    if (accountBlocker != null) {
                        if (accountBlocker.fail(username))
                            params2.addAll(Lists.newArrayList("accountBlocked", "true"));
                    }
                    showPage(exc, 0, params2.toArray());
                    return;
                } catch (Exception e) {
                    log.error("", e);
                    showPage(exc, 0, "error", "INTERNAL_SERVER_ERROR");
                    return;
                }
                if (exposeUserCredentialsToSession) {
                    for (Map.Entry<String, String> param : params.entrySet()) if (!userAttributes.containsKey(param.getKey()))
                        userAttributes.put(param.getKey(), param.getValue());
                }
                if (tokenProvider != null)
                    showPage(exc, 1);
                else {
                    String target = params.get("target");
                    if (StringUtils.isEmpty(target))
                        target = "/";
                    exc.setResponse(Response.redirectWithout300(target).build());
                }
                Session session = sessionManager.getOrCreateSession(exc);
                session.preAuthorize(username, userAttributes);
                if (tokenProvider != null)
                    tokenProvider.requestToken(session.getUserAttributes());
            } else {
                showPage(exc, 0);
            }
        } else {
            if (accountBlocker != null && accountBlocker.isBlocked(s.getUserName())) {
                showPage(exc, 0, "error", "ACCOUNT_BLOCKED");
                return;
            }
            if (exc.getRequest().getMethod().equals("POST")) {
                String token = URLParamUtil.getParams(uriFactory, exc).get("token");
                try {
                    if (tokenProvider != null)
                        tokenProvider.verifyToken(s.getUserAttributes(), token);
                } catch (NoSuchElementException e) {
                    List<String> params = Lists.newArrayList("error", "INVALID_TOKEN");
                    if (accountBlocker != null)
                        if (accountBlocker.fail(s.getUserName()))
                            params.addAll(Lists.newArrayList("accountBlocked", "true"));
                    s.clear();
                    showPage(exc, 0, params.toArray());
                    return;
                } catch (Exception e) {
                    log.error("", e);
                    s.clear();
                    showPage(exc, 0, "error", "INTERNAL_SERVER_ERROR");
                    return;
                }
                if (accountBlocker != null)
                    accountBlocker.unblock(s.getUserName());
                String target = URLParamUtil.getParams(uriFactory, exc).get("target");
                if (StringUtils.isEmpty(target))
                    target = "/";
                if (this.message != null)
                    exc.setResponse(Response.redirectWithout300(target, message).build());
                else
                    exc.setResponse(Response.redirectWithout300(target).build());
                s.authorize();
            } else {
                showPage(exc, 1);
            }
        }
    } else {
        wsi.handleRequest(exc);
    }
}
Also used : ResolverMap(com.predic8.membrane.core.resolver.ResolverMap) ParseException(com.floreysoft.jmte.message.ParseException) MalformedURLException(java.net.MalformedURLException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Session(com.predic8.membrane.core.interceptor.authentication.session.SessionManager.Session)

Example 10 with Path

use of com.predic8.membrane.core.config.Path in project service-proxy by membrane.

the class SoapOperationExtractorTest method getExchange.

private Exchange getExchange(String path) throws IOException {
    Exchange exc = new Exchange(null);
    Request req = new Request();
    req.create("POST", "http://test", "HTTP/", new Header(), getClass().getClassLoader().getResourceAsStream(path));
    exc.setRequest(req);
    return exc;
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Header(com.predic8.membrane.core.http.Header) Request(com.predic8.membrane.core.http.Request)

Aggregations

Exchange (com.predic8.membrane.core.exchange.Exchange)8 Test (org.junit.Test)6 Request (com.predic8.membrane.core.http.Request)4 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)4 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)4 Process2 (com.predic8.membrane.examples.Process2)3 Definitions (com.predic8.wsdl.Definitions)3 WSDLParser (com.predic8.wsdl.WSDLParser)3 File (java.io.File)3 IOException (java.io.IOException)3 StringWriter (java.io.StringWriter)3 ParseException (com.floreysoft.jmte.message.ParseException)2 Header (com.predic8.membrane.core.http.Header)2 Response (com.predic8.membrane.core.http.Response)2 AbstractServiceProxy (com.predic8.membrane.core.rules.AbstractServiceProxy)2 ProxiesXmlUtil (com.predic8.membrane.examples.ProxiesXmlUtil)2 RequestTemplateCreator (com.predic8.wstool.creator.RequestTemplateCreator)2 SOARequestCreator (com.predic8.wstool.creator.SOARequestCreator)2 MarkupBuilder (groovy.xml.MarkupBuilder)2 MalformedURLException (java.net.MalformedURLException)2