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));
}
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]);
}
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()));
}
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)));
}
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);
}
}
Aggregations