public realm info update

This commit is contained in:
Bill Burke 2014-02-28 09:52:53 -05:00
parent 236d67f78d
commit 11559cba50
4 changed files with 35 additions and 74 deletions

View file

@ -15,34 +15,22 @@ import java.security.PublicKey;
*/ */
public class PublishedRealmRepresentation { public class PublishedRealmRepresentation {
protected String realm; protected String realm;
protected String self;
@JsonProperty("public_key") @JsonProperty("public_key")
protected String publicKeyPem; protected String publicKeyPem;
@JsonProperty("authorization") @JsonProperty("token-service")
protected String authorizationUrl; protected String tokenServiceUrl;
@JsonProperty("codes") @JsonProperty("account-service")
protected String codeUrl; protected String accountServiceUrl;
@JsonProperty("grants") @JsonProperty("admin-api")
protected String grantUrl; protected String adminApiUrl;
@JsonProperty("admin-role")
protected String adminRole;
@JsonIgnore @JsonIgnore
protected volatile transient PublicKey publicKey; protected volatile transient PublicKey publicKey;
public String getAdminRole() {
return adminRole;
}
public void setAdminRole(String adminRole) {
this.adminRole = adminRole;
}
public String getRealm() { public String getRealm() {
return realm; return realm;
} }
@ -51,14 +39,6 @@ public class PublishedRealmRepresentation {
this.realm = realm; this.realm = realm;
} }
public String getSelf() {
return self;
}
public void setSelf(String self) {
this.self = self;
}
public String getPublicKeyPem() { public String getPublicKeyPem() {
return publicKeyPem; return publicKeyPem;
} }
@ -97,28 +77,27 @@ public class PublishedRealmRepresentation {
this.publicKeyPem = PemUtils.removeBeginEnd(s); this.publicKeyPem = PemUtils.removeBeginEnd(s);
} }
public String getTokenServiceUrl() {
public String getAuthorizationUrl() { return tokenServiceUrl;
return authorizationUrl;
} }
public void setAuthorizationUrl(String authorizationUrl) { public void setTokenServiceUrl(String tokenServiceUrl) {
this.authorizationUrl = authorizationUrl; this.tokenServiceUrl = tokenServiceUrl;
} }
public String getCodeUrl() { public String getAccountServiceUrl() {
return codeUrl; return accountServiceUrl;
} }
public void setCodeUrl(String codeUrl) { public void setAccountServiceUrl(String accountServiceUrl) {
this.codeUrl = codeUrl; this.accountServiceUrl = accountServiceUrl;
} }
public String getGrantUrl() { public String getAdminApiUrl() {
return grantUrl; return adminApiUrl;
} }
public void setGrantUrl(String grantUrl) { public void setAdminApiUrl(String adminApiUrl) {
this.grantUrl = grantUrl; this.adminApiUrl = adminApiUrl;
} }
} }

View file

