Search in sources :

Example 1 with GlobalRoleConfigurationBuilder

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);
}
Also used : ParseUtils.ignoreAttribute(org.infinispan.configuration.parsing.ParseUtils.ignoreAttribute) GlobalRoleConfigurationBuilder(org.infinispan.configuration.global.GlobalRoleConfigurationBuilder)

Example 2 with GlobalRoleConfigurationBuilder

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;
        }
    });
}
Also used : GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) GlobalAuthorizationConfigurationBuilder(org.infinispan.configuration.global.GlobalAuthorizationConfigurationBuilder) GlobalRoleConfigurationBuilder(org.infinispan.configuration.global.GlobalRoleConfigurationBuilder) AuthorizationConfigurationBuilder(org.infinispan.configuration.cache.AuthorizationConfigurationBuilder) DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) AuthorizationPermission(org.infinispan.security.AuthorizationPermission) GlobalAuthorizationConfigurationBuilder(org.infinispan.configuration.global.GlobalAuthorizationConfigurationBuilder) GlobalAuthorizationConfigurationBuilder(org.infinispan.configuration.global.GlobalAuthorizationConfigurationBuilder) AuthorizationConfigurationBuilder(org.infinispan.configuration.cache.AuthorizationConfigurationBuilder) Subject(javax.security.auth.Subject) GlobalRoleConfigurationBuilder(org.infinispan.configuration.global.GlobalRoleConfigurationBuilder) Before(org.junit.Before)

Aggregations

GlobalRoleConfigurationBuilder (org.infinispan.configuration.global.GlobalRoleConfigurationBuilder)2 Subject (javax.security.auth.Subject)1 AuthorizationConfigurationBuilder (org.infinispan.configuration.cache.AuthorizationConfigurationBuilder)1 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)1 GlobalAuthorizationConfigurationBuilder (org.infinispan.configuration.global.GlobalAuthorizationConfigurationBuilder)1 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)1 ParseUtils.ignoreAttribute (org.infinispan.configuration.parsing.ParseUtils.ignoreAttribute)1 DefaultCacheManager (org.infinispan.manager.DefaultCacheManager)1 AuthorizationPermission (org.infinispan.security.AuthorizationPermission)1 Before (org.junit.Before)1