use of org.onebusaway.users.model.UserIndexKey in project onebusaway-application-modules by camsys.
the class ApiKeyAction method saveAPIKey.
/**
* Handle the "Save" action for either creating a new key or updating
* an existing one.
* @return success message
*/
public String saveAPIKey() {
// Check if key already exists
UserIndexKey userKey = new UserIndexKey(UserIndexTypes.API_KEY, key);
UserIndex userIndexForId = userService.getUserIndexForId(userKey);
if (userIndexForId == null) {
createAPIKey(key);
addActionMessage("Key '" + key + "' created successfully");
} else {
updateAPIKey(userIndexForId);
addActionMessage("Key '" + key + "' updated successfully");
}
clearContactInfoAndKey();
return SUCCESS;
}
use of org.onebusaway.users.model.UserIndexKey in project onebusaway-application-modules by camsys.
the class ApiKeyAction method searchContactEmail.
public String searchContactEmail() {
String searchResult = "Email address '" + contactEmail + "' could not be found";
List<String> apiKeys = userService.getUserIndexKeyValuesForKeyType(UserIndexTypes.API_KEY);
// clear other fields
contactName = "";
contactCompany = "";
contactDetails = "";
key = "";
for (String apiKey : apiKeys) {
// for each api key, check if contact email matches
UserIndexKey userKey = new UserIndexKey(UserIndexTypes.API_KEY, apiKey);
UserIndex userIndex = userService.getUserIndexForId(userKey);
if (userIndex != null) {
User user = userIndex.getUser();
UserBean bean = userService.getUserAsBean(user);
if (contactEmail.equals(bean.getContactEmail())) {
minApiReqInt = bean.getMinApiRequestInterval();
contactName = bean.getContactName();
contactCompany = bean.getContactCompany();
contactDetails = bean.getContactDetails();
key = apiKey;
searchResult = "Email address '" + contactEmail + "' found";
break;
}
}
}
addActionMessage(searchResult);
return SUCCESS;
}
use of org.onebusaway.users.model.UserIndexKey in project onebusaway-application-modules by camsys.
the class ApiKeyAction method deleteAPIKey.
public String deleteAPIKey() {
// 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();
boolean found = false;
for (UserIndex index : user.getUserIndices()) {
if (index.getId().getValue().equalsIgnoreCase(userKey.getValue())) {
userIndexForId = index;
found = true;
break;
}
}
if (!found) {
addActionMessage("API key " + key + " not found (no exact match).");
}
userService.removeUserIndexForUser(user, userIndexForId.getId());
if (user.getUserIndices().isEmpty()) {
userService.deleteUser(user);
}
// Clear the cached value here
userService.getMinApiRequestIntervalForKey(key, true);
addActionMessage("Key '" + key + "' deleted");
clearContactInfoAndKey();
}
return SUCCESS;
}
use of org.onebusaway.users.model.UserIndexKey in project onebusaway-application-modules by camsys.
the class UserServiceImpl method setPasswordForUsernameUserIndex.
@Override
public void setPasswordForUsernameUserIndex(UserIndex userIndex, String password) {
UserIndexKey id = userIndex.getId();
if (!UserIndexTypes.USERNAME.equals(id.getType()))
throw new IllegalArgumentException("expected UserIndex of type " + UserIndexTypes.USERNAME);
String credentials = _passwordEncoder.encodePassword(password, id.getValue());
setCredentialsForUserIndex(userIndex, credentials);
}
use of org.onebusaway.users.model.UserIndexKey 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();
}
Aggregations