Search in sources :

Example 31 with UserIndex

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

the class UserServiceImpl method getUserAsBean.

@Override
public UserBean getUserAsBean(User user) {
    UserBean bean = new UserBean();
    bean.setUserId(Integer.toString(user.getId()));
    UserRole anonymous = _authoritiesService.getAnonymousRole();
    boolean isAnonymous = user.getRoles().contains(anonymous);
    bean.setAnonymous(isAnonymous);
    UserRole admin = _authoritiesService.getAdministratorRole();
    boolean isAdmin = user.getRoles().contains(admin);
    bean.setAdmin(isAdmin);
    List<UserIndexBean> indices = new ArrayList<UserIndexBean>();
    bean.setIndices(indices);
    for (UserIndex index : user.getUserIndices()) {
        UserIndexKey key = index.getId();
        UserIndexBean indexBean = new UserIndexBean();
        indexBean.setType(key.getType());
        indexBean.setValue(key.getValue());
        indices.add(indexBean);
    }
    _userPropertiesService.getUserAsBean(user, bean);
    return bean;
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexBean(org.onebusaway.users.client.model.UserIndexBean) UserIndexKey(org.onebusaway.users.model.UserIndexKey) UserBean(org.onebusaway.users.client.model.UserBean) UserRole(org.onebusaway.users.model.UserRole) ArrayList(java.util.ArrayList)

Example 32 with UserIndex

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

the class UserServiceImpl method mergeUsers.

@Override
public void mergeUsers(User sourceUser, User targetUser) {
    if (sourceUser.equals(targetUser))
        return;
    if (sourceUser.getCreationTime().before(targetUser.getCreationTime()))
        targetUser.setCreationTime(sourceUser.getCreationTime());
    _userPropertiesService.mergeProperties(sourceUser, targetUser);
    mergeRoles(sourceUser, targetUser);
    List<UserIndex> indices = new ArrayList<UserIndex>(sourceUser.getUserIndices());
    for (UserIndex index : indices) {
        index.setUser(targetUser);
        targetUser.getUserIndices().add(index);
    }
    sourceUser.getUserIndices().clear();
    _userDao.saveOrUpdateUsers(sourceUser, targetUser);
    deleteUser(sourceUser);
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) ArrayList(java.util.ArrayList)

Example 33 with UserIndex

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

the class UserServiceImpl method getUserIndexForUsername.

@Override
public UserIndex getUserIndexForUsername(String username) throws UsernameNotFoundException {
    int index = username.indexOf('_');
    if (index == -1)
        throw new UsernameNotFoundException("username did not take the form type_value: " + username);
    String type = username.substring(0, index);
    String value = username.substring(index + 1);
    UserIndexKey key = new UserIndexKey(type, value);
    UserIndex userIndex = getUserIndexForId(key);
    if (userIndex == null)
        throw new UsernameNotFoundException(key.toString());
    return userIndex;
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey)

Example 34 with UserIndex

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

the class UserDaoImplTest method deleteUser.

@Test
public void deleteUser() {
    UserRole userRole = new UserRole("user");
    _dao.saveOrUpdateUserRole(userRole);
    User user = new User();
    user.setCreationTime(new Date());
    user.setProperties(new UserPropertiesV2());
    user.getRoles().add(userRole);
    UserIndexKey key = new UserIndexKey("phone", "2065551234");
    UserIndex index = new UserIndex();
    index.setId(key);
    index.setUser(user);
    user.getUserIndices().add(index);
    _dao.saveOrUpdateUser(user);
    assertEquals(1, _dao.getNumberOfUsers());
    UserIndex index2 = _dao.getUserIndexForId(key);
    assertEquals(key, index2.getId());
    assertEquals(user, index2.getUser());
    _dao.deleteUser(user);
    assertEquals(0, _dao.getNumberOfUsers());
    index2 = _dao.getUserIndexForId(key);
    assertNull(index2);
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey) User(org.onebusaway.users.model.User) UserRole(org.onebusaway.users.model.UserRole) UserPropertiesV2(org.onebusaway.users.model.properties.UserPropertiesV2) Date(java.util.Date) Test(org.junit.Test)

Example 35 with UserIndex

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

the class IndexedUserAuthenticationProcessorFilter method obtainUsername.

/* during authentication, if you are trying to retrieve the username
  and the user isDisabled in the properties, it will return null
  Without the username, the user can not log in
  */
@Override
protected String obtainUsername(HttpServletRequest request) {
    String username = super.obtainUsername(request);
    if (username != null) {
        username = username.trim();
        if (username.length() > 0) {
            username = obtainUserIndexType(request) + "_" + username;
        }
    }
    UserIndex userIndex = _userService.getUserIndexForUsername(username);
    UserBean bean = _userService.getUserAsBean(userIndex.getUser());
    if (bean == null | bean.isDisabled()) {
        return null;
    }
    return username;
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserBean(org.onebusaway.users.client.model.UserBean)

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