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;
}
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);
}
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;
}
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);
}
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;
}
Aggregations