use of org.infinispan.configuration.global.GlobalRoleConfigurationBuilder in project infinispan by infinispan.
the class Parser method parseGlobalRole.
private void parseGlobalRole(ConfigurationReader reader, GlobalAuthorizationConfigurationBuilder builder, String name) {
String permissions = ParseUtils.requireAttributes(reader, Attribute.PERMISSIONS.getLocalName())[0];
if (name == null) {
name = ParseUtils.requireAttributes(reader, Attribute.NAME.getLocalName())[0];
}
GlobalRoleConfigurationBuilder role = builder.role(name);
for (String permission : permissions.split("\\s+")) {
role.permission(permission);
}
for (int i = 0; i < reader.getAttributeCount(); i++) {
ParseUtils.requireNoNamespaceAttribute(reader, i);
Attribute attribute = Attribute.forName(reader.getAttributeName(i));
switch(attribute) {
case NAME:
case PERMISSIONS:
{
// Already handled
break;
}
default:
{
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
ParseUtils.requireNoContent(reader);
}
use of org.infinispan.configuration.global.GlobalRoleConfigurationBuilder 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