Search in sources :

Example 1 with UserDetail

use of org.onebusaway.admin.model.ui.UserDetail in project onebusaway-application-modules by camsys.

the class UserManagementServiceImpl method getInactiveUsersDetails.

@Override
public List<UserDetail> getInactiveUsersDetails() {
    List<UserDetail> userDetails = new ArrayList<UserDetail>();
    List<User> users = hibernateTemplate.execute(new HibernateCallback<List<User>>() {

        @SuppressWarnings("unchecked")
        @Override
        public List<User> doInHibernate(Session session) throws HibernateException, SQLException {
            Criteria criteria = session.createCriteria(User.class).createCriteria("userIndices").add(Restrictions.eq("id.type", UserIndexTypes.USERNAME));
            List<User> users = criteria.list();
            return users;
        }
    });
    if (!users.isEmpty()) {
        for (User user : users) {
            UserBean bean = userService.getUserAsBean(user);
            if (bean.isDisabled()) {
                if (!user.getUserIndices().isEmpty()) {
                    UserDetail userDetail = buildUserDetail(user);
                    userDetails.add(userDetail);
                }
            }
        }
    }
    log.debug("Returning user details");
    return userDetails;
}
Also used : User(org.onebusaway.users.model.User) HibernateException(org.hibernate.HibernateException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Criteria(org.hibernate.Criteria) UserDetail(org.onebusaway.admin.model.ui.UserDetail) UserBean(org.onebusaway.users.client.model.UserBean) ArrayList(java.util.ArrayList) List(java.util.List) Session(org.hibernate.Session)

Example 2 with UserDetail

use of org.onebusaway.admin.model.ui.UserDetail in project onebusaway-application-modules by camsys.

the class UserManagementServiceImpl method getActiveUsersDetails.

@Override
public List<UserDetail> getActiveUsersDetails() {
    List<UserDetail> userDetails = new ArrayList<UserDetail>();
    List<User> users = hibernateTemplate.execute(new HibernateCallback<List<User>>() {

        @SuppressWarnings("unchecked")
        @Override
        public List<User> doInHibernate(Session session) throws HibernateException, SQLException {
            Criteria criteria = session.createCriteria(User.class).createCriteria("userIndices").add(Restrictions.eq("id.type", UserIndexTypes.USERNAME));
            List<User> users = criteria.list();
            return users;
        }
    });
    if (!users.isEmpty()) {
        for (User user : users) {
            UserBean bean = userService.getUserAsBean(user);
            if (!bean.isDisabled()) {
                if (!user.getUserIndices().isEmpty()) {
                    UserDetail userDetail = buildUserDetail(user);
                    userDetails.add(userDetail);
                }
            }
        }
    }
    log.debug("Returning user details");
    return userDetails;
}
Also used : User(org.onebusaway.users.model.User) HibernateException(org.hibernate.HibernateException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Criteria(org.hibernate.Criteria) UserDetail(org.onebusaway.admin.model.ui.UserDetail) UserBean(org.onebusaway.users.client.model.UserBean) ArrayList(java.util.ArrayList) List(java.util.List) Session(org.hibernate.Session)

Example 3 with UserDetail

use of org.onebusaway.admin.model.ui.UserDetail in project onebusaway-application-modules by camsys.

the class TemporaryPasswordServiceImpl method getTemporaryPasswordForUser.

@Override
public String getTemporaryPasswordForUser(String username) {
    String newpass = getTemporaryPassword();
    UserDetail detail = _userManagementService.getUserDetail(username);
    _log.warn("got userdetail for name: " + username);
    detail.setPassword(newpass);
    _userManagementService.updateUser(detail);
    setTemporaryPassword(username, true);
    return newpass;
}
Also used : UserDetail(org.onebusaway.admin.model.ui.UserDetail)

Example 4 with UserDetail

use of org.onebusaway.admin.model.ui.UserDetail in project onebusaway-application-modules by camsys.

the class UserManagementServiceImplTest method testUpdateNonExistingUser.

@Test
public void testUpdateNonExistingUser() {
    UserDetail userDetail = mock(UserDetail.class);
    when(userDetail.getId()).thenReturn(1);
    when(userDetail.getUsername()).thenReturn("admin2");
    when(userDao.getUserForId(1)).thenReturn(null);
    boolean success = service.updateUser(userDetail);
    assertFalse("Unable to update non existing user", success);
    verify(passwordEncoder, times(0)).encodePassword("password", "admin2");
    verify(userDao, times(0)).saveOrUpdateUser(user);
}
Also used : UserDetail(org.onebusaway.admin.model.ui.UserDetail) Test(org.junit.Test)

Example 5 with UserDetail

use of org.onebusaway.admin.model.ui.UserDetail in project onebusaway-application-modules by camsys.

the class UserManagementServiceImplTest method testDeactivateNonExistingUser.

@Test
public void testDeactivateNonExistingUser() {
    UserDetail userDetail = mock(UserDetail.class);
    when(userDetail.getId()).thenReturn(1);
    when(userDetail.getUsername()).thenReturn("admin2");
    when(userDao.getUserForId(1)).thenReturn(null);
    boolean success = service.deactivateUser(userDetail);
    assertFalse("Unable to delete non existing user", success);
    verify(userDao, times(0)).deleteUserIndex(isA(UserIndex.class));
    verify(userDao, times(0)).saveOrUpdateUser(user);
}
Also used : UserDetail(org.onebusaway.admin.model.ui.UserDetail) UserIndex(org.onebusaway.users.model.UserIndex) Test(org.junit.Test)

Aggregations

UserDetail (org.onebusaway.admin.model.ui.UserDetail)18 Test (org.junit.Test)6 UserIndex (org.onebusaway.users.model.UserIndex)6 StringReader (java.io.StringReader)4 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Criteria (org.hibernate.Criteria)4 HibernateException (org.hibernate.HibernateException)4 Session (org.hibernate.Session)4 User (org.onebusaway.users.model.User)4 UserRole (org.onebusaway.users.model.UserRole)4 UserBean (org.onebusaway.users.client.model.UserBean)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Response (javax.ws.rs.core.Response)1