Merge pull request #1141 from dbarentine/master

[KEYCLOAK-1205] Fix BearerAuthFilter refreshing token
This commit is contained in:
Stian Thorgersen 2015-04-15 11:09:26 +02:00
commit 29ea24c8fb
4 changed files with 16 additions and 6 deletions

View file

@ -26,7 +26,7 @@ public class Keycloak {
target = client.target(config.getServerUrl()); target = client.target(config.getServerUrl());
target.register(new BearerAuthFilter(tokenManager.getAccessTokenString())); target.register(new BearerAuthFilter(tokenManager));
} }
public static Keycloak getInstance(String serverUrl, String realm, String username, String password, String clientId, String clientSecret){ public static Keycloak getInstance(String serverUrl, String realm, String username, String password, String clientId, String clientSecret){

View file

@ -1,5 +1,7 @@
package org.keycloak.admin.client.resource; package org.keycloak.admin.client.resource;
import org.keycloak.admin.client.token.TokenManager;
import javax.ws.rs.client.ClientRequestContext; import javax.ws.rs.client.ClientRequestContext;
import javax.ws.rs.client.ClientRequestFilter; import javax.ws.rs.client.ClientRequestFilter;
import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.HttpHeaders;
@ -11,14 +13,23 @@ import java.io.IOException;
public class BearerAuthFilter implements ClientRequestFilter { public class BearerAuthFilter implements ClientRequestFilter {
private final String tokenString; private final String tokenString;
private final TokenManager tokenManager;
public BearerAuthFilter(String tokenString) { public BearerAuthFilter(String tokenString) {
this.tokenString = tokenString; this.tokenString = tokenString;
this.tokenManager = null;
} }
public BearerAuthFilter(TokenManager tokenManager) {
this.tokenManager = tokenManager;
this.tokenString = null;
}
@Override @Override
public void filter(ClientRequestContext requestContext) throws IOException { public void filter(ClientRequestContext requestContext) throws IOException {
String authHeader = "Bearer " + tokenString; String authHeader = "Bearer " + (tokenManager != null ? tokenManager.getAccessTokenString() : tokenString);
requestContext.getHeaders().add(HttpHeaders.AUTHORIZATION, authHeader); requestContext.getHeaders().add(HttpHeaders.AUTHORIZATION, authHeader);
} }

View file

@ -22,7 +22,7 @@ public interface RoleMappingResource {
@Path("realm") @Path("realm")
public RoleScopeResource realmLevel(); public RoleScopeResource realmLevel();
@Path("applications/{appName}") @Path("clients/{clientId}")
public RoleScopeResource applicationLevel(@PathParam("appName") String appName); public RoleScopeResource clientLevel(@PathParam("clientId") String clientId);
} }

View file

@ -66,8 +66,7 @@ public class TokenManager {
Form form = new Form() Form form = new Form()
.param("grant_type", "refresh_token") .param("grant_type", "refresh_token")
.param("username", config.getUsername()) .param("refresh_token", currentToken.getRefreshToken());
.param("password", config.getPassword());
if(config.isPublicClient()){ if(config.isPublicClient()){
form.param("client_id", config.getClientId()); form.param("client_id", config.getClientId());