Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
@@ -0,0 +1,48 @@
/*
* Copyright 2014-2025 Real Logic Limited.
*
* 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
*
* https://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 io.aeron.cluster;

import io.aeron.cluster.codecs.BackupQueryDecoder;
import io.aeron.cluster.codecs.HeartbeatRequestDecoder;
import io.aeron.cluster.codecs.MessageHeaderDecoder;
import io.aeron.cluster.codecs.StandbySnapshotDecoder;
import io.aeron.security.AuthorisationService;

/**
* An {@link AuthorisationService} that allows the actions required by Cluster Backup
* and Aeron Cluster Standby.
*/
public enum AllowBackupAndStandbyAuthorisationService implements AuthorisationService
{
/**
* As there is no instance state then this object can be used to save on allocation.
*/
INSTANCE;

/**
* {@inheritDoc}
*/
public boolean isAuthorised(
final int protocolId,
final int actionId,
final Object type,
final byte[] encodedPrincipal)
{
return MessageHeaderDecoder.SCHEMA_ID == protocolId &&
(BackupQueryDecoder.TEMPLATE_ID == actionId || HeartbeatRequestDecoder.TEMPLATE_ID == actionId ||
StandbySnapshotDecoder.TEMPLATE_ID == actionId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -790,15 +790,12 @@ public static final class Configuration
public static final String AUTHORISATION_SERVICE_SUPPLIER_PROP_NAME =
"aeron.cluster.authorisation.service.supplier";

static final AuthorisationService ALLOW_ONLY_BACKUP_QUERIES = (protocolId, actionId, type, encodedPrincipal) ->
MessageHeaderDecoder.SCHEMA_ID == protocolId && BackupQueryDecoder.TEMPLATE_ID == actionId;

/**
* Default {@link AuthorisationServiceSupplier} that returns {@link AuthorisationService} that forbids all
* command from being executed (i.e. {@link AuthorisationService#DENY_ALL}).
*/
public static final AuthorisationServiceSupplier DEFAULT_AUTHORISATION_SERVICE_SUPPLIER =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JavaDoc should be updated describing which commands are allowed.

() -> ALLOW_ONLY_BACKUP_QUERIES;
() -> AllowBackupAndStandbyAuthorisationService.INSTANCE;

/**
* Size in bytes of the error buffer for the cluster.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
import static io.aeron.AeronCounters.CLUSTER_ELECTION_COUNT_TYPE_ID;
import static io.aeron.AeronCounters.CLUSTER_LEADERSHIP_TERM_ID_TYPE_ID;
import static io.aeron.AeronCounters.NODE_CONTROL_TOGGLE_TYPE_ID;
import static io.aeron.cluster.ConsensusModule.Configuration.ALLOW_ONLY_BACKUP_QUERIES;
import static io.aeron.cluster.ConsensusModule.Configuration.AUTHENTICATOR_SUPPLIER_PROP_NAME;
import static io.aeron.cluster.ConsensusModule.Configuration.AUTHORISATION_SERVICE_SUPPLIER_PROP_NAME;
import static io.aeron.cluster.ConsensusModule.Configuration.CLUSTER_CLOCK_PROP_NAME;
Expand Down Expand Up @@ -247,9 +246,9 @@ void rejectInvalidLogChannelParameters()
}

@Test
void defaultAuthorisationServiceSupplierReturnsADenyAllAuthorisationService()
void defaultAuthorisationServiceSupplierAllowsBackupAndStandby()
{
assertSame(ALLOW_ONLY_BACKUP_QUERIES, DEFAULT_AUTHORISATION_SERVICE_SUPPLIER.get());
assertSame(AllowBackupAndStandbyAuthorisationService.INSTANCE, DEFAULT_AUTHORISATION_SERVICE_SUPPLIER.get());
}

@Test
Expand Down
Loading