Java Code Examples for com.haulmont.cuba.security.entity.User#getId()

The following examples show how to use com.haulmont.cuba.security.entity.User#getId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EclipseLinkDetachedTest.java    From cuba with Apache License 2.0 6 votes vote down vote up
@BeforeEach
public void setUp() throws Exception {
    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();

        User user = new User();
        userId = user.getId();
        user.setName("testUser");
        user.setLogin("testLogin");
        user.setPosition("manager");
        user.setGroup(em.find(Group.class, UUID.fromString("0fa2b1a5-1d68-4d69-9fbd-dff348347f93")));
        em.persist(user);

        UserRole userRole = new UserRole();
        userRoleId = userRole.getId();
        userRole.setUser(user);
        userRole.setRoleName("test-role");
        em.persist(userRole);

        tx.commit();
    } finally {
        tx.end();
    }
}
 
Example 2
Source File: PersistenceTest.java    From cuba with Apache License 2.0 6 votes vote down vote up
@BeforeEach
public void setUp() throws Exception {
    QueryRunner runner = new QueryRunner(cont.persistence().getDataSource());
    runner.update("delete from SYS_SERVER");

    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();

        User user = new User();
        userId = user.getId();
        user.setName("testUser");
        user.setLogin("testLogin");
        user.setGroup(em.find(Group.class, UUID.fromString("0fa2b1a5-1d68-4d69-9fbd-dff348347f93")));
        em.persist(user);

        tx.commit();
    } finally {
        tx.end();
    }
}
 
Example 3
Source File: UserRoleTest.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();

        Role role = new Role();
        role.setName("testRole1");
        em.persist(role);

        Group group = new Group();
        group.setName("testGroup1");
        em.persist(group);

        User user = new User();
        UUID userId = user.getId();
        user.setLogin("testUser1");
        user.setName("Test User 1");
        user.setGroup(group);
        em.persist(user);

        UserRole userRole = new UserRole();
        userRole.setUser(user);
        userRole.setRole(role);
        em.persist(userRole);

        tx.commitRetaining();

        em = cont.persistence().getEntityManager();
        user = em.find(User.class, userId);
        List<UserRole> userRoles = user.getUserRoles();
        assertEquals(1, userRoles.size());
        for (UserRole ur : userRoles) {
            Role r = ur.getRole();
            assertEquals(role.getName(), r.getName());
        }
    } finally {
        tx.end();
    }
}
 
Example 4
Source File: LoginTest.java    From cuba with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setUp() throws Exception {
    PasswordEncryption passwordEncryption = AppBeans.get(PasswordEncryption.NAME);
    authenticationManager = AppBeans.get(AuthenticationManager.NAME);
    userSessionSource = AppBeans.get(UserSessionSource.NAME);
    standardTestUserSession = userSessionSource.getUserSession();

    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();

        Group group = em.getReference(Group.class, UUID.fromString("0fa2b1a5-1d68-4d69-9fbd-dff348347f93"));

        User user1 = new User();
        user1Id = user1.getId();
        user1.setGroup(group);
        user1.setLogin("user1");
        user1.setPassword(passwordEncryption.getPasswordHash(user1.getId(), "1"));
        em.persist(user1);

        User user2 = new User();
        user2Id = user2.getId();
        user2.setGroup(group);
        user2.setLogin("user2");
        user2.setPassword(passwordEncryption.getPasswordHash(user2.getId(), "2"));
        em.persist(user2);

        tx.commit();
    } finally {
        tx.end();
    }
}
 
Example 5
Source File: PersistenceAttributeLoadedCheckTest.java    From cuba with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setUp() throws Exception {
    dataManager = AppBeans.get(DataManager.class);
    persistence = AppBeans.get(Persistence.class);

    try (Transaction tx = persistence.createTransaction()) {
        EntityManager em = persistence.getEntityManager();

        ScheduledTask task = new ScheduledTask();
        task.setBeanName("BeanName");
        task.setMethodName("MethodName");
        taskId = task.getId();

        User user = new User();
        userId = user.getId();
        user.setName("testUser");
        user.setLogin("login" + userId);
        user.setPassword("000");
        user.setGroup(em.find(Group.class, groupId));
        em.persist(user);

        em.persist(task);
        em.persist(user);
        tx.commit();
    }

    taskView = new View(ScheduledTask.class, true)
            .addProperty("beanName");

    userView = new View(User.class, true)
            .addProperty("login")
            .addProperty("loginLowerCase")
            .addProperty("name")
            .addProperty("password")
            .addProperty("group", new View(Group.class).addProperty("name"))
            .addProperty("userRoles", new View(UserRole.class));
}
 
Example 6
Source File: DataManagerCommitTest.java    From cuba with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setUp() throws Exception {
    dataManager = AppBeans.get(DataManager.class);

    try (Transaction tx = cont.persistence().createTransaction()) {
        EntityManager em = cont.persistence().getEntityManager();

        Group group = em.find(Group.class, groupId);

        User user = new User();
        userId = user.getId();
        user.setName("testUser");
        user.setLogin("login" + userId);
        user.setPassword("000");
        user.setGroup(group);
        em.persist(user);

        UserRole userRole = new UserRole();
        userRoleId = userRole.getId();
        userRole.setRoleName("test-role");
        userRole.setUser(user);
        em.persist(userRole);

        tx.commit();
    }

    view = new View(User.class, true)
            .addProperty("login")
            .addProperty("loginLowerCase")
            .addProperty("name")
            .addProperty("password")
            .addProperty("group", new View(Group.class).addProperty("name"))
            .addProperty("userRoles", new View(UserRole.class));
}
 
Example 7
Source File: OrmBehaviorTest.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Test
public void testPersistWithUnManagedAttribute() throws Exception {
    Group group = new Group();
    groupId = group.getId();
    group.setName("Old Name");
    Transaction tx = cont.persistence().createTransaction();
    try {
        cont.persistence().getEntityManager().persist(group);
        tx.commit();
    } finally {
        tx.end();
    }

    // Let's imagine that this entity was loaded with MyBatis
    Group g = new Group();
    g.setId(groupId);
    g.setName("Old Name");

    User user = new User();
    userId = user.getId();
    user.setLogin("typednativesqlquery");
    user.setGroup(g);
    user.setName("Test");

    tx = cont.persistence().createTransaction();
    try {
        cont.persistence().getEntityManager().persist(user);
        tx.commitRetaining();

        user = cont.persistence().getEntityManager().find(User.class, userId,
                new View(User.class).addProperty("group"));
        tx.commit();
    } finally {
        tx.end();
    }

    user = reserialize(user);
    assertEquals(groupId, user.getGroup().getId());
}
 
Example 8
Source File: TestBeforeCommitTxListener.java    From cuba with Apache License 2.0 5 votes vote down vote up
private void createEntity(EntityManager entityManager) {
    Group companyGroup = entityManager.find(Group.class, TestSupport.COMPANY_GROUP_ID);
    User u = metadata.create(User.class);
    createdEntityId = u.getId();
    u.setLogin("TxLstnrTst-" + u.getId());
    u.setLoginLowerCase(u.getLogin().toLowerCase());
    u.setGroup(companyGroup);
    entityManager.persist(u);
}