Search in sources :

Example 16 with UserIndex

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

the class CreateAPIKeyOnInitAction method execute.

@PostConstruct
public void execute() {
    if (createAPIKey) {
        UserIndexKey userIndexKey = new UserIndexKey(UserIndexTypes.API_KEY, key);
        UserIndex userIndex = _userService.getOrCreateUserForIndexKey(userIndexKey, key, false);
        _userPropertiesService.authorizeApi(userIndex.getUser(), 0);
    }
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey) PostConstruct(javax.annotation.PostConstruct)

Example 17 with UserIndex

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

the class UserDaoImplTest method testTransitionUserIndex.

@Test
public void testTransitionUserIndex() {
    User userA = new User();
    userA.setCreationTime(new Date());
    userA.setProperties(new UserPropertiesV2());
    UserIndex index = new UserIndex();
    index.setId(new UserIndexKey("test", "A"));
    index.setUser(userA);
    userA.getUserIndices().add(index);
    _dao.saveOrUpdateUser(userA);
    User userB = new User();
    userB.setCreationTime(new Date());
    userB.setProperties(new UserPropertiesV2());
    _dao.saveOrUpdateUser(userB);
    assertEquals(1, _dao.getUserForId(userA.getId()).getUserIndices().size());
    assertEquals(0, _dao.getUserForId(userB.getId()).getUserIndices().size());
    index.setUser(userB);
    userA.getUserIndices().remove(index);
    userB.getUserIndices().add(index);
    _dao.saveOrUpdateUsers(userA, userB);
    assertEquals(0, _dao.getUserForId(userA.getId()).getUserIndices().size());
    assertEquals(1, _dao.getUserForId(userB.getId()).getUserIndices().size());
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey) User(org.onebusaway.users.model.User) UserPropertiesV2(org.onebusaway.users.model.properties.UserPropertiesV2) Date(java.util.Date) Test(org.junit.Test)

Example 18 with UserIndex

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

the class UserServiceImplTest method testCompletePhoneNumberRegistration.

@Test
public void testCompletePhoneNumberRegistration() {
    User userA = createUser(1234);
    UserIndexKey key = new UserIndexKey(UserIndexTypes.PHONE_NUMBER, "12065551234");
    UserDao userDao = Mockito.mock(UserDao.class);
    _service.setUserDao(userDao);
    Mockito.when(userDao.getUserForId(1234)).thenReturn(userA);
    UserIndex migratedIndex = new UserIndex();
    migratedIndex.setId(key);
    migratedIndex.setUser(userA);
    migratedIndex.setCredentials("");
    Mockito.when(userDao.getUserIndexForId(key)).thenReturn(migratedIndex);
    UserIndexRegistrationService registrationService = Mockito.mock(UserIndexRegistrationService.class);
    _service.setUserIndexRegistrationService(registrationService);
    UserRegistration registration = new UserRegistration(1234, "5555");
    Mockito.when(registrationService.getRegistrationForUserIndexKey(key)).thenReturn(registration);
    UserPropertiesService userPropertiesService = Mockito.mock(UserPropertiesService.class);
    _service.setUserPropertiesService(userPropertiesService);
    User userB = createUser(1235);
    UserIndex index = createUserIndex(key.getType(), key.getValue(), userB);
    UserIndex updated = _service.completePhoneNumberRegistration(index, "5554");
    assertTrue(updated == null);
    updated = _service.completePhoneNumberRegistration(index, "5555");
    assertTrue(updated != null);
    Mockito.verify(userPropertiesService).mergeProperties(userB, userA);
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey) User(org.onebusaway.users.model.User) UserIndexRegistrationService(org.onebusaway.users.services.internal.UserIndexRegistrationService) UserDao(org.onebusaway.users.services.UserDao) UserPropertiesService(org.onebusaway.users.services.UserPropertiesService) UserRegistration(org.onebusaway.users.services.internal.UserRegistration) Test(org.junit.Test)

Example 19 with UserIndex

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

the class UserServiceImplTest method createUserIndex.

private UserIndex createUserIndex(String indexType, String indexValue, User user) {
    UserIndex index = new UserIndex();
    index.setId(new UserIndexKey(indexType, indexValue));
    index.setUser(user);
    index.setCredentials("");
    user.getUserIndices().add(index);
    return index;
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey)

Example 20 with UserIndex

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

the class UserManagementServiceImplTest method testCreateAdmin.

@Test
public void testCreateAdmin() {
    UserIndex userIndex = mock(UserIndex.class);
    UserRole role = mock(UserRole.class);
    Set<UserRole> roles = new HashSet<UserRole>();
    roles.add(role);
    when(userService.getOrCreateUserForUsernameAndPassword("admin", "password")).thenReturn(userIndex);
    when(userIndex.getUser()).thenReturn(user);
    when(authoritiesService.getUserRoleForName(StandardAuthoritiesService.USER)).thenReturn(role);
    when(user.getRoles()).thenReturn(roles);
    boolean success = service.createUser("admin", "password", true);
    assertTrue("Expecting user to be created successfully", success);
    verify(userService).getOrCreateUserForUsernameAndPassword("admin", "password");
    verify(userService).enableAdminRoleForUser(user, false);
    verify(userDao).saveOrUpdateUser(user);
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserRole(org.onebusaway.users.model.UserRole) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

UserIndex (org.onebusaway.users.model.UserIndex)44 User (org.onebusaway.users.model.User)23 UserIndexKey (org.onebusaway.users.model.UserIndexKey)22 Test (org.junit.Test)9 UserBean (org.onebusaway.users.client.model.UserBean)8 UserRole (org.onebusaway.users.model.UserRole)8 HashSet (java.util.HashSet)6 IOException (java.io.IOException)5 WebApplicationException (javax.ws.rs.WebApplicationException)5 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)5 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)5 UserDetail (org.onebusaway.admin.model.ui.UserDetail)5 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 PostConstruct (javax.annotation.PostConstruct)3 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Response (javax.ws.rs.core.Response)2 UserPropertiesV2 (org.onebusaway.users.model.properties.UserPropertiesV2)2