Skip to content

Commit

Permalink
Added public endpoint to restcomm that will return keycloak*.json con…
Browse files Browse the repository at this point in the history
…figuration for all secured applications.Refers #337.
  • Loading branch information
otsakir committed Jul 6, 2015
1 parent eb2899c commit e536efb
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
<servlet-mapping>
<servlet-name>Jersey</servlet-name>
<url-pattern>/2012-04-24/*</url-pattern>
<!--<url-pattern>/keycloak/*</url-pattern> -->
</servlet-mapping>

<security-constraint>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.mobicents.servlet.restcomm.http;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import org.keycloak.representations.adapters.config.BaseAdapterConfig;
import org.keycloak.util.JsonSerialization;

@Path("/keycloak/config")
public class KeycloakResourcesEndpoint extends AbstractEndpoint {

public KeycloakResourcesEndpoint() {
// TODO Auto-generated constructor stub
}

@GET
@Path("/restcomm.json")
@Produces("application/json")
public Response getRestcommConfig() throws IOException {
BaseAdapterConfig config = new BaseAdapterConfig();
config.setRealm("restcomm");
config.setRealmKey("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB");
config.setAuthServerUrl("https://identity.restcomm.com/auth");
config.setSslRequired("all");
config.setResource("restcomm-rest");
config.setEnableBasicAuth(true);
config.setCors(true);

Map<String,String> credentials = new HashMap<String,String>();
credentials.put("secret", "password");
config.setCredentials(credentials);

return Response.ok(JsonSerialization.writeValueAsPrettyString(config), MediaType.APPLICATION_JSON).build();
}

@GET
@Path("/restcomm-ui.json")
@Produces("application/json")
public Response getRestcommUIConfig() throws IOException {
BaseAdapterConfig config = new BaseAdapterConfig();
config.setRealm("restcomm");
config.setRealmKey("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB");
config.setAuthServerUrl("https://identity.restcomm.com/auth");
config.setSslRequired("all");
config.setResource("restcomm-ui");
config.setPublicClient(true);

return Response.ok(JsonSerialization.writeValueAsPrettyString(config), MediaType.APPLICATION_JSON).build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.mobicents.servlet.restcomm.http.applications;

import java.util.HashSet;
import java.util.Set;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

import org.mobicents.servlet.restcomm.http.KeycloakResourcesEndpoint;

/**
* A separate Web application for public resources. Automatic binding to endpoints
* cannot work here. There is already the default web application under /services
* that gets bound with all other resources automatically.
*
* @author "Tsakiridis Orestis"
*
*/
@ApplicationPath("/public")
public class PublicResources extends Application {

public Set<Class<?>> getClasses() {
Set<Class<?>> resources = new HashSet<Class<?>>();
resources.add(KeycloakResourcesEndpoint.class);
return resources;
}
}

0 comments on commit e536efb

Please sign in to comment.