Search in sources :

Example 6 with UserIndex

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);
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) User(org.onebusaway.users.model.User)

Example 7 with UserIndex

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;
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) User(org.onebusaway.users.model.User) UserRole(org.onebusaway.users.model.UserRole) Date(java.util.Date) UserPropertiesV4(org.onebusaway.users.model.properties.UserPropertiesV4) HashSet(java.util.HashSet)

Example 8 with 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;
        }
    }
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex)

Example 9 with UserIndex

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();
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey) User(org.onebusaway.users.model.User) UserBean(org.onebusaway.users.client.model.UserBean) Cacheable(org.onebusaway.container.cache.Cacheable) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with UserIndex

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);
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) UserIndex(org.onebusaway.users.model.UserIndex) Transactional(org.springframework.transaction.annotation.Transactional)

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