use of org.onebusaway.users.model.UserIndex 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);
}
use of org.onebusaway.users.model.UserIndex in project onebusaway-application-modules by camsys.
the class UserServiceImpl method getOrCreateUserForIndexKey.
@Override
public UserIndex getOrCreateUserForIndexKey(UserIndexKey key, String credentials, boolean isAnonymous) {
UserIndex userIndex = _userDao.getUserIndexForId(key);
if (userIndex == null) {
User user = new User();
user.setCreationTime(new Date());
user.setTemporary(true);
user.setProperties(new UserPropertiesV4());
Set<UserRole> roles = new HashSet<UserRole>();
if (isAnonymous)
roles.add(_authoritiesService.getAnonymousRole());
else
roles.add(_authoritiesService.getUserRole());
user.setRoles(roles);
userIndex = new UserIndex();
userIndex.setId(key);
userIndex.setCredentials(credentials);
userIndex.setUser(user);
user.getUserIndices().add(userIndex);
_userDao.saveOrUpdateUser(user);
}
return userIndex;
}
use of org.onebusaway.users.model.UserIndex in project onebusaway-application-modules by camsys.
the class UserServiceImpl method removeUserIndexForUser.
@Override
public void removeUserIndexForUser(User user, UserIndexKey key) {
for (UserIndex index : user.getUserIndices()) {
if (index.getId().equals(key)) {
_userDao.deleteUserIndex(index);
index.setUser(null);
user.getUserIndices().remove(index);
_userDao.saveOrUpdateUser(user);
return;
}
}
}
use of org.onebusaway.users.model.UserIndex in project onebusaway-application-modules by camsys.
the class UserServiceImpl method getMinApiRequestIntervalForKey.
@Cacheable
@Transactional
@Override
public Long getMinApiRequestIntervalForKey(String key, @CacheableArgument(cacheRefreshIndicator = true) boolean forceRefresh) {
UserIndexKey indexKey = new UserIndexKey(UserIndexTypes.API_KEY, key);
UserIndex userIndex = getUserIndexForId(indexKey);
if (userIndex == null) {
return null;
}
User user = userIndex.getUser();
UserBean bean = getUserAsBean(user);
return bean.getMinApiRequestInterval();
}
use of org.onebusaway.users.model.UserIndex in project onebusaway-application-modules by camsys.
the class UserDetailsServiceImpl method getUserForIndexKey.
/**
**
* {@link IndexedUserDetailsService} Interface
***
*/
@Transactional
@Override
public IndexedUserDetails getUserForIndexKey(UserIndexKey key) throws UsernameNotFoundException, DataAccessException {
UserIndex userIndex = _userService.getUserIndexForId(key);
if (userIndex == null)
throw new UsernameNotFoundException(key.toString());
setLastAccessTimeForUser(userIndex);
return new IndexedUserDetailsImpl(_authoritiesService, userIndex);
}
Aggregations