KEYCLOAK-1187 First round: Combined ApplicationModel and OAuthClientModel into ClientModel. Removed OAuth Clients from Admin console and renamed Applications to Clients.
This commit is contained in:
1 parent
b92a178142
commit
6fbc0975c0
196 files changed
+6069
-9521
No files matched your search
@@ -1,24 +1,18 @@
|
||||
package org.keycloak.protocol;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
import org.keycloak.Config;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.KeycloakSessionFactory;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.provider.ProviderEvent;
|
||||
import org.keycloak.provider.ProviderEventListener;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public abstract class AbstractLoginProtocolFactory implements LoginProtocolFactory {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(AbstractLoginProtocolFactory.class);
|
||||
|
||||
@Override
|
||||
public void init(Config.Scope config) {
|
||||
}
|
||||
@@ -34,8 +28,6 @@ public abstract class AbstractLoginProtocolFactory implements LoginProtocolFacto
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected abstract void addDefaults(ClientModel realm);
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.keycloak.OAuth2Constants;
|
||||
import org.keycloak.events.Details;
|
||||
import org.keycloak.events.EventBuilder;
|
||||
import org.keycloak.events.EventType;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.ClientSessionModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmModel;
|
||||
@@ -164,8 +164,8 @@ public class OIDCLoginProtocol implements LoginProtocol {
|
||||
|
||||
@Override
|
||||
public void backchannelLogout(UserSessionModel userSession, ClientSessionModel clientSession) {
|
||||
if (!(clientSession.getClient() instanceof ApplicationModel)) return;
|
||||
ApplicationModel app = (ApplicationModel)clientSession.getClient();
|
||||
if (!(clientSession.getClient() instanceof ClientModel)) return;
|
||||
ClientModel app = (ClientModel)clientSession.getClient();
|
||||
ApacheHttpClient4Executor executor = ResourceAdminManager.createExecutor();
|
||||
|
||||
try {
|
||||
|
||||
@@ -8,7 +8,6 @@ import org.keycloak.events.EventBuilder;
|
||||
import org.keycloak.jose.jws.JWSBuilder;
|
||||
import org.keycloak.jose.jws.JWSInput;
|
||||
import org.keycloak.jose.jws.crypto.RSAProvider;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.ClientSessionModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
@@ -233,8 +232,8 @@ public class TokenManager {
|
||||
if (client.isFullScopeAllowed()) return roleMappings;
|
||||
|
||||
Set<RoleModel> scopeMappings = client.getScopeMappings();
|
||||
if (client instanceof ApplicationModel) {
|
||||
scopeMappings.addAll(((ApplicationModel) client).getRoles());
|
||||
if (client instanceof ClientModel) {
|
||||
scopeMappings.addAll(((ClientModel) client).getRoles());
|
||||
}
|
||||
|
||||
for (RoleModel role : roleMappings) {
|
||||
@@ -339,10 +338,10 @@ public class TokenManager {
|
||||
return;
|
||||
|
||||
} else {
|
||||
ApplicationModel app = (ApplicationModel) role.getContainer();
|
||||
access = token.getResourceAccess(app.getName());
|
||||
ClientModel app = (ClientModel) role.getContainer();
|
||||
access = token.getResourceAccess(app.getClientId());
|
||||
if (access == null) {
|
||||
access = token.addAccess(app.getName());
|
||||
access = token.addAccess(app.getClientId());
|
||||
if (app.isSurrogateAuthRequired()) access.verifyCaller(true);
|
||||
} else if (access.isUserInRole(role.getName())) return;
|
||||
|
||||
|
||||
+2
-3
@@ -11,7 +11,6 @@ import org.keycloak.events.Errors;
|
||||
import org.keycloak.events.EventBuilder;
|
||||
import org.keycloak.events.EventType;
|
||||
import org.keycloak.login.LoginFormsProvider;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.ClientSessionModel;
|
||||
import org.keycloak.models.IdentityProviderModel;
|
||||
@@ -168,13 +167,13 @@ public class AuthorizationEndpoint {
|
||||
|
||||
event.client(clientId);
|
||||
|
||||
client = realm.findClient(clientId);
|
||||
client = realm.getClientByClientId(clientId);
|
||||
if (client == null) {
|
||||
event.error(Errors.CLIENT_NOT_FOUND);
|
||||
throw new ErrorPageException(session, realm, uriInfo, headers, Messages.CLIENT_NOT_FOUND );
|
||||
}
|
||||
|
||||
if ((client instanceof ApplicationModel) && ((ApplicationModel) client).isBearerOnly()) {
|
||||
if ((client instanceof ClientModel) && ((ClientModel) client).isBearerOnly()) {
|
||||
event.error(Errors.NOT_ALLOWED);
|
||||
throw new ErrorPageException(session, realm, uriInfo, headers, Messages.BEARER_ONLY );
|
||||
}
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ public class LoginStatusIframeEndpoint {
|
||||
throw new BadRequestException("Invalid origin");
|
||||
}
|
||||
|
||||
ClientModel client = realm.findClient(client_id);
|
||||
ClientModel client = realm.getClientByClientId(client_id);
|
||||
if (client == null) {
|
||||
throw new NotFoundException("could not find client");
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import org.keycloak.events.Details;
|
||||
import org.keycloak.events.Errors;
|
||||
import org.keycloak.events.EventBuilder;
|
||||
import org.keycloak.events.EventType;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmModel;
|
||||
@@ -191,7 +190,7 @@ public class LogoutEndpoint {
|
||||
private ClientModel authorizeClient(String authorizationHeader, MultivaluedMap<String, String> formData, EventBuilder event) {
|
||||
ClientModel client = AuthorizeClientUtil.authorizeClient(authorizationHeader, formData, event, realm);
|
||||
|
||||
if ( (client instanceof ApplicationModel) && ((ApplicationModel)client).isBearerOnly()) {
|
||||
if ( (client instanceof ClientModel) && ((ClientModel)client).isBearerOnly()) {
|
||||
throw new ErrorResponseException("invalid_client", "Bearer-only not allowed", Response.Status.BAD_REQUEST);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import org.keycloak.events.Details;
|
||||
import org.keycloak.events.Errors;
|
||||
import org.keycloak.events.EventBuilder;
|
||||
import org.keycloak.events.EventType;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.ClientSessionModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
@@ -20,7 +19,6 @@ import org.keycloak.models.UserSessionModel;
|
||||
import org.keycloak.models.UserSessionProvider;
|
||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||
import org.keycloak.protocol.oidc.OIDCLoginProtocol;
|
||||
import org.keycloak.protocol.oidc.OIDCLoginProtocolService;
|
||||
import org.keycloak.protocol.oidc.TokenManager;
|
||||
import org.keycloak.protocol.oidc.utils.AuthorizeClientUtil;
|
||||
import org.keycloak.representations.AccessToken;
|
||||
@@ -31,7 +29,6 @@ import org.keycloak.services.managers.ClientSessionCode;
|
||||
import org.keycloak.services.resources.Cors;
|
||||
import org.keycloak.services.resources.flows.Urls;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.OPTIONS;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.core.Context;
|
||||
@@ -147,7 +144,7 @@ public class TokenEndpoint {
|
||||
String authorizationHeader = headers.getRequestHeaders().getFirst(HttpHeaders.AUTHORIZATION);
|
||||
client = AuthorizeClientUtil.authorizeClient(authorizationHeader, formParams, event, realm);
|
||||
|
||||
if ((client instanceof ApplicationModel) && ((ApplicationModel) client).isBearerOnly()) {
|
||||
if ((client instanceof ClientModel) && ((ClientModel) client).isBearerOnly()) {
|
||||
throw new ErrorResponseException("invalid_client", "Bearer-only not allowed", Response.Status.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ public class UserInfoEndpoint {
|
||||
}
|
||||
|
||||
UserSessionModel userSession = session.sessions().getUserSession(realm, token.getSessionState());
|
||||
ClientModel clientModel = realm.findClient(token.getIssuedFor());
|
||||
ClientModel clientModel = realm.getClientByClientId(token.getIssuedFor());
|
||||
UserModel userModel = userSession.getUser();
|
||||
AccessToken userInfo = new AccessToken();
|
||||
tokenManager.transformAccessToken(session, userInfo, realm, clientModel, userModel, userSession, null);
|
||||
|
||||
@@ -44,7 +44,7 @@ public class AuthorizeClientUtil {
|
||||
|
||||
event.client(client_id);
|
||||
|
||||
ClientModel client = realm.findClient(client_id);
|
||||
ClientModel client = realm.getClientByClientId(client_id);
|
||||
if (client == null) {
|
||||
Map<String, String> error = new HashMap<String, String>();
|
||||
error.put(OAuth2Constants.ERROR, "invalid_client");
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package org.keycloak.protocol.oidc.utils;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.Constants;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.services.resources.flows.Urls;
|
||||
|
||||
@@ -46,12 +44,7 @@ public class RedirectUtils {
|
||||
|
||||
private static Set<String> getValidateRedirectUris(RealmModel realm) {
|
||||
Set<String> redirects = new HashSet<String>();
|
||||
for (ApplicationModel client : realm.getApplications()) {
|
||||
for (String redirect : client.getRedirectUris()) {
|
||||
redirects.add(redirect);
|
||||
}
|
||||
}
|
||||
for (OAuthClientModel client : realm.getOAuthClients()) {
|
||||
for (ClientModel client : realm.getClients()) {
|
||||
for (String redirect : client.getRedirectUris()) {
|
||||
redirects.add(redirect);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import org.jboss.logging.Logger;
|
||||
import org.keycloak.Config;
|
||||
import org.keycloak.enums.SslRequired;
|
||||
import org.keycloak.models.AdminRoles;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.Constants;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.KeycloakSessionFactory;
|
||||
@@ -71,7 +71,7 @@ public class ApplianceBootstrap {
|
||||
RoleModel adminRole = realm.getRole(AdminRoles.ADMIN);
|
||||
adminUser.grantRole(adminRole);
|
||||
|
||||
ApplicationModel accountApp = realm.getApplicationNameMap().get(Constants.ACCOUNT_MANAGEMENT_APP);
|
||||
ClientModel accountApp = realm.getClientNameMap().get(Constants.ACCOUNT_MANAGEMENT_APP);
|
||||
for (String r : accountApp.getDefaultRoles()) {
|
||||
adminUser.grantRole(accountApp.getRole(r));
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.keycloak.services.managers;
|
||||
import org.codehaus.jackson.annotate.JsonProperty;
|
||||
import org.codehaus.jackson.annotate.JsonPropertyOrder;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.UserSessionProvider;
|
||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||
@@ -36,12 +36,12 @@ public class ApplicationManager {
|
||||
public ApplicationManager() {
|
||||
}
|
||||
|
||||
public ApplicationModel createApplication(RealmModel realm, String name) {
|
||||
public ClientModel createApplication(RealmModel realm, String name) {
|
||||
return KeycloakModelUtils.createApplication(realm, name);
|
||||
}
|
||||
|
||||
public boolean removeApplication(RealmModel realm, ApplicationModel application) {
|
||||
if (realm.removeApplication(application.getId())) {
|
||||
public boolean removeApplication(RealmModel realm, ClientModel application) {
|
||||
if (realm.removeClient(application.getId())) {
|
||||
UserSessionProvider sessions = realmManager.getSession().sessions();
|
||||
if (sessions != null) {
|
||||
sessions.onClientRemoved(realm, application);
|
||||
@@ -52,7 +52,7 @@ public class ApplicationManager {
|
||||
}
|
||||
}
|
||||
|
||||
public Set<String> validateRegisteredNodes(ApplicationModel application) {
|
||||
public Set<String> validateRegisteredNodes(ClientModel application) {
|
||||
Map<String, Integer> registeredNodes = application.getRegisteredNodes();
|
||||
if (registeredNodes == null || registeredNodes.isEmpty()) {
|
||||
return Collections.emptySet();
|
||||
@@ -141,22 +141,22 @@ public class ApplicationManager {
|
||||
}
|
||||
|
||||
|
||||
public InstallationAdapterConfig toInstallationRepresentation(RealmModel realmModel, ApplicationModel applicationModel, URI baseUri) {
|
||||
public InstallationAdapterConfig toInstallationRepresentation(RealmModel realmModel, ClientModel clientModel, URI baseUri) {
|
||||
InstallationAdapterConfig rep = new InstallationAdapterConfig();
|
||||
rep.setRealm(realmModel.getName());
|
||||
rep.setRealmKey(realmModel.getPublicKeyPem());
|
||||
rep.setSslRequired(realmModel.getSslRequired().name().toLowerCase());
|
||||
|
||||
if (applicationModel.isPublicClient() && !applicationModel.isBearerOnly()) rep.setPublicClient(true);
|
||||
if (applicationModel.isBearerOnly()) rep.setBearerOnly(true);
|
||||
if (!applicationModel.isBearerOnly()) rep.setAuthServerUrl(baseUri.toString());
|
||||
if (applicationModel.getRoles().size() > 0) rep.setUseResourceRoleMappings(true);
|
||||
if (clientModel.isPublicClient() && !clientModel.isBearerOnly()) rep.setPublicClient(true);
|
||||
if (clientModel.isBearerOnly()) rep.setBearerOnly(true);
|
||||
if (!clientModel.isBearerOnly()) rep.setAuthServerUrl(baseUri.toString());
|
||||
if (clientModel.getRoles().size() > 0) rep.setUseResourceRoleMappings(true);
|
||||
|
||||
rep.setResource(applicationModel.getName());
|
||||
rep.setResource(clientModel.getClientId());
|
||||
|
||||
if (!applicationModel.isBearerOnly() && !applicationModel.isPublicClient()) {
|
||||
if (!clientModel.isBearerOnly() && !clientModel.isPublicClient()) {
|
||||
Map<String, String> creds = new HashMap<String, String>();
|
||||
String cred = applicationModel.getSecret();
|
||||
String cred = clientModel.getSecret();
|
||||
creds.put(CredentialRepresentation.SECRET, cred);
|
||||
rep.setCredentials(creds);
|
||||
}
|
||||
@@ -164,27 +164,27 @@ public class ApplicationManager {
|
||||
return rep;
|
||||
}
|
||||
|
||||
public String toJBossSubsystemConfig(RealmModel realmModel, ApplicationModel applicationModel, URI baseUri) {
|
||||
public String toJBossSubsystemConfig(RealmModel realmModel, ClientModel clientModel, URI baseUri) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("<secure-deployment name=\"WAR MODULE NAME.war\">\n");
|
||||
buffer.append(" <realm>").append(realmModel.getName()).append("</realm>\n");
|
||||
buffer.append(" <realm-public-key>").append(realmModel.getPublicKeyPem()).append("</realm-public-key>\n");
|
||||
if (applicationModel.isBearerOnly()){
|
||||
if (clientModel.isBearerOnly()){
|
||||
buffer.append(" <bearer-only>true</bearer-only>\n");
|
||||
|
||||
} else {
|
||||
buffer.append(" <auth-server-url>").append(baseUri.toString()).append("</auth-server-url>\n");
|
||||
if (applicationModel.isPublicClient() && !applicationModel.isBearerOnly()) {
|
||||
if (clientModel.isPublicClient() && !clientModel.isBearerOnly()) {
|
||||
buffer.append(" <public-client>true</public-client>\n");
|
||||
}
|
||||
}
|
||||
buffer.append(" <ssl-required>").append(realmModel.getSslRequired().name()).append("</ssl-required>\n");
|
||||
buffer.append(" <resource>").append(applicationModel.getName()).append("</resource>\n");
|
||||
String cred = applicationModel.getSecret();
|
||||
if (!applicationModel.isBearerOnly() && !applicationModel.isPublicClient()) {
|
||||
buffer.append(" <resource>").append(clientModel.getClientId()).append("</resource>\n");
|
||||
String cred = clientModel.getSecret();
|
||||
if (!clientModel.isBearerOnly() && !clientModel.isPublicClient()) {
|
||||
buffer.append(" <credential name=\"secret\">").append(cred).append("</credential>\n");
|
||||
}
|
||||
if (applicationModel.getRoles().size() > 0) {
|
||||
if (clientModel.getRoles().size() > 0) {
|
||||
buffer.append(" <use-resource-role-mappings>true</use-resource-role-mappings>\n");
|
||||
}
|
||||
buffer.append("</secure-deployment>\n");
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.keycloak.services.managers;
|
||||
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.ClientSessionModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
@@ -81,16 +80,16 @@ public class Auth {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasAppRole(ApplicationModel app, String role) {
|
||||
public boolean hasAppRole(ClientModel app, String role) {
|
||||
if (cookie) {
|
||||
return user.hasRole(app.getRole(role));
|
||||
} else {
|
||||
AccessToken.Access access = token.getResourceAccess(app.getName());
|
||||
AccessToken.Access access = token.getResourceAccess(app.getClientId());
|
||||
return access != null && access.isUserInRole(role);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasOneOfAppRole(ApplicationModel app, String... roles) {
|
||||
public boolean hasOneOfAppRole(ClientModel app, String... roles) {
|
||||
for (String r : roles) {
|
||||
if (hasAppRole(app, r)) {
|
||||
return true;
|
||||
|
||||
@@ -12,7 +12,6 @@ import org.keycloak.events.EventBuilder;
|
||||
import org.keycloak.events.EventType;
|
||||
import org.keycloak.jose.jws.JWSBuilder;
|
||||
import org.keycloak.login.LoginFormsProvider;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.ClientSessionModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
@@ -111,7 +110,7 @@ public class AuthenticationManager {
|
||||
|
||||
for (ClientSessionModel clientSession : userSession.getClientSessions()) {
|
||||
ClientModel client = clientSession.getClient();
|
||||
if (client instanceof ApplicationModel && !client.isFrontchannelLogout() && clientSession.getAction() != ClientSessionModel.Action.LOGGED_OUT) {
|
||||
if (client instanceof ClientModel && !client.isFrontchannelLogout() && clientSession.getAction() != ClientSessionModel.Action.LOGGED_OUT) {
|
||||
String authMethod = clientSession.getAuthMethod();
|
||||
if (authMethod == null) continue; // must be a keycloak service like account
|
||||
LoginProtocol protocol = session.getProvider(LoginProtocol.class, authMethod);
|
||||
@@ -145,7 +144,7 @@ public class AuthenticationManager {
|
||||
redirectClients.add(clientSession);
|
||||
continue;
|
||||
}
|
||||
if (client instanceof ApplicationModel && !client.isFrontchannelLogout()) {
|
||||
if (client instanceof ClientModel && !client.isFrontchannelLogout()) {
|
||||
String authMethod = clientSession.getAuthMethod();
|
||||
if (authMethod == null) continue; // must be a keycloak service like account
|
||||
LoginProtocol protocol = session.getProvider(LoginProtocol.class, authMethod);
|
||||
@@ -381,13 +380,9 @@ public class AuthenticationManager {
|
||||
isEmailVerificationRequired(realm, user);
|
||||
ClientModel client = clientSession.getClient();
|
||||
|
||||
boolean isResource = client instanceof ApplicationModel;
|
||||
ClientSessionCode accessCode = new ClientSessionCode(realm, clientSession);
|
||||
|
||||
|
||||
logger.debugv("processAccessCode: isResource: {0}", isResource);
|
||||
logger.debugv("processAccessCode: go to oauth page?: {0}",
|
||||
!isResource);
|
||||
logger.debugv("processAccessCode: go to oauth page?: {0}", client.isConsentRequired());
|
||||
|
||||
event.detail(Details.CODE_ID, clientSession.getId());
|
||||
|
||||
@@ -417,7 +412,7 @@ public class AuthenticationManager {
|
||||
}
|
||||
}
|
||||
|
||||
if (!isResource) {
|
||||
if (client.isConsentRequired()) {
|
||||
accessCode.setAction(ClientSessionModel.Action.OAUTH_GRANT);
|
||||
|
||||
List<RoleModel> realmRoles = new LinkedList<RoleModel>();
|
||||
@@ -426,7 +421,7 @@ public class AuthenticationManager {
|
||||
if (r.getContainer() instanceof RealmModel) {
|
||||
realmRoles.add(r);
|
||||
} else {
|
||||
resourceRoles.add(((ApplicationModel) r.getContainer()).getName(), r);
|
||||
resourceRoles.add(((ClientModel) r.getContainer()).getClientId(), r);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
package org.keycloak.services.managers;
|
||||
|
||||
import org.codehaus.jackson.annotate.JsonProperty;
|
||||
import org.codehaus.jackson.annotate.JsonPropertyOrder;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.UserSessionProvider;
|
||||
import org.keycloak.representations.adapters.config.BaseRealmConfig;
|
||||
import org.keycloak.representations.idm.CredentialRepresentation;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public class OAuthClientManager {
|
||||
|
||||
private RealmManager realmManager;
|
||||
|
||||
public OAuthClientManager() {
|
||||
}
|
||||
|
||||
public OAuthClientManager(RealmManager realmManager) {
|
||||
this.realmManager = realmManager;
|
||||
}
|
||||
|
||||
public boolean removeClient(RealmModel realm, OAuthClientModel client) {
|
||||
if (realm.removeOAuthClient(client.getId())) {
|
||||
UserSessionProvider sessions = realmManager.getSession().sessions();
|
||||
if (sessions != null) {
|
||||
realmManager.getSession().sessions().onClientRemoved(realm, client);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@JsonPropertyOrder({"realm", "realm-public-key", "auth-server-url", "ssl-required",
|
||||
"resource", "public-client", "credentials"})
|
||||
public static class InstallationAdapterConfig extends BaseRealmConfig {
|
||||
@JsonProperty("public-client")
|
||||
protected Boolean publicClient;
|
||||
@JsonProperty("resource")
|
||||
protected String resource;
|
||||
@JsonProperty("credentials")
|
||||
protected Map<String, String> credentials;
|
||||
|
||||
public String getResource() {
|
||||
return resource;
|
||||
}
|
||||
|
||||
public void setResource(String resource) {
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
public Map<String, String> getCredentials() {
|
||||
return credentials;
|
||||
}
|
||||
|
||||
public void setCredentials(Map<String, String> credentials) {
|
||||
this.credentials = credentials;
|
||||
}
|
||||
|
||||
public Boolean getPublicClient() {
|
||||
return publicClient;
|
||||
}
|
||||
|
||||
public void setPublicClient(Boolean publicClient) {
|
||||
this.publicClient = publicClient;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public InstallationAdapterConfig toInstallationRepresentation(RealmModel realmModel, OAuthClientModel model, URI baseUri) {
|
||||
InstallationAdapterConfig rep = new InstallationAdapterConfig();
|
||||
rep.setRealm(realmModel.getName());
|
||||
rep.setRealmKey(realmModel.getPublicKeyPem());
|
||||
rep.setSslRequired(realmModel.getSslRequired().name().toLowerCase());
|
||||
rep.setAuthServerUrl(baseUri.toString());
|
||||
if (model.isPublicClient()) rep.setPublicClient(true);
|
||||
|
||||
rep.setResource(model.getClientId());
|
||||
|
||||
if (!model.isPublicClient()) {
|
||||
Map<String, String> creds = new HashMap<String, String>();
|
||||
creds.put(CredentialRepresentation.SECRET, model.getSecret());
|
||||
rep.setCredentials(creds);
|
||||
}
|
||||
|
||||
return rep;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import org.keycloak.enums.SslRequired;
|
||||
import org.keycloak.exportimport.util.ImportUtils;
|
||||
import org.keycloak.models.AccountRoles;
|
||||
import org.keycloak.models.AdminRoles;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.BrowserSecurityHeaders;
|
||||
import org.keycloak.models.Constants;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
@@ -25,7 +25,6 @@ import org.keycloak.timer.TimerProvider;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -91,7 +90,7 @@ public class RealmManager {
|
||||
}
|
||||
|
||||
protected void setupAdminConsole(RealmModel realm) {
|
||||
ApplicationModel adminConsole = realm.getApplicationByName(Constants.ADMIN_CONSOLE_APPLICATION);
|
||||
ClientModel adminConsole = realm.getClientByClientId(Constants.ADMIN_CONSOLE_APPLICATION);
|
||||
if (adminConsole == null) adminConsole = new ApplicationManager(this).createApplication(realm, Constants.ADMIN_CONSOLE_APPLICATION);
|
||||
String baseUrl = contextPath + "/admin/" + realm.getName() + "/console";
|
||||
adminConsole.setBaseUrl(baseUrl + "/index.html");
|
||||
@@ -105,7 +104,7 @@ public class RealmManager {
|
||||
adminRole = realm.getRole(AdminRoles.ADMIN);
|
||||
} else {
|
||||
String realmAdminApplicationName = getRealmAdminApplicationName(realm);
|
||||
ApplicationModel realmAdminApp = realm.getApplicationByName(realmAdminApplicationName);
|
||||
ClientModel realmAdminApp = realm.getClientByClientId(realmAdminApplicationName);
|
||||
adminRole = realmAdminApp.getRole(AdminRoles.REALM_ADMIN);
|
||||
}
|
||||
adminConsole.addScopeMapping(adminRole);
|
||||
@@ -178,7 +177,7 @@ public class RealmManager {
|
||||
ApplicationManager applicationManager = new ApplicationManager(new RealmManager(session));
|
||||
|
||||
String realmAdminApplicationName = getRealmAdminApplicationName(realm);
|
||||
ApplicationModel realmAdminApp = realm.getApplicationByName(realmAdminApplicationName);
|
||||
ClientModel realmAdminApp = realm.getClientByClientId(realmAdminApplicationName);
|
||||
if (realmAdminApp == null) {
|
||||
realmAdminApp = applicationManager.createApplication(realm, realmAdminApplicationName);
|
||||
}
|
||||
@@ -196,7 +195,7 @@ public class RealmManager {
|
||||
|
||||
|
||||
private void setupAccountManagement(RealmModel realm) {
|
||||
ApplicationModel application = realm.getApplicationNameMap().get(Constants.ACCOUNT_MANAGEMENT_APP);
|
||||
ClientModel application = realm.getClientNameMap().get(Constants.ACCOUNT_MANAGEMENT_APP);
|
||||
if (application == null) {
|
||||
application = new ApplicationManager(this).createApplication(realm, Constants.ACCOUNT_MANAGEMENT_APP);
|
||||
application.setEnabled(true);
|
||||
|
||||
@@ -7,7 +7,6 @@ import org.jboss.resteasy.client.ClientResponse;
|
||||
import org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor;
|
||||
import org.keycloak.TokenIdGenerator;
|
||||
import org.keycloak.constants.AdapterConstants;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.ClientSessionModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
@@ -58,7 +57,7 @@ public class ResourceAdminManager {
|
||||
|
||||
}
|
||||
|
||||
public static String getManagementUrl(URI requestUri, ApplicationModel application) {
|
||||
public static String getManagementUrl(URI requestUri, ClientModel application) {
|
||||
String mgmtUrl = application.getManagementUrl();
|
||||
if (mgmtUrl == null || mgmtUrl.equals("")) {
|
||||
return null;
|
||||
@@ -73,7 +72,7 @@ public class ResourceAdminManager {
|
||||
|
||||
// For non-cluster setup, return just single configured managementUrls
|
||||
// For cluster setup, return the management Urls corresponding to all registered cluster nodes
|
||||
private List<String> getAllManagementUrls(URI requestUri, ApplicationModel application) {
|
||||
private List<String> getAllManagementUrls(URI requestUri, ClientModel application) {
|
||||
String baseMgmtUrl = getManagementUrl(requestUri, application);
|
||||
if (baseMgmtUrl == null) {
|
||||
return Collections.emptyList();
|
||||
@@ -106,7 +105,7 @@ public class ResourceAdminManager {
|
||||
|
||||
try {
|
||||
// Map from "app" to clientSessions for this app
|
||||
MultivaluedHashMap<ApplicationModel, ClientSessionModel> clientSessions = new MultivaluedHashMap<ApplicationModel, ClientSessionModel>();
|
||||
MultivaluedHashMap<ClientModel, ClientSessionModel> clientSessions = new MultivaluedHashMap<ClientModel, ClientSessionModel>();
|
||||
for (UserSessionModel userSession : userSessions) {
|
||||
putClientSessions(clientSessions, userSession);
|
||||
}
|
||||
@@ -114,7 +113,7 @@ public class ResourceAdminManager {
|
||||
logger.debugv("logging out {0} resources ", clientSessions.size());
|
||||
//logger.infov("logging out resources: {0}", clientSessions);
|
||||
|
||||
for (Map.Entry<ApplicationModel, List<ClientSessionModel>> entry : clientSessions.entrySet()) {
|
||||
for (Map.Entry<ClientModel, List<ClientSessionModel>> entry : clientSessions.entrySet()) {
|
||||
logoutClientSessions(requestUri, realm, entry.getKey(), entry.getValue(), executor);
|
||||
}
|
||||
} finally {
|
||||
@@ -122,23 +121,21 @@ public class ResourceAdminManager {
|
||||
}
|
||||
}
|
||||
|
||||
private void putClientSessions(MultivaluedHashMap<ApplicationModel, ClientSessionModel> clientSessions, UserSessionModel userSession) {
|
||||
private void putClientSessions(MultivaluedHashMap<ClientModel, ClientSessionModel> clientSessions, UserSessionModel userSession) {
|
||||
for (ClientSessionModel clientSession : userSession.getClientSessions()) {
|
||||
ClientModel client = clientSession.getClient();
|
||||
if (client instanceof ApplicationModel) {
|
||||
clientSessions.add((ApplicationModel)client, clientSession);
|
||||
}
|
||||
clientSessions.add(client, clientSession);
|
||||
}
|
||||
}
|
||||
|
||||
public void logoutUserFromApplication(URI requestUri, RealmModel realm, ApplicationModel resource, UserModel user, KeycloakSession session) {
|
||||
public void logoutUserFromApplication(URI requestUri, RealmModel realm, ClientModel resource, UserModel user, KeycloakSession session) {
|
||||
ApacheHttpClient4Executor executor = createExecutor();
|
||||
|
||||
try {
|
||||
List<UserSessionModel> userSessions = session.sessions().getUserSessions(realm, user);
|
||||
List<ClientSessionModel> ourAppClientSessions = null;
|
||||
if (userSessions != null) {
|
||||
MultivaluedHashMap<ApplicationModel, ClientSessionModel> clientSessions = new MultivaluedHashMap<ApplicationModel, ClientSessionModel>();
|
||||
MultivaluedHashMap<ClientModel, ClientSessionModel> clientSessions = new MultivaluedHashMap<ClientModel, ClientSessionModel>();
|
||||
for (UserSessionModel userSession : userSessions) {
|
||||
putClientSessions(clientSessions, userSession);
|
||||
}
|
||||
@@ -152,11 +149,11 @@ public class ResourceAdminManager {
|
||||
|
||||
}
|
||||
|
||||
public boolean logoutClientSession(URI requestUri, RealmModel realm, ApplicationModel resource, ClientSessionModel clientSession, ApacheHttpClient4Executor client) {
|
||||
public boolean logoutClientSession(URI requestUri, RealmModel realm, ClientModel resource, ClientSessionModel clientSession, ApacheHttpClient4Executor client) {
|
||||
return logoutClientSessions(requestUri, realm, resource, Arrays.asList(clientSession), client);
|
||||
}
|
||||
|
||||
protected boolean logoutClientSessions(URI requestUri, RealmModel realm, ApplicationModel resource, List<ClientSessionModel> clientSessions, ApacheHttpClient4Executor client) {
|
||||
protected boolean logoutClientSessions(URI requestUri, RealmModel realm, ClientModel resource, List<ClientSessionModel> clientSessions, ApacheHttpClient4Executor client) {
|
||||
String managementUrl = getManagementUrl(requestUri, resource);
|
||||
if (managementUrl != null) {
|
||||
|
||||
@@ -176,7 +173,7 @@ public class ResourceAdminManager {
|
||||
}
|
||||
|
||||
if (adapterSessionIds == null || adapterSessionIds.isEmpty()) {
|
||||
logger.debugv("Can't logout {0}: no logged adapter sessions", resource.getName());
|
||||
logger.debugv("Can't logout {0}: no logged adapter sessions", resource.getClientId());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -201,7 +198,7 @@ public class ResourceAdminManager {
|
||||
return sendLogoutRequest(realm, resource, allSessionIds, userSessions, client, 0, managementUrl);
|
||||
}
|
||||
} else {
|
||||
logger.debugv("Can't logout {0}: no management url", resource.getName());
|
||||
logger.debugv("Can't logout {0}: no management url", resource.getClientId());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -213,11 +210,11 @@ public class ResourceAdminManager {
|
||||
|
||||
try {
|
||||
realm.setNotBefore(Time.currentTime());
|
||||
List<ApplicationModel> resources = realm.getApplications();
|
||||
List<ClientModel> resources = realm.getClients();
|
||||
logger.debugv("logging out {0} resources ", resources.size());
|
||||
|
||||
GlobalRequestResult finalResult = new GlobalRequestResult();
|
||||
for (ApplicationModel resource : resources) {
|
||||
for (ClientModel resource : resources) {
|
||||
GlobalRequestResult currentResult = logoutApplication(requestUri, realm, resource, executor, realm.getNotBefore());
|
||||
finalResult.addAll(currentResult);
|
||||
}
|
||||
@@ -227,7 +224,7 @@ public class ResourceAdminManager {
|
||||
}
|
||||
}
|
||||
|
||||
public GlobalRequestResult logoutApplication(URI requestUri, RealmModel realm, ApplicationModel resource) {
|
||||
public GlobalRequestResult logoutApplication(URI requestUri, RealmModel realm, ClientModel resource) {
|
||||
ApacheHttpClient4Executor executor = createExecutor();
|
||||
try {
|
||||
resource.setNotBefore(Time.currentTime());
|
||||
@@ -238,10 +235,10 @@ public class ResourceAdminManager {
|
||||
}
|
||||
|
||||
|
||||
protected GlobalRequestResult logoutApplication(URI requestUri, RealmModel realm, ApplicationModel resource, ApacheHttpClient4Executor executor, int notBefore) {
|
||||
protected GlobalRequestResult logoutApplication(URI requestUri, RealmModel realm, ClientModel resource, ApacheHttpClient4Executor executor, int notBefore) {
|
||||
List<String> mgmtUrls = getAllManagementUrls(requestUri, resource);
|
||||
if (mgmtUrls.isEmpty()) {
|
||||
logger.debug("No management URL or no registered cluster nodes for the application " + resource.getName());
|
||||
logger.debug("No management URL or no registered cluster nodes for the application " + resource.getClientId());
|
||||
return new GlobalRequestResult();
|
||||
}
|
||||
|
||||
@@ -259,16 +256,16 @@ public class ResourceAdminManager {
|
||||
return result;
|
||||
}
|
||||
|
||||
protected boolean sendLogoutRequest(RealmModel realm, ApplicationModel resource, List<String> adapterSessionIds, List<String> userSessions, ApacheHttpClient4Executor client, int notBefore, String managementUrl) {
|
||||
LogoutAction adminAction = new LogoutAction(TokenIdGenerator.generateId(), Time.currentTime() + 30, resource.getName(), adapterSessionIds, notBefore, userSessions);
|
||||
protected boolean sendLogoutRequest(RealmModel realm, ClientModel resource, List<String> adapterSessionIds, List<String> userSessions, ApacheHttpClient4Executor client, int notBefore, String managementUrl) {
|
||||
LogoutAction adminAction = new LogoutAction(TokenIdGenerator.generateId(), Time.currentTime() + 30, resource.getClientId(), adapterSessionIds, notBefore, userSessions);
|
||||
String token = new TokenManager().encodeToken(realm, adminAction);
|
||||
if (logger.isDebugEnabled()) logger.debugv("logout resource {0} url: {1} sessionIds: " + adapterSessionIds, resource.getName(), managementUrl);
|
||||
if (logger.isDebugEnabled()) logger.debugv("logout resource {0} url: {1} sessionIds: " + adapterSessionIds, resource.getClientId(), managementUrl);
|
||||
ClientRequest request = client.createRequest(UriBuilder.fromUri(managementUrl).path(AdapterConstants.K_LOGOUT).build().toString());
|
||||
ClientResponse response;
|
||||
try {
|
||||
response = request.body(MediaType.TEXT_PLAIN_TYPE, token).post();
|
||||
} catch (Exception e) {
|
||||
logger.warn("Logout for application '" + resource.getName() + "' failed", e);
|
||||
logger.warn("Logout for application '" + resource.getClientId() + "' failed", e);
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
@@ -285,7 +282,7 @@ public class ResourceAdminManager {
|
||||
|
||||
try {
|
||||
GlobalRequestResult finalResult = new GlobalRequestResult();
|
||||
for (ApplicationModel application : realm.getApplications()) {
|
||||
for (ClientModel application : realm.getClients()) {
|
||||
GlobalRequestResult currentResult = pushRevocationPolicy(requestUri, realm, application, realm.getNotBefore(), executor);
|
||||
finalResult.addAll(currentResult);
|
||||
}
|
||||
@@ -295,7 +292,7 @@ public class ResourceAdminManager {
|
||||
}
|
||||
}
|
||||
|
||||
public GlobalRequestResult pushApplicationRevocationPolicy(URI requestUri, RealmModel realm, ApplicationModel application) {
|
||||
public GlobalRequestResult pushApplicationRevocationPolicy(URI requestUri, RealmModel realm, ClientModel application) {
|
||||
ApacheHttpClient4Executor executor = createExecutor();
|
||||
|
||||
try {
|
||||
@@ -306,10 +303,10 @@ public class ResourceAdminManager {
|
||||
}
|
||||
|
||||
|
||||
protected GlobalRequestResult pushRevocationPolicy(URI requestUri, RealmModel realm, ApplicationModel resource, int notBefore, ApacheHttpClient4Executor executor) {
|
||||
protected GlobalRequestResult pushRevocationPolicy(URI requestUri, RealmModel realm, ClientModel resource, int notBefore, ApacheHttpClient4Executor executor) {
|
||||
List<String> mgmtUrls = getAllManagementUrls(requestUri, resource);
|
||||
if (mgmtUrls.isEmpty()) {
|
||||
logger.debugf("No management URL or no registered cluster nodes for the application %s", resource.getName());
|
||||
logger.debugf("No management URL or no registered cluster nodes for the application %s", resource.getClientId());
|
||||
return new GlobalRequestResult();
|
||||
}
|
||||
|
||||
@@ -327,10 +324,10 @@ public class ResourceAdminManager {
|
||||
return result;
|
||||
}
|
||||
|
||||
protected boolean sendPushRevocationPolicyRequest(RealmModel realm, ApplicationModel resource, int notBefore, ApacheHttpClient4Executor client, String managementUrl) {
|
||||
PushNotBeforeAction adminAction = new PushNotBeforeAction(TokenIdGenerator.generateId(), Time.currentTime() + 30, resource.getName(), notBefore);
|
||||
protected boolean sendPushRevocationPolicyRequest(RealmModel realm, ClientModel resource, int notBefore, ApacheHttpClient4Executor client, String managementUrl) {
|
||||
PushNotBeforeAction adminAction = new PushNotBeforeAction(TokenIdGenerator.generateId(), Time.currentTime() + 30, resource.getClientId(), notBefore);
|
||||
String token = new TokenManager().encodeToken(realm, adminAction);
|
||||
logger.infov("pushRevocation resource: {0} url: {1}", resource.getName(), managementUrl);
|
||||
logger.infov("pushRevocation resource: {0} url: {1}", resource.getClientId(), managementUrl);
|
||||
ClientRequest request = client.createRequest(UriBuilder.fromUri(managementUrl).path(AdapterConstants.K_PUSH_NOT_BEFORE).build().toString());
|
||||
ClientResponse response;
|
||||
try {
|
||||
@@ -348,10 +345,10 @@ public class ResourceAdminManager {
|
||||
}
|
||||
}
|
||||
|
||||
public GlobalRequestResult testNodesAvailability(URI requestUri, RealmModel realm, ApplicationModel application) {
|
||||
public GlobalRequestResult testNodesAvailability(URI requestUri, RealmModel realm, ClientModel application) {
|
||||
List<String> mgmtUrls = getAllManagementUrls(requestUri, application);
|
||||
if (mgmtUrls.isEmpty()) {
|
||||
logger.debug("No management URL or no registered cluster nodes for the application " + application.getName());
|
||||
logger.debug("No management URL or no registered cluster nodes for the application " + application.getClientId());
|
||||
return new GlobalRequestResult();
|
||||
}
|
||||
|
||||
@@ -375,10 +372,10 @@ public class ResourceAdminManager {
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean sendTestNodeAvailabilityRequest(RealmModel realm, ApplicationModel application, ApacheHttpClient4Executor client, String managementUrl) {
|
||||
TestAvailabilityAction adminAction = new TestAvailabilityAction(TokenIdGenerator.generateId(), Time.currentTime() + 30, application.getName());
|
||||
protected boolean sendTestNodeAvailabilityRequest(RealmModel realm, ClientModel application, ApacheHttpClient4Executor client, String managementUrl) {
|
||||
TestAvailabilityAction adminAction = new TestAvailabilityAction(TokenIdGenerator.generateId(), Time.currentTime() + 30, application.getClientId());
|
||||
String token = new TokenManager().encodeToken(realm, adminAction);
|
||||
logger.debugv("testNodes availability resource: {0} url: {1}", application.getName(), managementUrl);
|
||||
logger.debugv("testNodes availability resource: {0} url: {1}", application.getClientId(), managementUrl);
|
||||
ClientRequest request = client.createRequest(UriBuilder.fromUri(managementUrl).path(AdapterConstants.K_TEST_AVAILABLE).build().toString());
|
||||
ClientResponse response;
|
||||
try {
|
||||
|
||||
@@ -131,14 +131,14 @@ public class AccountService {
|
||||
private KeycloakSession session;
|
||||
|
||||
private final AppAuthManager authManager;
|
||||
private final ApplicationModel application;
|
||||
private final ClientModel application;
|
||||
private EventBuilder event;
|
||||
private AccountProvider account;
|
||||
private Auth auth;
|
||||
private EventStoreProvider eventStore;
|
||||
private String stateChecker;
|
||||
|
||||
public AccountService(RealmModel realm, ApplicationModel application, EventBuilder event) {
|
||||
public AccountService(RealmModel realm, ClientModel application, EventBuilder event) {
|
||||
this.realm = realm;
|
||||
this.application = application;
|
||||
this.event = event;
|
||||
@@ -813,7 +813,7 @@ public class AccountService {
|
||||
|
||||
String referrerUri = uriInfo.getQueryParameters().getFirst("referrer_uri");
|
||||
|
||||
ApplicationModel application = realm.getApplicationByName(referrer);
|
||||
ClientModel application = realm.getClientByClientId(referrer);
|
||||
if (application != null) {
|
||||
if (referrerUri != null) {
|
||||
referrerUri = RedirectUtils.verifyRedirectUri(uriInfo, referrerUri, realm, application);
|
||||
@@ -825,7 +825,7 @@ public class AccountService {
|
||||
return new String[]{referrer, referrerUri};
|
||||
}
|
||||
} else if (referrerUri != null) {
|
||||
ClientModel client = realm.getOAuthClient(referrer);
|
||||
ClientModel client = realm.getClientByClientId(referrer);
|
||||
if (client != null) {
|
||||
referrerUri = RedirectUtils.verifyRedirectUri(uriInfo, referrerUri, realm, application);
|
||||
|
||||
|
||||
+21
-24
@@ -1,20 +1,5 @@
|
||||
package org.keycloak.services.resources;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ws.rs.HeaderParam;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.ws.rs.core.MultivaluedMap;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriBuilder;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import javax.ws.rs.ext.Providers;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
import org.jboss.resteasy.spi.BadRequestException;
|
||||
import org.jboss.resteasy.spi.HttpRequest;
|
||||
@@ -26,15 +11,27 @@ import org.keycloak.events.Details;
|
||||
import org.keycloak.events.Errors;
|
||||
import org.keycloak.events.EventBuilder;
|
||||
import org.keycloak.events.EventType;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.protocol.oidc.OIDCLoginProtocolService;
|
||||
import org.keycloak.protocol.oidc.utils.AuthorizeClientUtil;
|
||||
import org.keycloak.services.ForbiddenException;
|
||||
import org.keycloak.util.Time;
|
||||
|
||||
import javax.ws.rs.HeaderParam;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.ws.rs.core.MultivaluedMap;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriBuilder;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import javax.ws.rs.ext.Providers;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
|
||||
*/
|
||||
@@ -105,11 +102,11 @@ public class ClientsManagementService {
|
||||
throw new UnauthorizedException("Realm not enabled");
|
||||
}
|
||||
|
||||
ApplicationModel application = authorizeApplication(authorizationHeader, formData);
|
||||
ClientModel application = authorizeApplication(authorizationHeader, formData);
|
||||
String nodeHost = getApplicationClusterHost(formData);
|
||||
|
||||
event.client(application).detail(Details.NODE_HOST, nodeHost);
|
||||
logger.debugf("Registering cluster host '%s' for client '%s'", nodeHost, application.getName());
|
||||
logger.debugf("Registering cluster host '%s' for client '%s'", nodeHost, application.getClientId());
|
||||
|
||||
application.registerNode(nodeHost, Time.currentTime());
|
||||
|
||||
@@ -141,11 +138,11 @@ public class ClientsManagementService {
|
||||
throw new UnauthorizedException("Realm not enabled");
|
||||
}
|
||||
|
||||
ApplicationModel application = authorizeApplication(authorizationHeader, formData);
|
||||
ClientModel application = authorizeApplication(authorizationHeader, formData);
|
||||
String nodeHost = getApplicationClusterHost(formData);
|
||||
|
||||
event.client(application).detail(Details.NODE_HOST, nodeHost);
|
||||
logger.debugf("Unregistering cluster host '%s' for client '%s'", nodeHost, application.getName());
|
||||
logger.debugf("Unregistering cluster host '%s' for client '%s'", nodeHost, application.getClientId());
|
||||
|
||||
application.unregisterNode(nodeHost);
|
||||
|
||||
@@ -154,7 +151,7 @@ public class ClientsManagementService {
|
||||
return Response.noContent().build();
|
||||
}
|
||||
|
||||
protected ApplicationModel authorizeApplication(String authorizationHeader, MultivaluedMap<String, String> formData) {
|
||||
protected ClientModel authorizeApplication(String authorizationHeader, MultivaluedMap<String, String> formData) {
|
||||
ClientModel client = AuthorizeClientUtil.authorizeClient(authorizationHeader, formData, event, realm);
|
||||
|
||||
if (client.isPublicClient()) {
|
||||
@@ -165,7 +162,7 @@ public class ClientsManagementService {
|
||||
throw new BadRequestException("Public clients not allowed", javax.ws.rs.core.Response.status(javax.ws.rs.core.Response.Status.BAD_REQUEST).entity(error).type("application/json").build());
|
||||
}
|
||||
|
||||
if (!(client instanceof ApplicationModel)) {
|
||||
if (!(client instanceof ClientModel)) {
|
||||
Map<String, String> error = new HashMap<String, String>();
|
||||
error.put(OAuth2Constants.ERROR, "invalid_client");
|
||||
error.put(OAuth2Constants.ERROR_DESCRIPTION, "Just applications are allowed");
|
||||
@@ -173,7 +170,7 @@ public class ClientsManagementService {
|
||||
throw new BadRequestException("ust applications are allowed", javax.ws.rs.core.Response.status(javax.ws.rs.core.Response.Status.BAD_REQUEST).entity(error).type("application/json").build());
|
||||
}
|
||||
|
||||
return (ApplicationModel)client;
|
||||
return (ClientModel)client;
|
||||
}
|
||||
|
||||
protected String getApplicationClusterHost(MultivaluedMap<String, String> formData) {
|
||||
|
||||
@@ -35,11 +35,9 @@ import org.keycloak.models.ClientSessionModel;
|
||||
import org.keycloak.models.FederatedIdentityModel;
|
||||
import org.keycloak.models.IdentityProviderModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.UserModel;
|
||||
import org.keycloak.models.UserSessionModel;
|
||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||
import org.keycloak.protocol.oidc.TokenManager;
|
||||
import org.keycloak.provider.ProviderFactory;
|
||||
import org.keycloak.services.managers.AppAuthManager;
|
||||
@@ -181,7 +179,7 @@ public class IdentityBrokerService implements IdentityProvider.AuthenticationCal
|
||||
|
||||
if (authResult != null) {
|
||||
String audience = authResult.getToken().getAudience();
|
||||
ClientModel clientModel = this.realmModel.findClient(audience);
|
||||
ClientModel clientModel = this.realmModel.getClientByClientId(audience);
|
||||
|
||||
if (clientModel == null) {
|
||||
return badRequest("Invalid client.");
|
||||
@@ -191,7 +189,7 @@ public class IdentityBrokerService implements IdentityProvider.AuthenticationCal
|
||||
return corsResponse(badRequest("Client [" + audience + "] not authorized to retrieve tokens from identity provider [" + providerId + "]."), clientModel);
|
||||
}
|
||||
|
||||
if (OAuthClientModel.class.isInstance(clientModel) && !forceRetrieval) {
|
||||
if (clientModel.isConsentRequired()) {
|
||||
return corsResponse(Flows.forms(this.session, this.realmModel, clientModel, this.uriInfo, headers)
|
||||
.setClientSessionCode(authManager.extractAuthorizationHeaderToken(this.request.getHttpHeaders()))
|
||||
.setAccessRequest("Your information from " + providerId + " identity provider.")
|
||||
@@ -329,7 +327,7 @@ public class IdentityBrokerService implements IdentityProvider.AuthenticationCal
|
||||
return redirectToErrorPage(Messages.ACCOUNT_DISABLED);
|
||||
}
|
||||
|
||||
if (!authenticatedUser.hasRole(this.realmModel.getApplicationByName(ACCOUNT_MANAGEMENT_APP).getRole(MANAGE_ACCOUNT))) {
|
||||
if (!authenticatedUser.hasRole(this.realmModel.getClientByClientId(ACCOUNT_MANAGEMENT_APP).getRole(MANAGE_ACCOUNT))) {
|
||||
fireErrorEvent(Errors.NOT_ALLOWED);
|
||||
return redirectToErrorPage(Messages.INSUFFICIENT_PERMISSION);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.ClientSessionModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.ModelException;
|
||||
import org.keycloak.models.PasswordPolicy;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RequiredCredentialModel;
|
||||
import org.keycloak.models.UserCredentialModel;
|
||||
@@ -73,8 +72,6 @@ import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriBuilder;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import javax.ws.rs.ext.Providers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -320,7 +317,6 @@ public class LoginActionsService {
|
||||
event.detail(Details.REMEMBER_ME, "true");
|
||||
}
|
||||
|
||||
|
||||
ClientModel client = clientSession.getClient();
|
||||
if (client == null) {
|
||||
event.error(Errors.CLIENT_NOT_FOUND);
|
||||
|
||||
@@ -5,7 +5,7 @@ import org.jboss.resteasy.spi.NotFoundException;
|
||||
import org.jboss.resteasy.spi.ResteasyProviderFactory;
|
||||
import org.keycloak.ClientConnection;
|
||||
import org.keycloak.events.EventBuilder;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.Constants;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmModel;
|
||||
@@ -157,7 +157,7 @@ public class RealmsResource {
|
||||
RealmManager realmManager = new RealmManager(session);
|
||||
RealmModel realm = locateRealm(name, realmManager);
|
||||
|
||||
ApplicationModel application = realm.getApplicationNameMap().get(Constants.ACCOUNT_MANAGEMENT_APP);
|
||||
ClientModel application = realm.getClientNameMap().get(Constants.ACCOUNT_MANAGEMENT_APP);
|
||||
if (application == null || !application.isEnabled()) {
|
||||
logger.debug("account management not enabled");
|
||||
throw new NotFoundException("account management not enabled");
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.keycloak.services.resources.admin;
|
||||
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RoleModel;
|
||||
@@ -43,7 +42,7 @@ public class AdminAuth {
|
||||
|
||||
|
||||
public boolean hasRealmRole(String role) {
|
||||
if (client instanceof ApplicationModel) {
|
||||
if (client instanceof ClientModel) {
|
||||
RoleModel roleModel = realm.getRole(role);
|
||||
return user.hasRole(roleModel) && client.hasScope(roleModel);
|
||||
} else {
|
||||
@@ -61,17 +60,17 @@ public class AdminAuth {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasAppRole(ApplicationModel app, String role) {
|
||||
if (client instanceof ApplicationModel) {
|
||||
public boolean hasAppRole(ClientModel app, String role) {
|
||||
if (client instanceof ClientModel) {
|
||||
RoleModel roleModel = app.getRole(role);
|
||||
return user.hasRole(roleModel) && client.hasScope(roleModel);
|
||||
} else {
|
||||
AccessToken.Access access = token.getResourceAccess(app.getName());
|
||||
AccessToken.Access access = token.getResourceAccess(app.getClientId());
|
||||
return access != null && access.isUserInRole(role);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasOneOfAppRole(ApplicationModel app, String... roles) {
|
||||
public boolean hasOneOfAppRole(ClientModel app, String... roles) {
|
||||
for (String r : roles) {
|
||||
if (hasAppRole(app, r)) {
|
||||
return true;
|
||||
|
||||
@@ -14,7 +14,7 @@ import org.keycloak.freemarker.FreeMarkerUtil;
|
||||
import org.keycloak.freemarker.Theme;
|
||||
import org.keycloak.freemarker.ThemeProvider;
|
||||
import org.keycloak.models.AdminRoles;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.Constants;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmModel;
|
||||
@@ -154,7 +154,7 @@ public class AdminConsole {
|
||||
@Produces("application/json")
|
||||
@NoCache
|
||||
public ApplicationManager.InstallationAdapterConfig config() {
|
||||
ApplicationModel consoleApp = realm.getApplicationByName(Constants.ADMIN_CONSOLE_APPLICATION);
|
||||
ClientModel consoleApp = realm.getClientByClientId(Constants.ADMIN_CONSOLE_APPLICATION);
|
||||
if (consoleApp == null) {
|
||||
throw new NotFoundException("Could not find admin console application");
|
||||
}
|
||||
@@ -208,7 +208,7 @@ public class AdminConsole {
|
||||
|
||||
private void addRealmAccess(RealmModel realm, UserModel user, Map<String, Set<String>> realmAdminAccess) {
|
||||
RealmManager realmManager = new RealmManager(session);
|
||||
ApplicationModel realmAdminApp = realm.getApplicationByName(realmManager.getRealmAdminApplicationName(realm));
|
||||
ClientModel realmAdminApp = realm.getClientByClientId(realmManager.getRealmAdminApplicationName(realm));
|
||||
Set<RoleModel> roles = realmAdminApp.getRoles();
|
||||
for (RoleModel role : roles) {
|
||||
if (!user.hasRole(role)) continue;
|
||||
@@ -223,7 +223,7 @@ public class AdminConsole {
|
||||
private void addMasterRealmAccess(RealmModel masterRealm, UserModel user, Map<String, Set<String>> realmAdminAccess) {
|
||||
List<RealmModel> realms = session.realms().getRealms();
|
||||
for (RealmModel realm : realms) {
|
||||
ApplicationModel realmAdminApp = realm.getMasterAdminApp();
|
||||
ClientModel realmAdminApp = realm.getMasterAdminApp();
|
||||
Set<RoleModel> roles = realmAdminApp.getRoles();
|
||||
for (RoleModel role : roles) {
|
||||
if (!user.hasRole(role)) continue;
|
||||
|
||||
@@ -149,7 +149,7 @@ public class AdminRoot {
|
||||
throw new UnauthorizedException("Bearer");
|
||||
}
|
||||
|
||||
ClientModel client = realm.findClient(token.getIssuedFor());
|
||||
ClientModel client = realm.getClientByClientId(token.getIssuedFor());
|
||||
if (client == null) {
|
||||
throw new NotFoundException("Could not find client for authorization");
|
||||
|
||||
|
||||
+5
-5
@@ -5,7 +5,7 @@ import org.jboss.resteasy.annotations.cache.NoCache;
|
||||
import org.jboss.resteasy.spi.BadRequestException;
|
||||
import org.jboss.resteasy.spi.NotFoundException;
|
||||
import org.jboss.resteasy.spi.ResteasyProviderFactory;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.ModelDuplicateException;
|
||||
import org.keycloak.models.RealmModel;
|
||||
@@ -57,7 +57,7 @@ public class ApplicationResource {
|
||||
protected static final Logger logger = Logger.getLogger(ApplicationResource.class);
|
||||
protected RealmModel realm;
|
||||
private RealmAuth auth;
|
||||
protected ApplicationModel application;
|
||||
protected ClientModel application;
|
||||
protected KeycloakSession session;
|
||||
|
||||
@Context
|
||||
@@ -70,13 +70,13 @@ public class ApplicationResource {
|
||||
return keycloak;
|
||||
}
|
||||
|
||||
public ApplicationResource(RealmModel realm, RealmAuth auth, ApplicationModel applicationModel, KeycloakSession session) {
|
||||
public ApplicationResource(RealmModel realm, RealmAuth auth, ClientModel clientModel, KeycloakSession session) {
|
||||
this.realm = realm;
|
||||
this.auth = auth;
|
||||
this.application = applicationModel;
|
||||
this.application = clientModel;
|
||||
this.session = session;
|
||||
|
||||
auth.init(RealmAuth.Resource.APPLICATION);
|
||||
auth.init(RealmAuth.Resource.CLIENT);
|
||||
}
|
||||
|
||||
@Path("protocol-mappers")
|
||||
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
package org.keycloak.services.resources.admin;
|
||||
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
|
||||
/**
|
||||
@@ -13,13 +13,13 @@ public class ApplicationsByIdResource extends ApplicationsResource {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ApplicationModel getApplicationByPathParam(String id) {
|
||||
return realm.getApplicationById(id);
|
||||
protected ClientModel getApplicationByPathParam(String id) {
|
||||
return realm.getClientById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getApplicationPath(ApplicationModel applicationModel) {
|
||||
return applicationModel.getId();
|
||||
protected String getApplicationPath(ClientModel clientModel) {
|
||||
return clientModel.getId();
|
||||
}
|
||||
|
||||
}
|
||||
+15
-15
@@ -4,7 +4,7 @@ import org.jboss.logging.Logger;
|
||||
import org.jboss.resteasy.annotations.cache.NoCache;
|
||||
import org.jboss.resteasy.spi.NotFoundException;
|
||||
import org.jboss.resteasy.spi.ResteasyProviderFactory;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.ModelDuplicateException;
|
||||
import org.keycloak.models.RealmModel;
|
||||
@@ -44,7 +44,7 @@ public class ApplicationsResource {
|
||||
this.realm = realm;
|
||||
this.auth = auth;
|
||||
|
||||
auth.init(RealmAuth.Resource.APPLICATION);
|
||||
auth.init(RealmAuth.Resource.CLIENT);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,15 +59,15 @@ public class ApplicationsResource {
|
||||
auth.requireAny();
|
||||
|
||||
List<ApplicationRepresentation> rep = new ArrayList<ApplicationRepresentation>();
|
||||
List<ApplicationModel> applicationModels = realm.getApplications();
|
||||
List<ClientModel> clientModels = realm.getClients();
|
||||
|
||||
boolean view = auth.hasView();
|
||||
for (ApplicationModel applicationModel : applicationModels) {
|
||||
for (ClientModel clientModel : clientModels) {
|
||||
if (view) {
|
||||
rep.add(ModelToRepresentation.toRepresentation(applicationModel));
|
||||
rep.add(ModelToRepresentation.toRepresentation(clientModel));
|
||||
} else {
|
||||
ApplicationRepresentation app = new ApplicationRepresentation();
|
||||
app.setName(applicationModel.getName());
|
||||
app.setName(clientModel.getClientId());
|
||||
rep.add(app);
|
||||
}
|
||||
}
|
||||
@@ -88,15 +88,15 @@ public class ApplicationsResource {
|
||||
auth.requireManage();
|
||||
|
||||
try {
|
||||
ApplicationModel applicationModel = RepresentationToModel.createApplication(session, realm, rep, true);
|
||||
return Response.created(uriInfo.getAbsolutePathBuilder().path(getApplicationPath(applicationModel)).build()).build();
|
||||
ClientModel clientModel = RepresentationToModel.createApplication(session, realm, rep, true);
|
||||
return Response.created(uriInfo.getAbsolutePathBuilder().path(getApplicationPath(clientModel)).build()).build();
|
||||
} catch (ModelDuplicateException e) {
|
||||
return Flows.errors().exists("Application " + rep.getName() + " already exists");
|
||||
}
|
||||
}
|
||||
|
||||
protected String getApplicationPath(ApplicationModel applicationModel) {
|
||||
return applicationModel.getName();
|
||||
protected String getApplicationPath(ClientModel clientModel) {
|
||||
return clientModel.getClientId();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,18 +107,18 @@ public class ApplicationsResource {
|
||||
*/
|
||||
@Path("{app-name}")
|
||||
public ApplicationResource getApplication(final @PathParam("app-name") String name) {
|
||||
ApplicationModel applicationModel = getApplicationByPathParam(name);
|
||||
if (applicationModel == null) {
|
||||
ClientModel clientModel = getApplicationByPathParam(name);
|
||||
if (clientModel == null) {
|
||||
throw new NotFoundException("Could not find application: " + name);
|
||||
}
|
||||
ApplicationResource applicationResource = new ApplicationResource(realm, auth, applicationModel, session);
|
||||
ApplicationResource applicationResource = new ApplicationResource(realm, auth, clientModel, session);
|
||||
ResteasyProviderFactory.getInstance().injectProperties(applicationResource);
|
||||
//resourceContext.initResource(applicationResource);
|
||||
return applicationResource;
|
||||
}
|
||||
|
||||
protected ApplicationModel getApplicationByPathParam(String name) {
|
||||
return realm.getApplicationByName(name);
|
||||
protected ClientModel getApplicationByPathParam(String name) {
|
||||
return realm.getClientByClientId(name);
|
||||
}
|
||||
|
||||
}
|
||||
-2
@@ -6,8 +6,6 @@ import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
|
||||
import org.jboss.resteasy.spi.BadRequestException;
|
||||
import org.jboss.resteasy.spi.NotAcceptableException;
|
||||
import org.jboss.resteasy.spi.NotFoundException;
|
||||
import org.keycloak.events.EventBuilder;
|
||||
import org.keycloak.events.EventType;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmModel;
|
||||
|
||||
+6
-8
@@ -4,8 +4,8 @@ import org.jboss.logging.Logger;
|
||||
import org.jboss.resteasy.annotations.cache.NoCache;
|
||||
import org.keycloak.broker.provider.IdentityProvider;
|
||||
import org.keycloak.broker.provider.IdentityProviderFactory;
|
||||
import org.keycloak.models.ClientIdentityProviderMappingModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.ClientIdentityProviderMappingModel;
|
||||
import org.keycloak.models.FederatedIdentityModel;
|
||||
import org.keycloak.models.IdentityProviderModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
@@ -65,8 +65,7 @@ public class IdentityProviderResource {
|
||||
public Response delete() {
|
||||
this.auth.requireManage();
|
||||
|
||||
removeClientIdentityProviders(this.realm.getApplications(), this.identityProviderModel);
|
||||
removeClientIdentityProviders(this.realm.getOAuthClients(), this.identityProviderModel);
|
||||
removeClientIdentityProviders(this.realm.getClients(), this.identityProviderModel);
|
||||
|
||||
this.realm.removeIdentityProviderByAlias(this.identityProviderModel.getAlias());
|
||||
|
||||
@@ -90,8 +89,7 @@ public class IdentityProviderResource {
|
||||
// Admin changed the ID (alias) of identity provider. We must update all clients and users
|
||||
logger.debug("Changing providerId in all clients and linked users. oldProviderId=" + oldProviderId + ", newProviderId=" + newProviderId);
|
||||
|
||||
updateClientsAfterProviderAliasChange(this.realm.getApplications(), oldProviderId, newProviderId);
|
||||
updateClientsAfterProviderAliasChange(this.realm.getOAuthClients(), oldProviderId, newProviderId);
|
||||
updateClientsAfterProviderAliasChange(this.realm.getClients(), oldProviderId, newProviderId);
|
||||
updateUsersAfterProviderAliasChange(this.session.users().getUsers(this.realm), oldProviderId, newProviderId);
|
||||
}
|
||||
|
||||
@@ -113,7 +111,7 @@ public class IdentityProviderResource {
|
||||
return null;
|
||||
}
|
||||
|
||||
private void updateClientsAfterProviderAliasChange(List<? extends ClientModel> clients, String oldProviderId, String newProviderId) {
|
||||
private void updateClientsAfterProviderAliasChange(List<ClientModel> clients, String oldProviderId, String newProviderId) {
|
||||
for (ClientModel client : clients) {
|
||||
List<ClientIdentityProviderMappingModel> clientIdentityProviders = client.getIdentityProviders();
|
||||
boolean found = true;
|
||||
@@ -175,11 +173,11 @@ public class IdentityProviderResource {
|
||||
}
|
||||
|
||||
|
||||
private void removeClientIdentityProviders(List<? extends ClientModel> clients, IdentityProviderModel identityProvider) {
|
||||
private void removeClientIdentityProviders(List<ClientModel> clients, IdentityProviderModel identityProvider) {
|
||||
for (ClientModel clientModel : clients) {
|
||||
List<ClientIdentityProviderMappingModel> identityProviders = clientModel.getIdentityProviders();
|
||||
|
||||
for (ClientIdentityProviderMappingModel providerMappingModel : new ArrayList<ClientIdentityProviderMappingModel>(identityProviders)) {
|
||||
for (ClientIdentityProviderMappingModel providerMappingModel : new ArrayList<>(identityProviders)) {
|
||||
if (providerMappingModel.getIdentityProvider().equals(identityProvider.getAlias())) {
|
||||
identityProviders.remove(providerMappingModel);
|
||||
clientModel.updateIdentityProviders(identityProviders);
|
||||
|
||||
-206
@@ -1,206 +0,0 @@
|
||||
package org.keycloak.services.resources.admin;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
import org.jboss.resteasy.annotations.cache.NoCache;
|
||||
import org.jboss.resteasy.spi.NotFoundException;
|
||||
import org.jboss.resteasy.spi.ResteasyProviderFactory;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.ModelDuplicateException;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.UserCredentialModel;
|
||||
import org.keycloak.models.utils.ModelToRepresentation;
|
||||
import org.keycloak.models.utils.RepresentationToModel;
|
||||
import org.keycloak.representations.idm.CredentialRepresentation;
|
||||
import org.keycloak.representations.idm.OAuthClientRepresentation;
|
||||
import org.keycloak.services.managers.OAuthClientManager;
|
||||
import org.keycloak.services.managers.RealmManager;
|
||||
import org.keycloak.services.resources.KeycloakApplication;
|
||||
import org.keycloak.services.resources.flows.Flows;
|
||||
import org.keycloak.util.JsonSerialization;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Base resource class for managing oauth clients
|
||||
*
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public class OAuthClientResource {
|
||||
protected static final Logger logger = Logger.getLogger(RealmAdminResource.class);
|
||||
protected RealmModel realm;
|
||||
private RealmAuth auth;
|
||||
protected OAuthClientModel oauthClient;
|
||||
protected KeycloakSession session;
|
||||
@Context
|
||||
protected UriInfo uriInfo;
|
||||
|
||||
@Context
|
||||
protected KeycloakApplication application;
|
||||
|
||||
protected KeycloakApplication getApplication() {
|
||||
return (KeycloakApplication)application;
|
||||
}
|
||||
|
||||
public OAuthClientResource(RealmModel realm, RealmAuth auth, OAuthClientModel oauthClient, KeycloakSession session) {
|
||||
this.realm = realm;
|
||||
this.auth = auth;
|
||||
this.oauthClient = oauthClient;
|
||||
this.session = session;
|
||||
|
||||
auth.init(RealmAuth.Resource.CLIENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* interface for updating attached ProtocolMappers
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Path("protocol-mappers")
|
||||
public ProtocolMappersResource getProtocolMappers() {
|
||||
ProtocolMappersResource mappers = new ProtocolMappersResource(oauthClient, auth);
|
||||
ResteasyProviderFactory.getInstance().injectProperties(mappers);
|
||||
//resourceContext.initResource(mappers);
|
||||
return mappers;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param attributePrefix
|
||||
* @return
|
||||
*/
|
||||
@Path("certificates/{attr}")
|
||||
public ClientAttributeCertificateResource getCertficateResource(@PathParam("attr") String attributePrefix) {
|
||||
return new ClientAttributeCertificateResource(realm, auth, oauthClient, session, attributePrefix);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Update the oauth client
|
||||
*
|
||||
* @param rep
|
||||
* @return
|
||||
*/
|
||||
@PUT
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Response update(final OAuthClientRepresentation rep) {
|
||||
auth.requireManage();
|
||||
|
||||
try {
|
||||
RepresentationToModel.updateOAuthClient(session, rep, oauthClient);
|
||||
return Response.noContent().build();
|
||||
} catch (ModelDuplicateException e) {
|
||||
return Flows.errors().exists("Client " + rep.getName() + " already exists");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a representation of the oauth client
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GET
|
||||
@NoCache
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public OAuthClientRepresentation getOAuthClient() {
|
||||
auth.requireView();
|
||||
|
||||
return ModelToRepresentation.toRepresentation(oauthClient);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an example keycloak.json file to use to configure the oauth client
|
||||
*
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@GET
|
||||
@NoCache
|
||||
@Path("installation")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public String getInstallation() throws IOException {
|
||||
auth.requireView();
|
||||
|
||||
OAuthClientManager manager = new OAuthClientManager();
|
||||
Object rep = manager.toInstallationRepresentation(realm, oauthClient, getApplication().getBaseUri(uriInfo));
|
||||
|
||||
// TODO Temporary solution to pretty-print
|
||||
return JsonSerialization.mapper.writerWithDefaultPrettyPrinter().writeValueAsString(rep);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the OAuth Client
|
||||
*
|
||||
*/
|
||||
@DELETE
|
||||
@NoCache
|
||||
public void deleteOAuthClient() {
|
||||
auth.requireManage();
|
||||
|
||||
new OAuthClientManager(new RealmManager(session)).removeClient(realm, oauthClient);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate a new client secret for the oauth client
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Path("client-secret")
|
||||
@POST
|
||||
@Produces("application/json")
|
||||
@Consumes("application/json")
|
||||
public CredentialRepresentation regenerateSecret() {
|
||||
auth.requireManage();
|
||||
|
||||
logger.debug("regenerateSecret");
|
||||
UserCredentialModel cred = UserCredentialModel.generateSecret();
|
||||
oauthClient.setSecret(cred.getValue());
|
||||
CredentialRepresentation rep = ModelToRepresentation.toRepresentation(cred);
|
||||
return rep;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the secret of the oauth client
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Path("client-secret")
|
||||
@GET
|
||||
@NoCache
|
||||
@Produces("application/json")
|
||||
public CredentialRepresentation getClientSecret() {
|
||||
auth.requireView();
|
||||
|
||||
logger.debug("getClientSecret");
|
||||
UserCredentialModel model = UserCredentialModel.secret(oauthClient.getSecret());
|
||||
if (model == null) throw new NotFoundException("Application does not have a secret");
|
||||
return ModelToRepresentation.toRepresentation(model);
|
||||
}
|
||||
|
||||
/**
|
||||
* Base path for managing the oauth client's scope
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Path("scope-mappings")
|
||||
public ScopeMappedResource getScopeMappedResource() {
|
||||
return new ScopeMappedResource(realm, auth, oauthClient, session);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
package org.keycloak.services.resources.admin;
|
||||
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public class OAuthClientsByIdResource extends OAuthClientsResource {
|
||||
public OAuthClientsByIdResource(RealmModel realm, RealmAuth auth, KeycloakSession session) {
|
||||
super(realm, auth, session);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OAuthClientModel getOAuthClientModel(String id) {
|
||||
return realm.getOAuthClientById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getClientPath(OAuthClientModel oauth) {
|
||||
return oauth.getId();
|
||||
}
|
||||
|
||||
}
|
||||
-121
@@ -1,121 +0,0 @@
|
||||
package org.keycloak.services.resources.admin;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
import org.jboss.resteasy.annotations.cache.NoCache;
|
||||
import org.jboss.resteasy.spi.NotFoundException;
|
||||
import org.jboss.resteasy.spi.ResteasyProviderFactory;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.ModelDuplicateException;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.utils.ModelToRepresentation;
|
||||
import org.keycloak.models.utils.RepresentationToModel;
|
||||
import org.keycloak.representations.idm.OAuthClientRepresentation;
|
||||
import org.keycloak.services.resources.flows.Flows;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
* @version $Revision: 1 $
|
||||
*/
|
||||
public class OAuthClientsResource {
|
||||
protected static final Logger logger = Logger.getLogger(RealmAdminResource.class);
|
||||
protected RealmModel realm;
|
||||
protected KeycloakSession session;
|
||||
private RealmAuth auth;
|
||||
|
||||
public OAuthClientsResource(RealmModel realm, RealmAuth auth, KeycloakSession session) {
|
||||
this.auth = auth;
|
||||
this.realm = realm;
|
||||
this.session = session;
|
||||
|
||||
auth.init(RealmAuth.Resource.CLIENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of oauth clients in this realm.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@NoCache
|
||||
public List<OAuthClientRepresentation> getOAuthClients() {
|
||||
List<OAuthClientRepresentation> rep = new ArrayList<OAuthClientRepresentation>();
|
||||
List<OAuthClientModel> oauthModels = realm.getOAuthClients();
|
||||
|
||||
boolean view = auth.hasView();
|
||||
for (OAuthClientModel oauth : oauthModels) {
|
||||
if (view) {
|
||||
rep.add(ModelToRepresentation.toRepresentation(oauth));
|
||||
} else {
|
||||
OAuthClientRepresentation client = new OAuthClientRepresentation();
|
||||
client.setName(oauth.getClientId());
|
||||
rep.add(client);
|
||||
}
|
||||
}
|
||||
|
||||
return rep;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an oauth client
|
||||
*
|
||||
* @param uriInfo
|
||||
* @param rep
|
||||
* @return
|
||||
*/
|
||||
@POST
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Response createOAuthClient(final @Context UriInfo uriInfo, final OAuthClientRepresentation rep) {
|
||||
auth.requireManage();
|
||||
|
||||
try {
|
||||
OAuthClientModel oauth = RepresentationToModel.createOAuthClient(session, rep, realm);
|
||||
return Response.created(uriInfo.getAbsolutePathBuilder().path(getClientPath(oauth)).build()).build();
|
||||
} catch (ModelDuplicateException e) {
|
||||
return Flows.errors().exists("Client " + rep.getName() + " already exists");
|
||||
}
|
||||
}
|
||||
|
||||
protected String getClientPath(OAuthClientModel oauth) {
|
||||
return oauth.getClientId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Base path to manage one specific oauth client
|
||||
*
|
||||
* @param clientId oauth client's clientId
|
||||
* @return
|
||||
*/
|
||||
@Path("{clientId}")
|
||||
public OAuthClientResource getOAuthClient(final @PathParam("clientId") String clientId) {
|
||||
auth.requireView();
|
||||
|
||||
OAuthClientModel oauth = getOAuthClientModel(clientId);
|
||||
if (oauth == null) {
|
||||
throw new NotFoundException("OAuth Client not found");
|
||||
}
|
||||
OAuthClientResource oAuthClientResource = new OAuthClientResource(realm, auth, oauth, session);
|
||||
ResteasyProviderFactory.getInstance().injectProperties(oAuthClientResource);
|
||||
//resourceContext.initResource(oAuthClientResource);
|
||||
return oAuthClientResource;
|
||||
}
|
||||
|
||||
protected OAuthClientModel getOAuthClientModel(String clientId) {
|
||||
return realm.getOAuthClient(clientId);
|
||||
}
|
||||
|
||||
}
|
||||
-3
@@ -21,7 +21,6 @@ import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -147,6 +146,4 @@ public class ProtocolMappersResource {
|
||||
client.removeProtocolMapper(model);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
+5
-32
@@ -10,7 +10,7 @@ import org.keycloak.events.EventQuery;
|
||||
import org.keycloak.events.EventStoreProvider;
|
||||
import org.keycloak.events.EventType;
|
||||
import org.keycloak.exportimport.ApplicationImporter;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.ModelDuplicateException;
|
||||
import org.keycloak.models.RealmModel;
|
||||
@@ -46,7 +46,6 @@ import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -122,32 +121,6 @@ public class RealmAdminResource {
|
||||
return applicationsResource;
|
||||
}
|
||||
|
||||
/**
|
||||
* base path for managing oauth clients in this realm uses name of client
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Path("oauth-clients")
|
||||
public OAuthClientsResource getOAuthClients() {
|
||||
OAuthClientsResource oauth = new OAuthClientsResource(realm, auth, session);
|
||||
ResteasyProviderFactory.getInstance().injectProperties(oauth);
|
||||
//resourceContext.initResource(oauth);
|
||||
return oauth;
|
||||
}
|
||||
|
||||
/**
|
||||
* base path for managing oauth clients in this realm uses ids
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Path("oauth-clients-by-id")
|
||||
public OAuthClientsByIdResource getOAuthClientsById() {
|
||||
OAuthClientsByIdResource oauth = new OAuthClientsByIdResource(realm, auth, session);
|
||||
ResteasyProviderFactory.getInstance().injectProperties(oauth);
|
||||
//resourceContext.initResource(oauth);
|
||||
return oauth;
|
||||
}
|
||||
|
||||
/**
|
||||
* base path for managing realm-level roles of this realm
|
||||
*
|
||||
@@ -327,10 +300,10 @@ public class RealmAdminResource {
|
||||
public Map<String, Integer> getApplicationSessionStats() {
|
||||
auth.requireView();
|
||||
Map<String, Integer> stats = new HashMap<String, Integer>();
|
||||
for (ApplicationModel application : realm.getApplications()) {
|
||||
for (ClientModel application : realm.getClients()) {
|
||||
int size = session.sessions().getActiveUserSessions(application.getRealm(), application);
|
||||
if (size == 0) continue;
|
||||
stats.put(application.getName(), size);
|
||||
stats.put(application.getClientId(), size);
|
||||
}
|
||||
return stats;
|
||||
}
|
||||
@@ -348,12 +321,12 @@ public class RealmAdminResource {
|
||||
public List<Map<String, String>> getApplicationByIdSessionStats() {
|
||||
auth.requireView();
|
||||
List<Map<String, String>> data = new LinkedList<Map<String, String>>();
|
||||
for (ApplicationModel application : realm.getApplications()) {
|
||||
for (ClientModel application : realm.getClients()) {
|
||||
int size = session.sessions().getActiveUserSessions(application.getRealm(), application);
|
||||
if (size == 0) continue;
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("id", application.getId());
|
||||
map.put("name", application.getName());
|
||||
map.put("name", application.getClientId());
|
||||
map.put("active", size + "");
|
||||
data.add(map);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.keycloak.services.resources.admin;
|
||||
|
||||
import org.keycloak.models.AdminRoles;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.services.ForbiddenException;
|
||||
|
||||
|
||||
@@ -13,13 +13,13 @@ public class RealmAuth {
|
||||
private Resource resource;
|
||||
|
||||
public enum Resource {
|
||||
APPLICATION, CLIENT, USER, REALM, EVENTS, IDENTITY_PROVIDER
|
||||
CLIENT, USER, REALM, EVENTS, IDENTITY_PROVIDER
|
||||
}
|
||||
|
||||
private AdminAuth auth;
|
||||
private ApplicationModel realmAdminApp;
|
||||
private ClientModel realmAdminApp;
|
||||
|
||||
public RealmAuth(AdminAuth auth, ApplicationModel realmAdminApp) {
|
||||
public RealmAuth(AdminAuth auth, ClientModel realmAdminApp) {
|
||||
this.auth = auth;
|
||||
this.realmAdminApp = realmAdminApp;
|
||||
}
|
||||
@@ -57,8 +57,6 @@ public class RealmAuth {
|
||||
|
||||
private String getViewRole(Resource resource) {
|
||||
switch (resource) {
|
||||
case APPLICATION:
|
||||
return AdminRoles.VIEW_APPLICATIONS;
|
||||
case CLIENT:
|
||||
return AdminRoles.VIEW_CLIENTS;
|
||||
case USER:
|
||||
@@ -76,8 +74,6 @@ public class RealmAuth {
|
||||
|
||||
private String getManageRole(Resource resource) {
|
||||
switch (resource) {
|
||||
case APPLICATION:
|
||||
return AdminRoles.MANAGE_APPLICATIONS;
|
||||
case CLIENT:
|
||||
return AdminRoles.MANAGE_CLIENTS;
|
||||
case USER:
|
||||
|
||||
+5
-6
@@ -4,11 +4,10 @@ import org.jboss.logging.Logger;
|
||||
import org.jboss.resteasy.annotations.cache.NoCache;
|
||||
import org.jboss.resteasy.plugins.providers.multipart.InputPart;
|
||||
import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
|
||||
import org.jboss.resteasy.spi.HttpRequest;
|
||||
import org.jboss.resteasy.spi.NotFoundException;
|
||||
import org.jboss.resteasy.spi.ResteasyProviderFactory;
|
||||
import org.keycloak.models.AdminRoles;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.ModelDuplicateException;
|
||||
import org.keycloak.models.RealmModel;
|
||||
@@ -85,14 +84,14 @@ public class RealmsAdminResource {
|
||||
addRealmRep(reps, realm, realm.getMasterAdminApp());
|
||||
}
|
||||
} else {
|
||||
ApplicationModel adminApp = auth.getRealm().getApplicationByName(realmManager.getRealmAdminApplicationName(auth.getRealm()));
|
||||
ClientModel adminApp = auth.getRealm().getClientByClientId(realmManager.getRealmAdminApplicationName(auth.getRealm()));
|
||||
addRealmRep(reps, auth.getRealm(), adminApp);
|
||||
}
|
||||
logger.debug(("getRealms()"));
|
||||
return reps;
|
||||
}
|
||||
|
||||
protected void addRealmRep(List<RealmRepresentation> reps, RealmModel realm, ApplicationModel realmManagementApplication) {
|
||||
protected void addRealmRep(List<RealmRepresentation> reps, RealmModel realm, ClientModel realmManagementApplication) {
|
||||
if (auth.hasAppRole(realmManagementApplication, AdminRoles.MANAGE_REALM)) {
|
||||
reps.add(ModelToRepresentation.toRepresentation(realm, false));
|
||||
} else if (auth.hasOneOfAppRole(realmManagementApplication, AdminRoles.ALL_REALM_ROLES)) {
|
||||
@@ -187,7 +186,7 @@ public class RealmsAdminResource {
|
||||
}
|
||||
|
||||
RealmModel adminRealm = new RealmManager(session).getKeycloakAdminstrationRealm();
|
||||
ApplicationModel realmAdminApp = realm.getMasterAdminApp();
|
||||
ClientModel realmAdminApp = realm.getMasterAdminApp();
|
||||
for (String r : AdminRoles.ALL_REALM_ROLES) {
|
||||
RoleModel role = realmAdminApp.getRole(r);
|
||||
auth.getUser().grantRole(role);
|
||||
@@ -217,7 +216,7 @@ public class RealmsAdminResource {
|
||||
if (auth.getRealm().equals(realmManager.getKeycloakAdminstrationRealm())) {
|
||||
realmAuth = new RealmAuth(auth, realm.getMasterAdminApp());
|
||||
} else {
|
||||
realmAuth = new RealmAuth(auth, realm.getApplicationByName(realmManager.getRealmAdminApplicationName(auth.getRealm())));
|
||||
realmAuth = new RealmAuth(auth, realm.getClientByClientId(realmManager.getRealmAdminApplicationName(auth.getRealm())));
|
||||
}
|
||||
|
||||
RealmAdminResource adminResource = new RealmAdminResource(realmAuth, realm, tokenManager);
|
||||
|
||||
@@ -3,9 +3,8 @@ package org.keycloak.services.resources.admin;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.jboss.resteasy.annotations.cache.NoCache;
|
||||
import org.jboss.resteasy.spi.NotFoundException;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.OAuthClientModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.UserModel;
|
||||
@@ -70,9 +69,7 @@ public class RoleByIdResource extends RoleResource {
|
||||
RealmAuth.Resource r = null;
|
||||
if (roleModel.getContainer() instanceof RealmModel) {
|
||||
r = RealmAuth.Resource.REALM;
|
||||
} else if (roleModel.getContainer() instanceof ApplicationModel) {
|
||||
r = RealmAuth.Resource.APPLICATION;
|
||||
} else if (roleModel.getContainer() instanceof OAuthClientModel) {
|
||||
} else if (roleModel.getContainer() instanceof ClientModel) {
|
||||
r = RealmAuth.Resource.CLIENT;
|
||||
} else if (roleModel.getContainer() instanceof UserModel) {
|
||||
r = RealmAuth.Resource.USER;
|
||||
@@ -175,7 +172,7 @@ public class RoleByIdResource extends RoleResource {
|
||||
final @PathParam("app") String appName) {
|
||||
RoleModel role = getRoleModel(id);
|
||||
auth.requireView();
|
||||
ApplicationModel app = realm.getApplicationByName(appName);
|
||||
ClientModel app = realm.getClientByClientId(appName);
|
||||
if (app == null) {
|
||||
throw new NotFoundException("Could not find application: " + appName);
|
||||
|
||||
@@ -198,7 +195,7 @@ public class RoleByIdResource extends RoleResource {
|
||||
final @PathParam("appId") String appId) {
|
||||
RoleModel role = getRoleModel(id);
|
||||
auth.requireView();
|
||||
ApplicationModel app = realm.getApplicationById(appId);
|
||||
ClientModel app = realm.getClientById(appId);
|
||||
if (app == null) {
|
||||
throw new NotFoundException("Could not find application: " + appId);
|
||||
|
||||
|
||||
+3
-3
@@ -2,7 +2,7 @@ package org.keycloak.services.resources.admin;
|
||||
|
||||
import org.jboss.resteasy.annotations.cache.NoCache;
|
||||
import org.jboss.resteasy.spi.NotFoundException;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.ModelDuplicateException;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RoleContainerModel;
|
||||
@@ -225,7 +225,7 @@ public class RoleContainerResource extends RoleResource {
|
||||
if (role == null) {
|
||||
throw new NotFoundException("Could not find role: " + roleName);
|
||||
}
|
||||
ApplicationModel app = realm.getApplicationByName(appName);
|
||||
ClientModel app = realm.getClientByClientId(appName);
|
||||
if (app == null) {
|
||||
throw new NotFoundException("Could not find application: " + appName);
|
||||
|
||||
@@ -253,7 +253,7 @@ public class RoleContainerResource extends RoleResource {
|
||||
if (role == null) {
|
||||
throw new NotFoundException("Could not find role: " + roleName);
|
||||
}
|
||||
ApplicationModel app = realm.getApplicationById(appId);
|
||||
ClientModel app = realm.getClientById(appId);
|
||||
if (app == null) {
|
||||
throw new NotFoundException("Could not find application: " + appId);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.keycloak.services.resources.admin;
|
||||
|
||||
import org.jboss.resteasy.spi.NotFoundException;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.utils.ModelToRepresentation;
|
||||
@@ -69,7 +69,7 @@ public abstract class RoleResource {
|
||||
return composites;
|
||||
}
|
||||
|
||||
protected Set<RoleRepresentation> getApplicationRoleComposites(ApplicationModel app, RoleModel role) {
|
||||
protected Set<RoleRepresentation> getApplicationRoleComposites(ClientModel app, RoleModel role) {
|
||||
if (!role.isComposite() || role.getComposites().size() == 0) return Collections.emptySet();
|
||||
|
||||
Set<RoleRepresentation> composites = new HashSet<RoleRepresentation>(role.getComposites().size());
|
||||
|
||||
+2
-4
@@ -2,7 +2,6 @@ package org.keycloak.services.resources.admin;
|
||||
|
||||
import org.jboss.resteasy.annotations.cache.NoCache;
|
||||
import org.jboss.resteasy.spi.NotFoundException;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmModel;
|
||||
@@ -15,7 +14,6 @@ import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -30,9 +28,9 @@ public class ScopeMappedApplicationResource {
|
||||
private RealmAuth auth;
|
||||
protected ClientModel client;
|
||||
protected KeycloakSession session;
|
||||
protected ApplicationModel app;
|
||||
protected ClientModel app;
|
||||
|
||||
public ScopeMappedApplicationResource(RealmModel realm, RealmAuth auth, ClientModel client, KeycloakSession session, ApplicationModel app) {
|
||||
public ScopeMappedApplicationResource(RealmModel realm, RealmAuth auth, ClientModel client, KeycloakSession session, ClientModel app) {
|
||||
this.realm = realm;
|
||||
this.auth = auth;
|
||||
this.client = client;
|
||||
|
||||
+6
-7
@@ -2,7 +2,6 @@ package org.keycloak.services.resources.admin;
|
||||
|
||||
import org.jboss.resteasy.annotations.cache.NoCache;
|
||||
import org.jboss.resteasy.spi.NotFoundException;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmModel;
|
||||
@@ -65,21 +64,21 @@ public class ScopeMappedResource {
|
||||
all.setRealmMappings(realmRep);
|
||||
}
|
||||
|
||||
List<ApplicationModel> applications = realm.getApplications();
|
||||
List<ClientModel> applications = realm.getClients();
|
||||
if (applications.size() > 0) {
|
||||
Map<String, ApplicationMappingsRepresentation> appMappings = new HashMap<String, ApplicationMappingsRepresentation>();
|
||||
for (ApplicationModel app : applications) {
|
||||
for (ClientModel app : applications) {
|
||||
Set<RoleModel> roleMappings = app.getApplicationScopeMappings(client);
|
||||
if (roleMappings.size() > 0) {
|
||||
ApplicationMappingsRepresentation mappings = new ApplicationMappingsRepresentation();
|
||||
mappings.setApplicationId(app.getId());
|
||||
mappings.setApplication(app.getName());
|
||||
mappings.setApplication(app.getClientId());
|
||||
List<RoleRepresentation> roles = new ArrayList<RoleRepresentation>();
|
||||
mappings.setMappings(roles);
|
||||
for (RoleModel role : roleMappings) {
|
||||
roles.add(ModelToRepresentation.toRepresentation(role));
|
||||
}
|
||||
appMappings.put(app.getName(), mappings);
|
||||
appMappings.put(app.getClientId(), mappings);
|
||||
all.setApplicationMappings(appMappings);
|
||||
}
|
||||
}
|
||||
@@ -210,7 +209,7 @@ public class ScopeMappedResource {
|
||||
|
||||
@Path("applications/{app}")
|
||||
public ScopeMappedApplicationResource getApplicationScopeMappings(@PathParam("app") String appName) {
|
||||
ApplicationModel app = realm.getApplicationByName(appName);
|
||||
ClientModel app = realm.getClientByClientId(appName);
|
||||
|
||||
if (app == null) {
|
||||
throw new NotFoundException("Role not found");
|
||||
@@ -221,7 +220,7 @@ public class ScopeMappedResource {
|
||||
|
||||
@Path("applications-by-id/{appId}")
|
||||
public ScopeMappedApplicationResource getApplicationByIdScopeMappings(@PathParam("appId") String appId) {
|
||||
ApplicationModel app = realm.getApplicationById(appId);
|
||||
ClientModel app = realm.getClientById(appId);
|
||||
|
||||
if (app == null) {
|
||||
throw new NotFoundException("Application not found");
|
||||
|
||||
+5
-11
@@ -3,14 +3,11 @@ package org.keycloak.services.resources.admin;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.jboss.resteasy.annotations.cache.NoCache;
|
||||
import org.jboss.resteasy.spi.NotFoundException;
|
||||
import org.keycloak.ClientConnection;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.RoleModel;
|
||||
import org.keycloak.models.UserModel;
|
||||
import org.keycloak.models.utils.ModelToRepresentation;
|
||||
import org.keycloak.protocol.oidc.TokenManager;
|
||||
import org.keycloak.representations.idm.RoleRepresentation;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
@@ -18,10 +15,7 @@ import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -37,9 +31,9 @@ public class UserApplicationRoleMappingsResource {
|
||||
protected RealmModel realm;
|
||||
protected RealmAuth auth;
|
||||
protected UserModel user;
|
||||
protected ApplicationModel application;
|
||||
protected ClientModel application;
|
||||
|
||||
public UserApplicationRoleMappingsResource(RealmModel realm, RealmAuth auth, UserModel user, ApplicationModel application) {
|
||||
public UserApplicationRoleMappingsResource(RealmModel realm, RealmAuth auth, UserModel user, ClientModel application) {
|
||||
this.realm = realm;
|
||||
this.auth = auth;
|
||||
this.user = user;
|
||||
@@ -155,8 +149,8 @@ public class UserApplicationRoleMappingsResource {
|
||||
if (roles == null) {
|
||||
Set<RoleModel> roleModels = user.getApplicationRoleMappings(application);
|
||||
for (RoleModel roleModel : roleModels) {
|
||||
if (!(roleModel.getContainer() instanceof ApplicationModel)) {
|
||||
ApplicationModel app = (ApplicationModel) roleModel.getContainer();
|
||||
if (!(roleModel.getContainer() instanceof ClientModel)) {
|
||||
ClientModel app = (ClientModel) roleModel.getContainer();
|
||||
if (!app.getId().equals(application.getId())) continue;
|
||||
}
|
||||
user.deleteRoleMapping(roleModel);
|
||||
|
||||
@@ -7,7 +7,6 @@ import org.jboss.resteasy.spi.NotFoundException;
|
||||
import org.keycloak.ClientConnection;
|
||||
import org.keycloak.email.EmailException;
|
||||
import org.keycloak.email.EmailProvider;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.ClientSessionModel;
|
||||
import org.keycloak.models.Constants;
|
||||
@@ -440,21 +439,21 @@ public class UsersResource {
|
||||
all.setRealmMappings(realmRep);
|
||||
}
|
||||
|
||||
List<ApplicationModel> applications = realm.getApplications();
|
||||
List<ClientModel> applications = realm.getClients();
|
||||
if (applications.size() > 0) {
|
||||
Map<String, ApplicationMappingsRepresentation> appMappings = new HashMap<String, ApplicationMappingsRepresentation>();
|
||||
for (ApplicationModel application : applications) {
|
||||
for (ClientModel application : applications) {
|
||||
Set<RoleModel> roleMappings = user.getApplicationRoleMappings(application);
|
||||
if (roleMappings.size() > 0) {
|
||||
ApplicationMappingsRepresentation mappings = new ApplicationMappingsRepresentation();
|
||||
mappings.setApplicationId(application.getId());
|
||||
mappings.setApplication(application.getName());
|
||||
mappings.setApplication(application.getClientId());
|
||||
List<RoleRepresentation> roles = new ArrayList<RoleRepresentation>();
|
||||
mappings.setMappings(roles);
|
||||
for (RoleModel role : roleMappings) {
|
||||
roles.add(ModelToRepresentation.toRepresentation(role));
|
||||
}
|
||||
appMappings.put(application.getName(), mappings);
|
||||
appMappings.put(application.getClientId(), mappings);
|
||||
all.setApplicationMappings(appMappings);
|
||||
}
|
||||
}
|
||||
@@ -609,7 +608,7 @@ public class UsersResource {
|
||||
throw new NotFoundException("User not found");
|
||||
}
|
||||
|
||||
ApplicationModel application = realm.getApplicationByName(appName);
|
||||
ClientModel application = realm.getClientByClientId(appName);
|
||||
|
||||
if (application == null) {
|
||||
throw new NotFoundException("Application not found");
|
||||
@@ -625,7 +624,7 @@ public class UsersResource {
|
||||
throw new NotFoundException("User not found");
|
||||
}
|
||||
|
||||
ApplicationModel application = realm.getApplicationById(appId);
|
||||
ClientModel application = realm.getClientById(appId);
|
||||
|
||||
if (application == null) {
|
||||
throw new NotFoundException("Application not found");
|
||||
@@ -720,7 +719,7 @@ public class UsersResource {
|
||||
clientId = Constants.ACCOUNT_MANAGEMENT_APP;
|
||||
}
|
||||
|
||||
ClientModel client = realm.findClient(clientId);
|
||||
ClientModel client = realm.getClientByClientId(clientId);
|
||||
if (client == null || !client.isEnabled()) {
|
||||
return Flows.errors().error(clientId + " not enabled", Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user