Search in sources :

Example 1 with SystemPermissionsImpl

use of org.eclipse.che.multiuser.api.permission.server.model.impl.SystemPermissionsImpl in project che-server by eclipse-che.

the class SystemPermissionsTckModule method configure.

@Override
protected void configure() {
    H2DBTestServer server = H2DBTestServer.startDefault();
    install(new PersistTestModuleBuilder().setDriver(Driver.class).runningOn(server).addEntityClasses(UserImpl.class, AccountImpl.class, AbstractPermissions.class, SystemPermissionsImpl.class).setExceptionHandler(H2ExceptionHandler.class).build());
    bind(DBInitializer.class).asEagerSingleton();
    bind(SchemaInitializer.class).toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
    bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server));
    // Creates empty multibinder to avoid error during container starting
    Multibinder.newSetBinder(binder(), String.class, Names.named(SystemDomain.SYSTEM_DOMAIN_ACTIONS));
    bind(new TypeLiteral<AbstractPermissionsDomain<SystemPermissionsImpl>>() {
    }).to(TestDomain.class);
    bind(new TypeLiteral<PermissionsDao<SystemPermissionsImpl>>() {
    }).to(JpaSystemPermissionsDao.class);
    bind(new TypeLiteral<TckRepository<SystemPermissionsImpl>>() {
    }).toInstance(new JpaTckRepository<>(SystemPermissionsImpl.class));
    bind(new TypeLiteral<TckRepository<UserImpl>>() {
    }).toInstance(new JpaTckRepository<>(UserImpl.class));
}
Also used : TckResourcesCleaner(org.eclipse.che.commons.test.tck.TckResourcesCleaner) H2DBTestServer(org.eclipse.che.commons.test.db.H2DBTestServer) AccountImpl(org.eclipse.che.account.spi.AccountImpl) Driver(org.h2.Driver) AbstractPermissions(org.eclipse.che.multiuser.api.permission.server.model.impl.AbstractPermissions) H2JpaCleaner(org.eclipse.che.commons.test.db.H2JpaCleaner) PersistTestModuleBuilder(org.eclipse.che.commons.test.db.PersistTestModuleBuilder) SchemaInitializer(org.eclipse.che.core.db.schema.SchemaInitializer) FlywaySchemaInitializer(org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer) FlywaySchemaInitializer(org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer) TypeLiteral(com.google.inject.TypeLiteral) DBInitializer(org.eclipse.che.core.db.DBInitializer) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) SystemPermissionsImpl(org.eclipse.che.multiuser.api.permission.server.model.impl.SystemPermissionsImpl)

Example 2 with SystemPermissionsImpl

use of org.eclipse.che.multiuser.api.permission.server.model.impl.SystemPermissionsImpl in project che-server by eclipse-che.

the class SystemPermissionsDaoTest method shouldBeAbleToGetPermissions.

@Test
public void shouldBeAbleToGetPermissions() throws Exception {
    final SystemPermissionsImpl result1 = dao.get(systemPermissions[0].getUserId(), systemPermissions[0].getInstanceId());
    final SystemPermissionsImpl result2 = dao.get(systemPermissions[1].getUserId(), systemPermissions[1].getInstanceId());
    assertEquals(result1, systemPermissions[0]);
    assertEquals(result2, systemPermissions[1]);
}
Also used : SystemPermissionsImpl(org.eclipse.che.multiuser.api.permission.server.model.impl.SystemPermissionsImpl) Test(org.testng.annotations.Test)

Example 3 with SystemPermissionsImpl

use of org.eclipse.che.multiuser.api.permission.server.model.impl.SystemPermissionsImpl in project che-server by eclipse-che.

the class SystemPermissionsDaoTest method setupEntities.