@ -74,6 +74,12 @@ public class AccountService {
this.authManager = new AppAuthManager("KEYCLOAK_ACCOUNT_IDENTITY", tokenManager); this.authManager = new AppAuthManager("KEYCLOAK_ACCOUNT_IDENTITY", tokenManager);
} }
public static UriBuilder accountServiceBaseUrl(UriInfo uriInfo) {
UriBuilder base = uriInfo.getBaseUriBuilder().path(RealmsResource.class).path(RealmsResource.class, "getAccountService");
return base;
}
private Response forwardToPage(String path, AccountPages page) { private Response forwardToPage(String path, AccountPages page) {
Auth auth = getAuth(false); Auth auth = getAuth(false);
if (auth != null) { if (auth != null) {

View file

@ -4,6 +4,7 @@ import org.jboss.resteasy.annotations.cache.NoCache;
import org.jboss.resteasy.logging.Logger; import org.jboss.resteasy.logging.Logger;
import org.keycloak.models.RealmModel; import org.keycloak.models.RealmModel;
import org.keycloak.representations.idm.PublishedRealmRepresentation; import org.keycloak.representations.idm.PublishedRealmRepresentation;
import org.keycloak.services.resources.admin.AdminService;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.Path; import javax.ws.rs.Path;
@ -19,7 +20,6 @@ import javax.ws.rs.core.UriInfo;
*/ */
public class PublicRealmResource { public class PublicRealmResource {
protected static final Logger logger = Logger.getLogger(PublicRealmResource.class); protected static final Logger logger = Logger.getLogger(PublicRealmResource.class);
public static final String ADMIN_ROLE = "$REALM-ADMIN$";
@Context @Context
protected UriInfo uriInfo; protected UriInfo uriInfo;
@ -30,12 +30,6 @@ public class PublicRealmResource {
this.realm = realm; this.realm = realm;
} }
public static UriBuilder realmUrl(UriInfo uriInfo) {
UriBuilder base = uriInfo.getBaseUriBuilder()
.path(RealmsResource.class).path(RealmsResource.class, "getRealmResource");
return base;
}
@GET @GET
@NoCache @NoCache
@Produces("application/json") @Produces("application/json")
@ -43,38 +37,13 @@ public class PublicRealmResource {
return realmRep(realm, uriInfo); return realmRep(realm, uriInfo);
} }
@GET
@NoCache
@Path("html")
@Produces("text/html")
public String getRealmHtml(@PathParam("realm") String id) {
StringBuffer html = new StringBuffer();
String authUri = TokenService.loginPageUrl(uriInfo).build(realm.getName()).toString();
String codeUri = TokenService.accessCodeToTokenUrl(uriInfo).build(realm.getName()).toString();
String grantUrl = TokenService.grantAccessTokenUrl(uriInfo).build(realm.getName()).toString();
html.append("<html><body><h1>Realm: ").append(realm.getName()).append("</h1>");
html.append("<p>auth: ").append(authUri).append("</p>");
html.append("<p>code: ").append(codeUri).append("</p>");
html.append("<p>grant: ").append(grantUrl).append("</p>");
html.append("<p>public key: ").append(realm.getPublicKeyPem()).append("</p>");
html.append("</body></html>");
return html.toString();
}
public static PublishedRealmRepresentation realmRep(RealmModel realm, UriInfo uriInfo) { public static PublishedRealmRepresentation realmRep(RealmModel realm, UriInfo uriInfo) {
PublishedRealmRepresentation rep = new PublishedRealmRepresentation(); PublishedRealmRepresentation rep = new PublishedRealmRepresentation();
rep.setRealm(realm.getName()); rep.setRealm(realm.getName());
rep.setSelf(realmUrl(uriInfo).build(realm.getId()).toString()); rep.setTokenServiceUrl(TokenService.tokenServiceBaseUrl(uriInfo).build(realm.getId()).toString());
rep.setAccountServiceUrl(AccountService.accountServiceBaseUrl(uriInfo).build(realm.getId()).toString());
rep.setAdminApiUrl(AdminService.adminApiUrl(uriInfo).build(realm.getId()).toString());
rep.setPublicKeyPem(realm.getPublicKeyPem()); rep.setPublicKeyPem(realm.getPublicKeyPem());
rep.setAdminRole(ADMIN_ROLE);
rep.setAuthorizationUrl(TokenService.loginPageUrl(uriInfo).build(realm.getName()).toString());
rep.setCodeUrl(TokenService.accessCodeToTokenUrl(uriInfo).build(realm.getName()).toString());
rep.setGrantUrl(TokenService.grantAccessTokenUrl(uriInfo).build(realm.getName()).toString());
return rep; return rep;
} }

View file

@ -17,6 +17,7 @@ import org.keycloak.services.managers.AppAuthManager;
import org.keycloak.services.managers.Auth; import org.keycloak.services.managers.Auth;
import org.keycloak.services.managers.RealmManager; import org.keycloak.services.managers.RealmManager;
import org.keycloak.services.managers.TokenManager; import org.keycloak.services.managers.TokenManager;
import org.keycloak.services.resources.RealmsResource;
import org.keycloak.services.resources.TokenService; import org.keycloak.services.resources.TokenService;
import org.keycloak.services.resources.flows.Flows; import org.keycloak.services.resources.flows.Flows;
@ -75,6 +76,12 @@ public class AdminService {
this.authManager = new AppAuthManager("KEYCLOAK_ADMIN_CONSOLE_IDENTITY", tokenManager); this.authManager = new AppAuthManager("KEYCLOAK_ADMIN_CONSOLE_IDENTITY", tokenManager);
} }
public static UriBuilder adminApiUrl(UriInfo uriInfo) {
UriBuilder base = uriInfo.getBaseUriBuilder().path(AdminService.class).path(AdminService.class, "getRealmsAdmin").path(RealmsAdminResource.class, "getRealmAdmin");
return base;
}
public static class WhoAmI { public static class WhoAmI {
protected String userId; protected String userId;
protected String displayName; protected String displayName;