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;
}
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);
}
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();
}
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);
}
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();
}
Aggregations