Search in sources :

Example 1 with AuthorizationPermission

use of org.infinispan.security.AuthorizationPermission 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;
}
Also used : GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) IdentityRoleMapper(org.infinispan.security.mappers.IdentityRoleMapper) AuthorizationPermission(org.infinispan.security.AuthorizationPermission) GlobalAuthorizationConfigurationBuilder(org.infinispan.configuration.global.GlobalAuthorizationConfigurationBuilder)

Example 2 with AuthorizationPermission

use of org.infinispan.security.AuthorizationPermission in project infinispan by infinispan.

the class BackupWithSecurityTest method defaultConfigurationForSite.

@Override
protected ConfigurationBuilder defaultConfigurationForSite(int siteIndex) {
    ConfigurationBuilder builder = super.defaultConfigurationForSite(siteIndex);
    AuthorizationConfigurationBuilder authConfig = builder.security().authorization().enable();
    for (AuthorizationPermission perm : AuthorizationPermission.values()) {
        authConfig.role(perm.toString());
    }
    return builder;
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) GlobalAuthorizationConfigurationBuilder(org.infinispan.configuration.global.GlobalAuthorizationConfigurationBuilder) AuthorizationConfigurationBuilder(org.infinispan.configuration.cache.AuthorizationConfigurationBuilder) AuthorizationPermission(org.infinispan.security.AuthorizationPermission) GlobalAuthorizationConfigurationBuilder(org.infinispan.configuration.global.GlobalAuthorizationConfigurationBuilder) AuthorizationConfigurationBuilder(org.infinispan.configuration.cache.AuthorizationConfigurationBuilder)

Example 3 with AuthorizationPermission

use of org.infinispan.security.AuthorizationPermission in project infinispan by infinispan.

the class AbstractInfinispanServerDriver method createUserFile.

protected void createUserFile(String realm) {
    // Create users and groups for individual permissions
    UserTool userTool = new UserTool(rootDir.getAbsolutePath());
    for (AuthorizationPermission permission : AuthorizationPermission.values()) {
        String name = permission.name().toLowerCase();
        userTool.createUser(name + "_user", name, realm, UserTool.Encryption.DEFAULT, Collections.singletonList(name), null);
    }
    // Create users with composite roles
    for (TestUser user : TestUser.values()) {
        if (user != TestUser.ANONYMOUS) {
            userTool.createUser(user.getUser(), user.getPassword(), realm, UserTool.Encryption.DEFAULT, user.getRoles(), null);
        }
    }
}
Also used : AuthorizationPermission(org.infinispan.security.AuthorizationPermission) UserTool(org.infinispan.cli.user.UserTool) TestUser(org.infinispan.server.test.api.TestUser)

Example 4 with AuthorizationPermission

use of org.infinispan.security.AuthorizationPermission in project infinispan by infinispan.

the class SecurityRealmServerListener method before.

@Override
public void before(InfinispanServerDriver driver) {
    UserTool userTool = new UserTool(driver.getRootDir().getAbsolutePath(), realm + "-users.properties", realm + "-groups.properties");
    // Create users and groups for individual permissions
    for (AuthorizationPermission permission : AuthorizationPermission.values()) {
        String name = permission.name().toLowerCase();
        userTool.createUser(username(name + "_user"), name, realm, UserTool.Encryption.DEFAULT, Collections.singletonList(name), null);
    }
    // Create users with composite roles
    for (TestUser user : TestUser.values()) {
        if (user != TestUser.ANONYMOUS) {
            userTool.createUser(username(user.getUser()), user.getPassword(), realm, UserTool.Encryption.DEFAULT, user.getRoles(), null);
        }
    }
}
Also used : AuthorizationPermission(org.infinispan.security.AuthorizationPermission) UserTool(org.infinispan.cli.user.UserTool) TestUser(org.infinispan.server.test.api.TestUser)

Example 5 with AuthorizationPermission

use of org.infinispan.security.AuthorizationPermission 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

AuthorizationPermission (org.infinispan.security.AuthorizationPermission)6 GlobalAuthorizationConfigurationBuilder (org.infinispan.configuration.global.GlobalAuthorizationConfigurationBuilder)3 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)3 Subject (javax.security.auth.Subject)2 UserTool (org.infinispan.cli.user.UserTool)2 AuthorizationConfigurationBuilder (org.infinispan.configuration.cache.AuthorizationConfigurationBuilder)2 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)2 TestUser (org.infinispan.server.test.api.TestUser)2 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)1 BAD_REQUEST (io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST)1 CONFLICT (io.netty.handler.codec.http.HttpResponseStatus.CONFLICT)1 NO_CONTENT (io.netty.handler.codec.http.HttpResponseStatus.NO_CONTENT)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 CompletionStage (java.util.concurrent.CompletionStage)1 Collectors (java.util.stream.Collectors)1