@BeforeMethod
public void setupEntities() throws Exception {
    systemPermissions = new SystemPermissionsImpl[] { new SystemPermissionsImpl("user1", asList("read", "use", "run")), new SystemPermissionsImpl("user2", asList("read", "use")), new SystemPermissionsImpl("user3", asList("read", "use")) };
    users = new UserImpl[] { new UserImpl("user1", "user1@com.com", "usr1"), new UserImpl("user2", "user2@com.com", "usr2"), new UserImpl("user3", "user3@com.com", "usr3") };
    userRepository.createAll(asList(users));
    systemRepository.createAll(Stream.of(systemPermissions).map(SystemPermissionsImpl::new).collect(Collectors.toList()));
}
Also used : UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) SystemPermissionsImpl(org.eclipse.che.multiuser.api.permission.server.model.impl.SystemPermissionsImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with SystemPermissionsImpl

use of org.eclipse.che.multiuser.api.permission.server.model.impl.SystemPermissionsImpl in project che-server by eclipse-che.

the class AdminPermissionInitializerTest method shouldAddSystemPermissionsOnPostUserPersistedEvent.

@Test
public void shouldAddSystemPermissionsOnPostUserPersistedEvent() throws Exception {
    // given
    when(userManager.getByName(eq(NAME))).thenReturn(user);
    doNothing().when(permissionsManager).storePermission(any(SystemPermissionsImpl.class));
    doReturn(new SystemDomain(Collections.emptySet())).when(permissionsManager).getDomain(anyString());
    initializer.init();
    // when
    initializer.onEvent(new PostUserPersistedEvent(new UserImpl(NAME, EMAIL, NAME, PASSWORD, emptyList())));
    // then
    verify(permissionsManager).storePermission(argThat((ArgumentMatcher<SystemPermissionsImpl>) argument -> argument.getUserId().equals(NAME)));
}
Also used : PostUserPersistedEvent(org.eclipse.che.api.user.server.event.PostUserPersistedEvent) ArgumentMatcher(org.mockito.ArgumentMatcher) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) SystemPermissionsImpl(org.eclipse.che.multiuser.api.permission.server.model.impl.SystemPermissionsImpl) Test(org.testng.annotations.Test)

Example 5 with SystemPermissionsImpl

use of org.eclipse.che.multiuser.api.permission.server.model.impl.SystemPermissionsImpl in project che-server by eclipse-che.

the class JpaSystemPermissionsDao method getByInstance.

@Override
@Transactional
public Page<SystemPermissionsImpl> getByInstance(String instanceId, int maxItems, long skipCount) throws ServerException {
    checkArgument(skipCount <= Integer.MAX_VALUE, "The number of items to skip can't be greater than " + Integer.MAX_VALUE);
    // instanceId is ignored because system domain doesn't require it
    try {
        final EntityManager entityManager = managerProvider.get();
        final List<SystemPermissionsImpl> permissions = entityManager.createNamedQuery("SystemPermissions.getAll", SystemPermissionsImpl.class).setMaxResults(maxItems).setFirstResult((int) skipCount).getResultList().stream().map(SystemPermissionsImpl::new).collect(toList());
        final Long totalCount = entityManager.createNamedQuery("SystemPermissions.getTotalCount", Long.class).getSingleResult();
        return new Page<>(permissions, skipCount, maxItems, totalCount);
    } catch (RuntimeException e) {
        throw new ServerException(e.getLocalizedMessage(), e);
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ServerException(org.eclipse.che.api.core.ServerException) SystemPermissionsImpl(org.eclipse.che.multiuser.api.permission.server.model.impl.SystemPermissionsImpl) Page(org.eclipse.che.api.core.Page) Transactional(com.google.inject.persist.Transactional)

Aggregations

SystemPermissionsImpl (org.eclipse.che.multiuser.api.permission.server.model.impl.SystemPermissionsImpl)14 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)10 TypeLiteral (com.google.inject.TypeLiteral)6 AccountImpl (org.eclipse.che.account.spi.AccountImpl)6 TckResourcesCleaner (org.eclipse.che.commons.test.tck.TckResourcesCleaner)6 DBInitializer (org.eclipse.che.core.db.DBInitializer)6 SchemaInitializer (org.eclipse.che.core.db.schema.SchemaInitializer)6 FlywaySchemaInitializer (org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer)6 JpaPersistModule (com.google.inject.persist.jpa.JpaPersistModule)4 HashMap (java.util.HashMap)4 UserDevfileImpl (org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl)4 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)4 SystemPermissionsDaoTest (org.eclipse.che.multiuser.api.permission.server.spi.tck.SystemPermissionsDaoTest)4 JpaSignatureKeyDao (org.eclipse.che.multiuser.machine.authentication.server.signature.jpa.JpaSignatureKeyDao)4 SignatureKeyPairImpl (org.eclipse.che.multiuser.machine.authentication.server.signature.model.impl.SignatureKeyPairImpl)4 SignatureKeyDao (org.eclipse.che.multiuser.machine.authentication.server.signature.spi.SignatureKeyDao)4 MemberDao (org.eclipse.che.multiuser.organization.spi.MemberDao)4 OrganizationDao (org.eclipse.che.multiuser.organization.spi.OrganizationDao)4 OrganizationDistributedResourcesDao (org.eclipse.che.multiuser.organization.spi.OrganizationDistributedResourcesDao)4 MemberImpl (org.eclipse.che.multiuser.organization.spi.impl.MemberImpl)4