Skip to content

Commit

Permalink
Fixed broken user import issues after keycloak upgrade to 1.2.0.CR1. F…
Browse files Browse the repository at this point in the history
…ixes #251.
  • Loading branch information
otsakir committed May 20, 2015
1 parent 353e0e2 commit d5e1b2c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions restcomm/restcomm.http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-core</artifactId>
<version>1.1.0.Final</version>
<version>1.2.0.CR1</version>
</dependency>

<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-adapter-core</artifactId>
<version>1.1.0.Final</version>
<version>1.2.0.CR1</version>
<scope>provided</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class KeycloakClient {
static final String ADMIN_USERNAME = "admin";
static final String ADMIN_PASSWORD = "password";
static final String ADMINISTRATION_APPLICATION = "admin-client"; // the name of the oauth application that carries out administrative tasks
static final String KEYCKLOAD_URL_ORIGIN = "http://login.restcomm.com:8081";

static class TypedList extends ArrayList<RoleRepresentation> {
}
Expand Down Expand Up @@ -91,10 +92,11 @@ public static AccessTokenResponse getToken(HttpServletRequest request) throws IO
*/
try {
HttpPost post = new HttpPost(KeycloakUriBuilder.fromUri(getBaseUrl(request) + "/auth")
.path(ServiceUrlConstants.TOKEN_SERVICE_DIRECT_GRANT_PATH).build(REALM));
.path(ServiceUrlConstants.TOKEN_PATH).build(REALM));
List <NameValuePair> formparams = new ArrayList <NameValuePair>();
formparams.add(new BasicNameValuePair("username", ADMIN_USERNAME));
formparams.add(new BasicNameValuePair("password", ADMIN_PASSWORD));
formparams.add(new BasicNameValuePair(OAuth2Constants.GRANT_TYPE, "password"));
formparams.add(new BasicNameValuePair(OAuth2Constants.CLIENT_ID, ADMINISTRATION_APPLICATION));
UrlEncodedFormEntity form = new UrlEncodedFormEntity(formparams, "UTF-8");
post.setEntity(form);
Expand Down Expand Up @@ -202,8 +204,11 @@ public static UserRepresentation getUserInfo(HttpServletRequest request, AccessT
}


// Keycloak service is assumed to running on the same host with restcomm
// Returns the URL origin where keycloak lies. First tries from a configuration value that is explicitly defined. It falls back to geting the value from the request assuming that keycloak runs side by side with restcomm.
public static String getBaseUrl(HttpServletRequest request) {
if ( KEYCKLOAD_URL_ORIGIN != null && !KEYCKLOAD_URL_ORIGIN.equals("") )
return KEYCKLOAD_URL_ORIGIN;

String useHostname = request.getServletContext().getInitParameter("useHostname");
if (useHostname != null && "true".equalsIgnoreCase(useHostname)) {
return "http://" + HostUtils.getHostName() + ":8080";
Expand Down

0 comments on commit d5e1b2c

Please sign in to comment.