com.bazaarvoice.emodb.databus.auth.SystemProcessDatabusAuthorizer Maven / Gradle / Ivy
package com.bazaarvoice.emodb.databus.auth;
import com.bazaarvoice.emodb.databus.model.OwnedSubscription;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static java.util.Objects.requireNonNull;
/**
* {@link DatabusAuthorizer} for system processes, such as the canary and databus replay.
*/
public class SystemProcessDatabusAuthorizer implements DatabusAuthorizer {
private final Logger _log = LoggerFactory.getLogger(getClass());
private final String _systemOwnerId;
private final DatabusAuthorizerByOwner _processAuthorizer = new DatabusAuthorizerByOwner() {
@Override
public boolean canAccessSubscription(OwnedSubscription subscription) {
// System should only access its own subscriptions
return _systemOwnerId.equals(subscription.getOwnerId());
}
@Override
public boolean canReceiveEventsFromTable(String table) {
// System needs to be able to poll on updates to all tables
return true;
}
};
public SystemProcessDatabusAuthorizer(String systemOwnerId) {
_systemOwnerId = requireNonNull(systemOwnerId, "systemOwnerId");
}
@Override
public DatabusAuthorizerByOwner owner(String ownerId) {
if (_systemOwnerId.equals(ownerId)) {
return _processAuthorizer;
}
_log.warn("Non-system owner attempted authorization from system authorizer: {}", ownerId);
return ConstantDatabusAuthorizer.DENY_ALL.owner(ownerId);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy