-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving the CacheRealmProvider interface to the legacy module
- Loading branch information
Showing
9 changed files
with
122 additions
and
19 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ | |
# | ||
|
||
org.keycloak.models.cache.CacheUserProviderSpi | ||
org.keycloak.models.cache.CacheRealmProviderSpi |
57 changes: 57 additions & 0 deletions
57
...rc/main/java/org/keycloak/services/resources/admin/ClearRealmCacheRealmAdminProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2022 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.keycloak.services.resources.admin; | ||
|
||
import org.keycloak.Config.Scope; | ||
import org.keycloak.models.KeycloakSession; | ||
import org.keycloak.models.KeycloakSessionFactory; | ||
import org.keycloak.models.RealmModel; | ||
import org.keycloak.services.resources.admin.ext.AdminRealmResourceProvider; | ||
import org.keycloak.services.resources.admin.ext.AdminRealmResourceProviderFactory; | ||
import org.keycloak.services.resources.admin.permissions.AdminPermissionEvaluator; | ||
|
||
public class ClearRealmCacheRealmAdminProvider implements AdminRealmResourceProviderFactory, AdminRealmResourceProvider { | ||
|
||
@Override | ||
public AdminRealmResourceProvider create(KeycloakSession session) { | ||
return this; | ||
} | ||
|
||
@Override | ||
public void init(Scope config) { | ||
} | ||
|
||
@Override | ||
public void postInit(KeycloakSessionFactory factory) { | ||
} | ||
|
||
@Override | ||
public void close() { | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return "clear-realm-cache"; | ||
} | ||
|
||
@Override | ||
public Object getResource(KeycloakSession session, RealmModel realm, AdminPermissionEvaluator auth, AdminEventBuilder adminEvent) { | ||
return new ClearRealmCacheResource(realm, auth, adminEvent); | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
...services/src/main/java/org/keycloak/services/resources/admin/ClearRealmCacheResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2022 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.keycloak.services.resources.admin; | ||
|
||
import org.keycloak.events.admin.OperationType; | ||
import org.keycloak.models.KeycloakSession; | ||
import org.keycloak.models.RealmModel; | ||
import org.keycloak.models.cache.CacheRealmProvider; | ||
import org.keycloak.models.cache.UserCache; | ||
import org.keycloak.services.resources.admin.permissions.AdminPermissionEvaluator; | ||
|
||
import javax.ws.rs.POST; | ||
import javax.ws.rs.core.Context; | ||
|
||
/** | ||
* Clear user cache. | ||
*/ | ||
public class ClearRealmCacheResource { | ||
protected RealmModel realm; | ||
|
||
protected AdminPermissionEvaluator auth; | ||
|
||
protected AdminEventBuilder adminEvent; | ||
|
||
@Context | ||
protected KeycloakSession session; | ||
|
||
public ClearRealmCacheResource(RealmModel realm, AdminPermissionEvaluator auth, AdminEventBuilder adminEvent) { | ||
this.auth = auth; | ||
this.realm = realm; | ||
this.adminEvent = adminEvent; | ||
} | ||
|
||
/** | ||
* Clear user cache | ||
*/ | ||
@POST | ||
public void clearRealmCache() { | ||
auth.realm().requireManageRealm(); | ||
|
||
CacheRealmProvider cache = session.getProvider(CacheRealmProvider.class); | ||
if (cache != null) { | ||
cache.clear(); | ||
} | ||
|
||
adminEvent.operation(OperationType.ACTION).resourcePath(session.getContext().getUri()).success(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters