use of org.infinispan.configuration.global.GlobalAuthorizationConfigurationBuilder in project infinispan by infinispan.
the class Parser method parseGlobalAuthorization.
private void parseGlobalAuthorization(ConfigurationReader reader, ConfigurationBuilderHolder holder) {
GlobalAuthorizationConfigurationBuilder builder = holder.getGlobalConfigurationBuilder().security().authorization().enable();
for (int i = 0; i < reader.getAttributeCount(); i++) {
String value = reader.getAttributeValue(i);
Attribute attribute = Attribute.forName(reader.getAttributeName(i));
switch(attribute) {
case AUDIT_LOGGER:
{
builder.auditLogger(Util.getInstance(value, holder.getClassLoader()));
break;
}
default:
{
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
PrincipalRoleMapper roleMapper = null;
RolePermissionMapper permissionMapper = null;
while (reader.hasNext()) {
reader.nextElement();
Element element = Element.forName(reader.getLocalName());
switch(element) {
case AUTHORIZATION:
{
reader.require(ConfigurationReader.ElementType.END_ELEMENT);
if (permissionMapper != null) {
builder.rolePermissionMapper(permissionMapper);
}
if (roleMapper != null) {
builder.principalRoleMapper(roleMapper);
}
return;
}
case CLUSTER_PERMISSION_MAPPER:
if (permissionMapper != null) {
throw ParseUtils.unexpectedElement(reader);
}
ParseUtils.requireNoAttributes(reader);
ParseUtils.requireNoContent(reader);
permissionMapper = new ClusterPermissionMapper();
break;
case CUSTOM_PERMISSION_MAPPER:
if (permissionMapper != null) {
throw ParseUtils.unexpectedElement(reader);
}
permissionMapper = parseCustomPermissionMapper(reader, holder);
break;
case IDENTITY_ROLE_MAPPER:
if (roleMapper != null) {
throw ParseUtils.unexpectedElement(reader);
}
ParseUtils.requireNoAttributes(reader);
ParseUtils.requireNoContent(reader);
roleMapper = new IdentityRoleMapper();
break;
case COMMON_NAME_ROLE_MAPPER:
if (roleMapper != null) {
throw ParseUtils.unexpectedElement(reader);
}
ParseUtils.requireNoAttributes(reader);
ParseUtils.requireNoContent(reader);
roleMapper = new CommonNameRoleMapper();
break;
case CLUSTER_ROLE_MAPPER:
if (roleMapper != null) {
throw ParseUtils.unexpectedElement(reader);
}
ParseUtils.requireNoAttributes(reader);
ParseUtils.requireNoContent(reader);
roleMapper = new ClusterRoleMapper();
break;
case CUSTOM_ROLE_MAPPER:
if (roleMapper != null) {
throw ParseUtils.unexpectedElement(reader);
}
roleMapper = parseCustomRoleMapper(reader, holder);
break;
case ROLES:
{
while (reader.inTag()) {
Map.Entry<String, String> item = reader.getMapItem(Attribute.NAME);
parseGlobalRole(reader, builder, item.getKey());
reader.endMapItem();
}
break;
}
case ROLE:
{
parseGlobalRole(reader, builder, null);
break;
}
default:
{
throw ParseUtils.unexpectedElement(reader);
}
}
}
}
use of org.infinispan.configuration.global.GlobalAuthorizationConfigurationBuilder in project infinispan by infinispan.
the class CustomAuditLoggerTest method createCacheManager.
@Override
protected EmbeddedCacheManager createCacheManager() throws Exception {
GlobalConfigurationBuilder global = new GlobalConfigurationBuilder();
GlobalAuthorizationConfigurationBuilder globalRoles = global.security().authorization().enable().principalRoleMapper(new IdentityRoleMapper()).auditLogger(LOGGER);
ConfigurationBuilder config = TestCacheManagerFactory.getDefaultCacheConfiguration(true);
AuthorizationConfigurationBuilder authConfig = config.security().authorization().enable();
globalRoles.role(ADMIN_ROLE).permission(AuthorizationPermission.ALL).role(READER_ROLE).permission(AuthorizationPermission.READ);
authConfig.role(ADMIN_ROLE).role(READER_ROLE);
return TestCacheManagerFactory.createCacheManager(global, config);
}
use of org.infinispan.configuration.global.GlobalAuthorizationConfigurationBuilder in project infinispan by infinispan.
the class DynamicRBACTest method getGlobalConfigurationBuilder.
private GlobalConfigurationBuilder getGlobalConfigurationBuilder() {
GlobalConfigurationBuilder global = GlobalConfigurationBuilder.defaultClusteredBuilder();
GlobalAuthorizationConfigurationBuilder globalRoles = global.security().authorization().enable().principalRoleMapper(new ClusterRoleMapper()).rolePermissionMapper(new ClusterPermissionMapper());
globalRoles.role("reader").permission(AuthorizationPermission.ALL_READ).role("writer").permission(AuthorizationPermission.ALL_WRITE).role("admin").permission(AuthorizationPermission.ALL);
return global;
}
use of org.infinispan.configuration.global.GlobalAuthorizationConfigurationBuilder in project infinispan by infinispan.
the class BackupWithSecurityTest method defaultGlobalConfigurationForSite.
@Override
protected GlobalConfigurationBuilder defaultGlobalConfigurationForSite(int siteIndex) {
GlobalConfigurationBuilder builder = super.defaultGlobalConfigurationForSite(siteIndex);
GlobalAuthorizationConfigurationBuilder globalRoles = builder.security().authorization().enable().principalRoleMapper(new IdentityRoleMapper());
for (AuthorizationPermission perm : AuthorizationPermission.values()) {
globalRoles.role(perm.toString()).permission(perm);
}
return builder;
}
use of org.infinispan.configuration.global.GlobalAuthorizationConfigurationBuilder in project infinispan by infinispan.
the class AbstractAuthentication method setupCache.
@Before
public void setupCache() throws Exception {
// global setup
globalConfig = new GlobalConfigurationBuilder();
GlobalAuthorizationConfigurationBuilder globalRoles = globalConfig.security().authorization().enable().principalRoleMapper(getPrincipalRoleMapper());
// cache setup
cacheConfig = new ConfigurationBuilder();
cacheConfig.transaction().lockingMode(LockingMode.PESSIMISTIC);
cacheConfig.invocationBatching().enable();
AuthorizationConfigurationBuilder authConfig = cacheConfig.security().authorization().enable();
// authorization setup
Map<String, AuthorizationPermission[]> rolePermissionMap = getRolePermissionMap();
for (Entry<String, AuthorizationPermission[]> role : rolePermissionMap.entrySet()) {
authConfig = authConfig.role(role.getKey());
GlobalRoleConfigurationBuilder roleBuilder = globalRoles.role(role.getKey());
for (AuthorizationPermission permission : role.getValue()) {
roleBuilder = roleBuilder.permission(permission);
}
}
Subject admin = getAdminSubject();
Security.doAs(admin, new PrivilegedExceptionAction<Void>() {
public Void run() {
manager = new DefaultCacheManager(globalConfig.build());
manager.defineConfiguration(CACHE_NAME, cacheConfig.build());
secureCache = manager.getCache(CACHE_NAME);
secureCache.put(TEST_ENTRY_KEY, TEST_ENTRY_VALUE);
return null;
}
});
}
Aggregations