Search in sources :

Example 51 with User

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

the class ApiKeyAction method createAPIKey.

/**
 * Creates API key in the database
 * @return success message
 */
public void createAPIKey(String apiKey) {
    UserIndexKey userIndexKey = new UserIndexKey(UserIndexTypes.API_KEY, apiKey);
    UserIndex userIndex = userService.getOrCreateUserForIndexKey(userIndexKey, apiKey, false);
    if (minApiReqInt == null) {
        minApiReqInt = MIN_API_REQ_INT_DEFAULT;
    }
    userPropertiesService.authorizeApi(userIndex.getUser(), minApiReqInt);
    // Set the API Key contact info
    User user = userIndex.getUser();
    userPropertiesService.updateApiKeyContactInfo(user, contactName, contactCompany, contactEmail, contactDetails);
    // Clear the cached value here
    userService.getMinApiRequestIntervalForKey(apiKey, true);
    return;
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey) User(org.onebusaway.users.model.User)

Example 52 with User

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

the class UserManagementServiceImpl method createUser.

@Override
public boolean createUser(String userName, String password, boolean admin) {
    UserIndex userIndex = userService.getOrCreateUserForUsernameAndPassword(userName, password);
    if (userIndex == null)
        return false;
    if (admin) {
        User user = userIndex.getUser();
        // Enable admin role
        userService.enableAdminRoleForUser(user, false);
        // Disable operator role. User can either be admin or operator but not both
        disableOperatorRole(user);
    }
    log.info("User '{}' created successfully", userName);
    return true;
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) User(org.onebusaway.users.model.User)

Example 53 with User

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

the class UserManagementServiceImplTest method testCreateUser.

@Test
public void testCreateUser() {
    UserIndex userIndex = mock(UserIndex.class);
    when(userService.getOrCreateUserForUsernameAndPassword("operator", "password")).thenReturn(userIndex);
    boolean success = service.createUser("operator", "password", false);
    assertTrue("Expecting user to be created successfully", success);
    verify(userService).getOrCreateUserForUsernameAndPassword("operator", "password");
    verify(userService, times(0)).enableAdminRoleForUser(isA(User.class), isA(Boolean.class));
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) User(org.onebusaway.users.model.User) Test(org.junit.Test)

Example 54 with User

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

the class UserManagementServiceImpl method getUserDetails.

@Override
public List<UserDetail> getUserDetails(final int start, final int maxResults) {
    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)).setFirstResult(start).setMaxResults(maxResults);
            List<User> users = criteria.list();
            return users;
        }
    });
    if (!users.isEmpty()) {
        for (User user : users) {
            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) ArrayList(java.util.ArrayList) List(java.util.List) Session(org.hibernate.Session)

Example 55 with User

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

the class UserManagementServiceImpl method getUserDetail.

@Override
public UserDetail getUserDetail(final String userName) {
    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.like("id.value", userName));
            List<User> users = criteria.list();
            return users;
        }
    });
    UserDetail userDetail = null;
    if (!users.isEmpty()) {
        userDetail = buildUserDetail(users.get(0));
    }
    log.debug("Returning user details for user : {}", userName);
    return userDetail;
}
Also used : UserDetail(org.onebusaway.admin.model.ui.UserDetail) User(org.onebusaway.users.model.User) HibernateException(org.hibernate.HibernateException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) List(java.util.List) Criteria(org.hibernate.Criteria) Session(org.hibernate.Session)

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