use of org.onebusaway.users.model.UserIndex 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.UserIndex 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.UserIndex 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.UserIndex in project onebusaway-application-modules by camsys.
the class UserManagementServiceImpl method deactivateUser.
// deletes the user
@Override
public boolean deactivateUser(UserDetail userDetail) {
User user = userService.getUserForId(userDetail.getId());
if (user == null) {
log.info("User '{}' does not exist in the system", userDetail.getUsername());
return false;
}
// user record itself is still present
for (Iterator<UserIndex> it = user.getUserIndices().iterator(); it.hasNext(); ) {
UserIndex userIndex = it.next();
userDao.deleteUserIndex(userIndex);
it.remove();
}
userDao.saveOrUpdateUser(user);
log.info("User '{}' deleted successfully", userDetail.getUsername());
return true;
}
use of org.onebusaway.users.model.UserIndex in project onebusaway-application-modules by camsys.
the class AccessControlServiceImpl method currentUserHasPrivilege.
@Override
public boolean currentUserHasPrivilege(Privilege privilege) {
UserIndex idx = currentUserService.getCurrentUserAsUserIndex();
User user = (idx == null) ? null : idx.getUser();
return userHasPrivilege(user, privilege);
}
Aggregations