8000 Return 403 when invalidating the rotated client secret without permission by ksquare0608 · Pull Request #55538 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;

import org.keycloak.OAuthErrorException;
import org.keycloak.authorization.admin.AuthorizationService;
Expand Down Expand Up @@ -807,28 +806,23 @@ public ManagementPermissionReference setManagementPermissionsEnabled(ManagementP
@Tag(name = KeycloakOpenAPI.Admin.Tags.CLIENTS)
@Operation( summary = "Invalidate the rotated secret for the client")
public Response invalidateRotatedSecret() {
try{
auth.clients().requireConfigure(client);
auth.clients().requireConfigure(client);

logger.debug("delete rotated secret");
logger.debug("delete rotated secret");

// Always remove rotated secret attributes even when the feature is disabled,
// so stale secrets cannot become valid again if the feature is re-enabled.
OIDCClientSecretConfigWrapper wrapper = OIDCClientSecretConfigWrapper.fromClientModel(client);
// Always remove rotated secret attributes even when the feature is disabled,
// so stale secrets cannot become valid again if the feature is re-enabled.
OIDCClientSecretConfigWrapper wrapper = OIDCClientSecretConfigWrapper.fromClientModel(client);

CredentialRepresentation rep = new CredentialRepresentation();
rep.setType(CredentialRepresentation.SECRET);
rep.setValue(wrapper.getClientRotatedSecret(session));
CredentialRepresentation rep = new CredentialRepresentation();
rep.setType(CredentialRepresentation.SECRET);
rep.setValue(wrapper.getClientRotatedSecret(session));

adminEvent.operation(OperationType.DELETE).resourcePath(session.getContext().getUri()).representation(rep).success();
adminEvent.operation(OperationType.DELETE).resourcePath(session.getContext().getUri()).representation(rep).success();

wrapper.removeClientSecretRotated();
wrapper.removeClientSecretRotated();

return Response.noContent().build();
} catch (RuntimeException rte) {
throw new ErrorResponseException(rte.getCause().getMessage(), rte.getMessage(),
Status.INTERNAL_SERVER_ERROR);
}
return Response.noContent().build();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public void clients() {
invoke(realm -> realm.clients().get(foo.getId()).regenerateRegistrationAccessToken(), Resource.CLIENT, true);
invoke(realm -> realm.clients().get(foo.getId()).getSecret(), Resource.CLIENT, true);
invoke(realm -> realm.clients().get(foo.getId()).getClientRotatedSecret(), Resource.CLIENT, true);
invoke(realm -> realm.clients().get(foo.getId()).invalidateRotatedSecret(), Resource.CLIENT, true);
invoke(realm -> realm.clients().get(foo.getId()).pushRevocation(), Resource.CLIENT, true);
invoke(realm -> realm.clients().get(foo.getId()).getApplicationSessionCount(), Resource.CLIENT, false);
invoke(realm -> realm.clients().get(foo.getId()).getUserSessions(0, 100), Resource.CLIENT, false);
Expand Down
0