Search in sources :

Example 1 with User

use of com.predic8.membrane.core.interceptor.authentication.session.StaticUserDataProvider.User in project service-proxy by membrane.

the class UserFeatureInterceptor method handleRequest.

@Override
public Outcome handleRequest(Exchange exc) throws Exception {
    Rule predecessorRule = exc.getRule();
    Outcome outcome = flowController.invokeRequestHandlers(exc, predecessorRule.getInterceptors());
    while (isTargetInternalAndContinue(exc, outcome)) {
        log.debug("routing to serviceProxy with name: " + getServiceProxyName(exc));
        // rule matching
        String destination = exc.getDestinations().get(0);
        Rule newRule = getRuleByDest(destination);
        if (newRule == null)
            throw new Exception("No proxy found for destination " + destination);
        exc.setRule(newRule);
        // dispatching
        exc.getDestinations().clear();
        exc.getDestinations().add(DispatchingInterceptor.getForwardingDestination(exc));
        // user feature
        outcome = flowController.invokeRequestHandlers(exc, newRule.getInterceptors());
    }
    exc.setRule(predecessorRule);
    return outcome;
}
Also used : Rule(com.predic8.membrane.core.rules.Rule)

Example 2 with User

use of com.predic8.membrane.core.interceptor.authentication.session.StaticUserDataProvider.User in project service-proxy by membrane.

the class RegistrationInterceptor method handleRequest.

@Override
public Outcome handleRequest(Exchange exc) throws Exception {
    Request request = exc.getRequest();
    if (!request.isPOSTRequest())
        return ErrorMessages.returnErrorBadRequest(exc);
    User user;
    try {
        user = new ObjectMapper().readValue(request.getBodyAsStringDecoded(), User.class);
    } catch (IOException e) {
        return ErrorMessages.returnErrorBadRequest(exc);
    }
    try (Connection connection = userDataProvider.getDatasource().getConnection()) {
        try (ResultSet rs = connection.createStatement().executeQuery(getIsAccountNameAvailableSQL(user))) {
            if (rs.next() && rs.getInt(1) != 0)
                return ErrorMessages.returnErrorUserAlreadyExists(exc);
        }
        if (!SecurityUtils.isHashedPassword(user.getPassword()))
            user.setPassword(SecurityUtils.createPasswdCompatibleHash(user.getPassword()));
        connection.createStatement().executeUpdate(getInsertAccountIntoDatabaseSQL(user));
    }
    // TODO: Save user mit flag if confirmated
    // TODO: Send Confirmation Email
    // TODO: PreparedStatements gegen SQL-Injection verwenden??????
    exc.setResponse(Response.ok().build());
    return Outcome.RETURN;
}
Also used : User(com.predic8.membrane.core.interceptor.registration.entity.User) Request(com.predic8.membrane.core.http.Request) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with User

use of com.predic8.membrane.core.interceptor.authentication.session.StaticUserDataProvider.User in project service-proxy by membrane.

the class BasicAuthenticationInterceptorIntegrationTest method testHashedPassword.

@Test
public void testHashedPassword() throws Exception {
    List<User> users = new ArrayList<User>();
    User user = new User("admin", "$6$12345678$jwCsYagMo/KNcTDqnrWL25Dy3AfAT5U94abA5a/iPFO.Cx2zAkMpPxZBNKY/P/xiRrCfCFDxdBp7pvNEMoBcr0");
    users.add(user);
    BasicAuthenticationInterceptor interceptor = new BasicAuthenticationInterceptor();
    StaticUserDataProvider provider = (StaticUserDataProvider) interceptor.getUserDataProvider();
    interceptor.setUsers(users);
    User postData = new User("admin", "admin");
    try {
        provider.verify(postData.getAttributes());
    } catch (Exception e) {
        fail();
    }
}
Also used : User(com.predic8.membrane.core.interceptor.authentication.session.StaticUserDataProvider.User) ArrayList(java.util.ArrayList) StaticUserDataProvider(com.predic8.membrane.core.interceptor.authentication.session.StaticUserDataProvider) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with User

use of com.predic8.membrane.core.interceptor.authentication.session.StaticUserDataProvider.User 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 5 with User

use of com.predic8.membrane.core.interceptor.authentication.session.StaticUserDataProvider.User in project service-proxy by membrane.

the class BasicAuthenticationInterceptorIntegrationTest method setup.

@Before
public void setup() throws Exception {
    Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3001), "thomas-bayer.com", 80);
    router.getRuleManager().addProxyAndOpenPortIfNew(rule);
    BasicAuthenticationInterceptor interceptor = new BasicAuthenticationInterceptor();
    List<User> users = new ArrayList<User>();
    users.add(new User("admin", "admin"));
    interceptor.setUsers(users);
    router.addUserFeatureInterceptor(interceptor);
    router.init();
}
Also used : ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) User(com.predic8.membrane.core.interceptor.authentication.session.StaticUserDataProvider.User) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) ArrayList(java.util.ArrayList) Rule(com.predic8.membrane.core.rules.Rule) Before(org.junit.Before)

Aggregations

User (com.predic8.membrane.core.interceptor.authentication.session.StaticUserDataProvider.User)4 Request (com.predic8.membrane.core.http.Request)3 IOException (java.io.IOException)3 Test (org.junit.Test)3 Exchange (com.predic8.membrane.core.exchange.Exchange)2 Response (com.predic8.membrane.core.http.Response)2 Rule (com.predic8.membrane.core.rules.Rule)2 Process2 (com.predic8.membrane.examples.Process2)2 ProxiesXmlUtil (com.predic8.membrane.examples.ProxiesXmlUtil)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ParseException (com.floreysoft.jmte.message.ParseException)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 LogInterceptor (com.predic8.membrane.core.interceptor.LogInterceptor)1 StaticUserDataProvider (com.predic8.membrane.core.interceptor.authentication.session.StaticUserDataProvider)1 User (com.predic8.membrane.core.interceptor.registration.entity.User)1 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)1 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)1 Connection (java.sql.Connection)1