-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added public endpoint to restcomm that will return keycloak*.json con…
…figuration for all secured applications.Refers #337.
- Loading branch information
Showing
3 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...omm.http/src/main/java/org/mobicents/servlet/restcomm/http/KeycloakResourcesEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
....http/src/main/java/org/mobicents/servlet/restcomm/http/applications/PublicResources.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |