use of com.predic8.membrane.core.HttpRouter 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;
}
use of com.predic8.membrane.core.HttpRouter in project service-proxy by membrane.
the class WellknownFileTest method testValidWellknownFile.
@Test
public void testValidWellknownFile() throws Exception {
WellknownFile wkf = new WellknownFile();
wkf.setIssuer("http://testissuer.com");
wkf.setAuthorizationEndpoint(authServerUrl + "auth");
wkf.setTokenEndpoint(authServerUrl + "token");
wkf.setUserinfoEndpoint(authServerUrl + "userinfo");
wkf.setRevocationEndpoint(authServerUrl + "revoke");
wkf.setJwksUri(authServerUrl + "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());
assertEquals(expectedWellknownFile(), wkf.getWellknown());
}
use of com.predic8.membrane.core.HttpRouter in project service-proxy by membrane.
the class MyApplication method main.
public static void main(String[] args) throws Exception {
System.out.println("Starting up");
// create a new service proxy that listens on port 8080 and has a target to localhost:2001
ServiceProxy sp = createServiceProxy();
// create an enclosing WebSocket interceptor to add our own Logging interceptor to it
WebSocketInterceptor ws = new WebSocketInterceptor();
ws.getInterceptors().add(new MyWebSocketLogInterceptor());
// attach the WebSocket interceptor to the service proxy
sp.getInterceptors().add(ws);
// add the service proxy to a new router instance and start it
HttpRouter router = new HttpRouter();
router.add(sp);
router.init();
System.out.println("Starting finished - Waiting for WebSocket communication");
}
use of com.predic8.membrane.core.HttpRouter 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);
}
use of com.predic8.membrane.core.HttpRouter 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();
}
Aggregations