Search in sources :

Example 6 with User

use of org.onebusaway.users.model.User 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 7 with User

use of org.onebusaway.users.model.User in project onebusaway-application-modules by camsys.

the class UserManagementServiceImpl method activateUser.

// Marks the user as active
@Override
public boolean activateUser(UserDetail userDetail) {
    User user = userService.getUserForId(userDetail.getId());
    if (user == null) {
        log.info("User '{}' does not exist in the system", userDetail.getUsername());
        return false;
    }
    userPropertiesService.activateUser(user);
    log.info("User '{}' activated successfully", userDetail.getUsername());
    return true;
}
Also used : User(org.onebusaway.users.model.User)

Example 8 with User

use of org.onebusaway.users.model.User in project onebusaway-application-modules by camsys.

the class UserManagementServiceImpl method deactivateUser.

// deletes the user
@Override
public boolean deactivateUser(UserDetail userDetail) {
    User user = userService.getUserForId(userDetail.getId());
    if (user == null) {
        log.info("User '{}' does not exist in the system", userDetail.getUsername());
        return false;
    }
    // user record itself is still present
    for (Iterator<UserIndex> it = user.getUserIndices().iterator(); it.hasNext(); ) {
        UserIndex userIndex = it.next();
        userDao.deleteUserIndex(userIndex);
        it.remove();
    }
    userDao.saveOrUpdateUser(user);
    log.info("User '{}' deleted successfully", userDetail.getUsername());
    return true;
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) User(org.onebusaway.users.model.User)

Example 9 with User

use of org.onebusaway.users.model.User in project onebusaway-application-modules by camsys.

the class AccessControlServiceImpl method currentUserHasPrivilege.

@Override
public boolean currentUserHasPrivilege(Privilege privilege) {
    UserIndex idx = currentUserService.getCurrentUserAsUserIndex();
    User user = (idx == null) ? null : idx.getUser();
    return userHasPrivilege(user, privilege);
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) User(org.onebusaway.users.model.User)

Example 10 with User

use of org.onebusaway.users.model.User in project onebusaway-application-modules by camsys.

the class UserPropertiesServiceVersionedInvocationHandler method getServiceForUserArgs.

private UserPropertiesService getServiceForUserArgs(Object[] args) {
    if (_preferredVersion != -1)
        return getServiceForVersion(_preferredVersion);
    int maxVersion = 0;
    if (args != null) {
        for (Object arg : args) {
            if (arg instanceof User) {
                User user = (User) arg;
                int version = getPropertiesVersion(user);
                maxVersion = Math.max(maxVersion, version);
            } else if (arg instanceof UserIndex) {
                UserIndex userIndex = (UserIndex) arg;
                int version = getPropertiesVersion(userIndex.getUser());
                maxVersion = Math.max(maxVersion, version);
            }
        }
    }
    return getServiceForVersion(maxVersion);
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) User(org.onebusaway.users.model.User)

Aggregations

User (org.onebusaway.users.model.User)56 UserIndex (org.onebusaway.users.model.UserIndex)23 UserIndexKey (org.onebusaway.users.model.UserIndexKey)16 Test (org.junit.Test)13 Date (java.util.Date)9 UserBean (org.onebusaway.users.client.model.UserBean)8 UserPropertiesV1 (org.onebusaway.users.model.UserPropertiesV1)7 ArrayList (java.util.ArrayList)5 IOException (java.io.IOException)4 SQLException (java.sql.SQLException)4 List (java.util.List)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)4 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)4 Criteria (org.hibernate.Criteria)4 HibernateException (org.hibernate.HibernateException)4 Session (org.hibernate.Session)4 UserDetail (org.onebusaway.admin.model.ui.UserDetail)4 RouteFilter (org.onebusaway.users.model.properties.RouteFilter)4 UserRole (org.onebusaway.users.model.UserRole)3