use of org.onebusaway.users.model.UserIndexKey in project onebusaway-application-modules by camsys.
the class UserServiceImpl method getOrCreateUserForUsernameAndPassword.
@Override
public UserIndex getOrCreateUserForUsernameAndPassword(String username, String password) {
String credentials = _passwordEncoder.encodePassword(password, username);
UserIndexKey key = new UserIndexKey(UserIndexTypes.USERNAME, username);
return getOrCreateUserForIndexKey(key, credentials, false);
}
use of org.onebusaway.users.model.UserIndexKey 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.UserIndexKey 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.UserIndexKey in project onebusaway-application-modules by camsys.
the class ApiKeyAction method searchAPIKey.
public String searchAPIKey() {
// Check if key already exists
UserIndexKey userKey = new UserIndexKey(UserIndexTypes.API_KEY, key);
UserIndex userIndexForId = userService.getUserIndexForId(userKey);
if (userIndexForId == null) {
addActionMessage("Key '" + key + "' does not exist");
} else {
User user = userIndexForId.getUser();
UserBean bean = userService.getUserAsBean(user);
minApiReqInt = bean.getMinApiRequestInterval();
contactName = bean.getContactName();
contactCompany = bean.getContactCompany();
contactEmail = bean.getContactEmail();
contactDetails = bean.getContactDetails();
addActionMessage("Key '" + key + "' found");
}
return SUCCESS;
}
use of org.onebusaway.users.model.UserIndexKey in project onebusaway-application-modules by camsys.
the class ApiKeyAction method createAPIKey.
/**
* Creates API key in the database
* @return success message
*/
public void createAPIKey(String apiKey) {
UserIndexKey userIndexKey = new UserIndexKey(UserIndexTypes.API_KEY, apiKey);
UserIndex userIndex = userService.getOrCreateUserForIndexKey(userIndexKey, apiKey, false);
if (minApiReqInt == null) {
minApiReqInt = MIN_API_REQ_INT_DEFAULT;
}
userPropertiesService.authorizeApi(userIndex.getUser(), minApiReqInt);
// Set the API Key contact info
User user = userIndex.getUser();
userPropertiesService.updateApiKeyContactInfo(user, contactName, contactCompany, contactEmail, contactDetails);
// Clear the cached value here
userService.getMinApiRequestIntervalForKey(apiKey, true);
return;
}
Aggregations