Search in sources :

Example 6 with UserIndexKey

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

the class UserDetailsServiceImpl method loadUserByUsername.

/**
 **
 * {@link UserDetailsService} Interface
 ***
 */
@Transactional
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
    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);
    return getUserForIndexKey(key);
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) UserIndexKey(org.onebusaway.users.model.UserIndexKey) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with UserIndexKey

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

the class AutoUserCurrentUserStrategyImpl method createAuthentication.

protected Authentication createAuthentication() {
    UUID uuid = UUID.randomUUID();
    UUID credentials = UUID.randomUUID();
    UserIndexKey principal = new UserIndexKey(UserIndexTypes.WEB, uuid.toString());
    IndexedUserDetails details = _userDetailsService.getOrCreateUserForIndexKey(principal, credentials.toString(), true);
    return new DefaultUserAuthenticationToken(details);
}
Also used : UserIndexKey(org.onebusaway.users.model.UserIndexKey) IndexedUserDetails(org.onebusaway.users.model.IndexedUserDetails) DefaultUserAuthenticationToken(org.onebusaway.users.impl.authentication.DefaultUserAuthenticationToken) UUID(java.util.UUID)

Example 8 with UserIndexKey

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

the class CurrentUserServiceImpl method handleAddAccount.

@Override
public IndexedUserDetails handleAddAccount(String type, String id, String credentials, boolean isAnonymous) {
    User currentUser = _currentUserStrategy.getCurrentUser(false);
    UserIndexKey key = new UserIndexKey(type, id);
    UserIndex index = _userService.getUserIndexForId(key);
    boolean exists = index != null;
    // New user?
    if (exists) {
        if (currentUser != null) {
            User existingUser = index.getUser();
            _userService.mergeUsers(existingUser, currentUser);
        }
    } else {
        if (currentUser != null)
            index = _userService.addUserIndexToUser(currentUser, key, credentials);
        else
            index = _userService.getOrCreateUserForIndexKey(key, credentials, isAnonymous);
    }
    return new IndexedUserDetailsImpl(_authoritiesService, index);
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey) User(org.onebusaway.users.model.User)

Example 9 with UserIndexKey

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

the class CurrentUserServiceImpl method handleRegistration.

@Override
public IndexedUserDetails handleRegistration(String type, String id, String credentials, boolean isAnonymous) {
    UserIndexKey key = new UserIndexKey(type, id);
    UserIndex index = _userService.getOrCreateUserForIndexKey(key, credentials, isAnonymous);
    User oldUser = _currentUserStrategy.getCurrentUser(false);
    if (oldUser != null && _userService.isAnonymous(oldUser))
        _userService.mergeUsers(oldUser, index.getUser());
    return new IndexedUserDetailsImpl(_authoritiesService, index);
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey) User(org.onebusaway.users.model.User)

Example 10 with UserIndexKey

use of org.onebusaway.users.model.UserIndexKey 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)

Aggregations

UserIndexKey (org.onebusaway.users.model.UserIndexKey)30 UserIndex (org.onebusaway.users.model.UserIndex)22 User (org.onebusaway.users.model.User)16 UserBean (org.onebusaway.users.client.model.UserBean)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 Test (org.junit.Test)4 IndexedUserDetails (org.onebusaway.users.model.IndexedUserDetails)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 PostConstruct (javax.annotation.PostConstruct)2 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 DefaultUserAuthenticationToken (org.onebusaway.users.impl.authentication.DefaultUserAuthenticationToken)2 UserRole (org.onebusaway.users.model.UserRole)2 UserPropertiesV2 (org.onebusaway.users.model.properties.UserPropertiesV2)2