Search in sources :

Example 1 with MetadataCASUpdate

use of org.apache.druid.metadata.MetadataCASUpdate in project druid by druid-io.

the class CoordinatorBasicAuthorizerMetadataStorageUpdater method tryUpdateGroupMappingMap.

private boolean tryUpdateGroupMappingMap(String prefix, Map<String, BasicAuthorizerGroupMapping> groupMappingMap, byte[] oldGroupMappingMapValue, byte[] newGroupMappingMapValue) {
    try {
        List<MetadataCASUpdate> updates = new ArrayList<>();
        if (groupMappingMap != null) {
            updates.add(createMetadataCASUpdate(prefix, oldGroupMappingMapValue, newGroupMappingMapValue, GROUP_MAPPINGS));
            boolean succeeded = connector.compareAndSwap(updates);
            if (succeeded) {
                cachedGroupMappingMaps.put(prefix, new BasicAuthorizerGroupMappingMapBundle(groupMappingMap, newGroupMappingMapValue));
                byte[] serializedGroupMappingAndRoleMap = getCurrentGroupMappingAndRoleMapSerialized(prefix);
                cacheNotifier.addUpdateGroupMapping(prefix, serializedGroupMappingAndRoleMap);
                return true;
            } else {
                return false;
            }
        }
        return false;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : MetadataCASUpdate(org.apache.druid.metadata.MetadataCASUpdate) ArrayList(java.util.ArrayList) BasicAuthorizerGroupMappingMapBundle(org.apache.druid.security.basic.authorization.entity.BasicAuthorizerGroupMappingMapBundle) BasicSecurityDBResourceException(org.apache.druid.security.basic.BasicSecurityDBResourceException) IOException(java.io.IOException)

Example 2 with MetadataCASUpdate

use of org.apache.druid.metadata.MetadataCASUpdate in project druid by druid-io.

the class CoordinatorBasicAuthenticatorMetadataStorageUpdater method tryUpdateUserMap.

private boolean tryUpdateUserMap(String prefix, Map<String, BasicAuthenticatorUser> userMap, byte[] oldValue, byte[] newValue) {
    try {
        MetadataCASUpdate update = new MetadataCASUpdate(connectorConfig.getConfigTable(), MetadataStorageConnector.CONFIG_TABLE_KEY_COLUMN, MetadataStorageConnector.CONFIG_TABLE_VALUE_COLUMN, getPrefixedKeyColumn(prefix, USERS), oldValue, newValue);
        boolean succeeded = connector.compareAndSwap(Collections.singletonList(update));
        if (succeeded) {
            cachedUserMaps.put(prefix, new BasicAuthenticatorUserMapBundle(userMap, newValue));
            cacheNotifier.addUserUpdate(prefix, newValue);
            return true;
        } else {
            return false;
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : MetadataCASUpdate(org.apache.druid.metadata.MetadataCASUpdate) BasicAuthenticatorUserMapBundle(org.apache.druid.security.basic.authentication.entity.BasicAuthenticatorUserMapBundle) BasicSecurityDBResourceException(org.apache.druid.security.basic.BasicSecurityDBResourceException)

Example 3 with MetadataCASUpdate

use of org.apache.druid.metadata.MetadataCASUpdate in project druid by druid-io.

the class CoordinatorBasicAuthorizerMetadataStorageUpdater method tryUpdateGroupMappingAndRoleMap.

private boolean tryUpdateGroupMappingAndRoleMap(String prefix, Map<String, BasicAuthorizerGroupMapping> groupMappingMap, byte[] oldGroupMappingMapValue, byte[] newGroupMappingMapValue, Map<String, BasicAuthorizerRole> roleMap, byte[] oldRoleMapValue, byte[] newRoleMapValue) {
    try {
        List<MetadataCASUpdate> updates = new ArrayList<>();
        if (groupMappingMap != null && roleMap != null) {
            updates.add(createMetadataCASUpdate(prefix, oldGroupMappingMapValue, newGroupMappingMapValue, GROUP_MAPPINGS));
            updates.add(createMetadataCASUpdate(prefix, oldRoleMapValue, newRoleMapValue, ROLES));
        }
        boolean succeeded = connector.compareAndSwap(updates);
        if (succeeded) {
            cachedGroupMappingMaps.put(prefix, new BasicAuthorizerGroupMappingMapBundle(groupMappingMap, newGroupMappingMapValue));
            cachedRoleMaps.put(prefix, new BasicAuthorizerRoleMapBundle(roleMap, newRoleMapValue));
            byte[] serializedGroupMappingAndRoleMap = getCurrentGroupMappingAndRoleMapSerialized(prefix);
            cacheNotifier.addUpdateGroupMapping(prefix, serializedGroupMappingAndRoleMap);
            return true;
        } else {
            return false;
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : MetadataCASUpdate(org.apache.druid.metadata.MetadataCASUpdate) ArrayList(java.util.ArrayList) BasicAuthorizerGroupMappingMapBundle(org.apache.druid.security.basic.authorization.entity.BasicAuthorizerGroupMappingMapBundle) BasicSecurityDBResourceException(org.apache.druid.security.basic.BasicSecurityDBResourceException) IOException(java.io.IOException) BasicAuthorizerRoleMapBundle(org.apache.druid.security.basic.authorization.entity.BasicAuthorizerRoleMapBundle)

Example 4 with MetadataCASUpdate

use of org.apache.druid.metadata.MetadataCASUpdate in project druid by druid-io.

the class CoordinatorBasicAuthorizerMetadataStorageUpdater method tryUpdateRoleMap.

private boolean tryUpdateRoleMap(String prefix, Map<String, BasicAuthorizerRole> roleMap, byte[] oldRoleMapValue, byte[] newRoleMapValue) {
    try {
        List<MetadataCASUpdate> updates = new ArrayList<>();
        if (roleMap != null) {
            updates.add(createMetadataCASUpdate(prefix, oldRoleMapValue, newRoleMapValue, ROLES));
            boolean succeeded = connector.compareAndSwap(updates);
            if (succeeded) {
                cachedRoleMaps.put(prefix, new BasicAuthorizerRoleMapBundle(roleMap, newRoleMapValue));
                byte[] serializedUserAndRoleMap = getCurrentUserAndRoleMapSerialized(prefix);
                cacheNotifier.addUpdateUser(prefix, serializedUserAndRoleMap);
                byte[] serializedGroupMappingAndRoleMap = getCurrentGroupMappingAndRoleMapSerialized(prefix);
                cacheNotifier.addUpdateGroupMapping(prefix, serializedGroupMappingAndRoleMap);
                return true;
            } else {
                return false;
            }
        }
        return false;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : MetadataCASUpdate(org.apache.druid.metadata.MetadataCASUpdate) ArrayList(java.util.ArrayList) BasicSecurityDBResourceException(org.apache.druid.security.basic.BasicSecurityDBResourceException) IOException(java.io.IOException) BasicAuthorizerRoleMapBundle(org.apache.druid.security.basic.authorization.entity.BasicAuthorizerRoleMapBundle)

Example 5 with MetadataCASUpdate

use of org.apache.druid.metadata.MetadataCASUpdate in project druid by druid-io.

the class CoordinatorBasicAuthorizerMetadataStorageUpdater method tryUpdateUserAndRoleMap.

private boolean tryUpdateUserAndRoleMap(String prefix, Map<String, BasicAuthorizerUser> userMap, byte[] oldUserMapValue, byte[] newUserMapValue, Map<String, BasicAuthorizerRole> roleMap, byte[] oldRoleMapValue, byte[] newRoleMapValue) {
    try {
        List<MetadataCASUpdate> updates = new ArrayList<>();
        if (userMap != null && roleMap != null) {
            updates.add(createMetadataCASUpdate(prefix, oldUserMapValue, newUserMapValue, USERS));
            updates.add(createMetadataCASUpdate(prefix, oldRoleMapValue, newRoleMapValue, ROLES));
            boolean succeeded = connector.compareAndSwap(updates);
            if (succeeded) {
                cachedUserMaps.put(prefix, new BasicAuthorizerUserMapBundle(userMap, newUserMapValue));
                cachedRoleMaps.put(prefix, new BasicAuthorizerRoleMapBundle(roleMap, newRoleMapValue));
                byte[] serializedUserAndRoleMap = getCurrentUserAndRoleMapSerialized(prefix);
                cacheNotifier.addUpdateUser(prefix, serializedUserAndRoleMap);
                return true;
            } else {
                return false;
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return false;
}
Also used : MetadataCASUpdate(org.apache.druid.metadata.MetadataCASUpdate) BasicAuthorizerUserMapBundle(org.apache.druid.security.basic.authorization.entity.BasicAuthorizerUserMapBundle) ArrayList(java.util.ArrayList) BasicSecurityDBResourceException(org.apache.druid.security.basic.BasicSecurityDBResourceException) IOException(java.io.IOException) BasicAuthorizerRoleMapBundle(org.apache.druid.security.basic.authorization.entity.BasicAuthorizerRoleMapBundle)

Aggregations

MetadataCASUpdate (org.apache.druid.metadata.MetadataCASUpdate)6 BasicSecurityDBResourceException (org.apache.druid.security.basic.BasicSecurityDBResourceException)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 BasicAuthorizerRoleMapBundle (org.apache.druid.security.basic.authorization.entity.BasicAuthorizerRoleMapBundle)3 BasicAuthorizerGroupMappingMapBundle (org.apache.druid.security.basic.authorization.entity.BasicAuthorizerGroupMappingMapBundle)2 BasicAuthorizerUserMapBundle (org.apache.druid.security.basic.authorization.entity.BasicAuthorizerUserMapBundle)2 BasicAuthenticatorUserMapBundle (org.apache.druid.security.basic.authentication.entity.BasicAuthenticatorUserMapBundle)1