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