Search in sources :

Example 26 with ServiceProxyKey

use of com.predic8.membrane.core.rules.ServiceProxyKey in project service-proxy by membrane.

the class OAuth2ResourceTest method getMockAuthServiceProxy.

private ServiceProxy getMockAuthServiceProxy() throws IOException {
    ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(serverPort), null, 99999);
    WellknownFile wkf = new WellknownFile();
    wkf.setIssuer(getServerAddress());
    wkf.setAuthorizationEndpoint(getServerAddress() + "/auth");
    wkf.setTokenEndpoint(getServerAddress() + "/token");
    wkf.setUserinfoEndpoint(getServerAddress() + "/userinfo");
    wkf.setRevocationEndpoint(getServerAddress() + "/revoke");
    wkf.setJwksUri(getServerAddress() + "/certs");
    wkf.setSupportedResponseTypes("code token");
    wkf.setSupportedSubjectType("public");
    wkf.setSupportedIdTokenSigningAlgValues("RS256");
    wkf.setSupportedScopes("openid email profile");
    wkf.setSupportedTokenEndpointAuthMethods("client_secret_post");
    wkf.setSupportedClaims("sub email username");
    wkf.init(new HttpRouter());
    sp.getInterceptors().add(new AbstractInterceptor() {

        SecureRandom rand = new SecureRandom();

        @Override
        public synchronized Outcome handleRequest(Exchange exc) throws Exception {
            if (exc.getRequestURI().endsWith("/.well-known/openid-configuration")) {
                exc.setResponse(Response.ok(wkf.getWellknown()).build());
            } else if (exc.getRequestURI().startsWith("/auth?")) {
                Map<String, String> params = URLParamUtil.getParams(new URIFactory(), exc);
                exc.setResponse(Response.redirect(getClientAddress() + "/oauth2callback?code=1234&state=" + params.get("state"), false).build());
            } else if (exc.getRequestURI().startsWith("/token")) {
                ObjectMapper om = new ObjectMapper();
                Map<String, String> res = new HashMap<>();
                res.put("access_token", new BigInteger(130, rand).toString(32));
                res.put("token_type", "bearer");
                res.put("expires_in", "1");
                res.put("refresh_token", new BigInteger(130, rand).toString(32));
                exc.setResponse(Response.ok(om.writeValueAsString(res)).contentType("application/json").build());
            } else if (exc.getRequestURI().startsWith("/userinfo")) {
                ObjectMapper om = new ObjectMapper();
                Map<String, String> res = new HashMap<>();
                res.put("username", "dummy");
                exc.setResponse(Response.ok(om.writeValueAsString(res)).contentType("application/json").build());
            }
            if (exc.getResponse() == null)
                exc.setResponse(Response.notFound().build());
            return Outcome.RETURN;
        }
    });
    return sp;
}
Also used : AbstractInterceptor(com.predic8.membrane.core.interceptor.AbstractInterceptor) SecureRandom(java.security.SecureRandom) IOException(java.io.IOException) Exchange(com.predic8.membrane.core.exchange.Exchange) ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) Outcome(com.predic8.membrane.core.interceptor.Outcome) URIFactory(com.predic8.membrane.core.util.URIFactory) BigInteger(java.math.BigInteger) HttpRouter(com.predic8.membrane.core.HttpRouter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 27 with ServiceProxyKey

use of com.predic8.membrane.core.rules.ServiceProxyKey in project service-proxy by membrane.

the class MyApplication method createServiceProxy.

private static ServiceProxy createServiceProxy() {
    String hostname = "*";
    String method = "*";
    String path = ".*";
    int listenPort = 8080;
    ServiceProxyKey key = new ServiceProxyKey(hostname, method, path, listenPort);
    String targetHost = "localhost";
    int targetPort = 2001;
    return new ServiceProxy(key, targetHost, targetPort);
}
Also used : ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy)

Example 28 with ServiceProxyKey

use of com.predic8.membrane.core.rules.ServiceProxyKey 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)

Example 29 with ServiceProxyKey

use of com.predic8.membrane.core.rules.ServiceProxyKey in project service-proxy by membrane.

the class ClusterBalancerTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    extracor = new XMLElementSessionIdExtractor();
    extracor.setLocalName("session");
    extracor.setNamespace("http://predic8.com/session/");
    r = new HttpRouter();
    lb = new LoadBalancingInterceptor();
    lb.setSessionIdExtractor(extracor);
    lb.setName("Default");
    ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(3011), "predic8.com", 80);
    sp.getInterceptors().add(lb);
    r.getRuleManager().addProxyAndOpenPortIfNew(sp);
    r.init();
    BalancerUtil.up(r, "Default", "Default", "localhost", 2000);
    BalancerUtil.up(r, "Default", "Default", "localhost", 3000);
}
Also used : ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy)

Example 30 with ServiceProxyKey

use of com.predic8.membrane.core.rules.ServiceProxyKey in project service-proxy by membrane.

the class ClusterNotificationInterceptorTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    Rule rule = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3002), "thomas-bayer.com", 80);
    router = new HttpRouter();
    router.getRuleManager().addProxyAndOpenPortIfNew(rule);
    interceptor = new ClusterNotificationInterceptor();
    router.addUserFeatureInterceptor(interceptor);
    lbi = new LoadBalancingInterceptor();
    lbi.setName("Default");
    Rule rule2 = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3003), "thomas-bayer.com", 80);
    router.getRuleManager().addProxyAndOpenPortIfNew(rule2);
    rule2.getInterceptors().add(lbi);
    router.init();
}
Also used : ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) Rule(com.predic8.membrane.core.rules.Rule) HttpRouter(com.predic8.membrane.core.HttpRouter) Before(org.junit.Before)

Aggregations

ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)35 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)34 HttpRouter (com.predic8.membrane.core.HttpRouter)24 Before (org.junit.Before)18 Rule (com.predic8.membrane.core.rules.Rule)14 Exchange (com.predic8.membrane.core.exchange.Exchange)12 AbstractInterceptor (com.predic8.membrane.core.interceptor.AbstractInterceptor)11 Outcome (com.predic8.membrane.core.interceptor.Outcome)11 IOException (java.io.IOException)8 LoadBalancingInterceptor (com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor)3 Mapping (com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping)3 ProxyRule (com.predic8.membrane.core.rules.ProxyRule)3 SSLParser (com.predic8.membrane.core.config.security.SSLParser)2 MockInterceptor (com.predic8.membrane.core.interceptor.MockInterceptor)2 WebServerInterceptor (com.predic8.membrane.core.interceptor.server.WebServerInterceptor)2 ProxyRuleKey (com.predic8.membrane.core.rules.ProxyRuleKey)2 DummyWebServiceInterceptor (com.predic8.membrane.core.services.DummyWebServiceInterceptor)2 HttpClientConfiguration (com.predic8.membrane.core.transport.http.client.HttpClientConfiguration)2 ProxyConfiguration (com.predic8.membrane.core.transport.http.client.ProxyConfiguration)2 MalformedURLException (java.net.MalformedURLException)2