Search in sources :

Example 1 with UserIndex

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;
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey)

Example 2 with UserIndex

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;
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey) User(org.onebusaway.users.model.User) UserBean(org.onebusaway.users.client.model.UserBean)

Example 3 with UserIndex

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;
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey) User(org.onebusaway.users.model.User)

Example 4 with UserIndex

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;
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) User(org.onebusaway.users.model.User)

Example 5 with UserIndex

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);
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) User(org.onebusaway.users.model.User)

Aggregations

UserIndex (org.onebusaway.users.model.UserIndex)44 User (org.onebusaway.users.model.User)23 UserIndexKey (org.onebusaway.users.model.UserIndexKey)22 Test (org.junit.Test)9 UserBean (org.onebusaway.users.client.model.UserBean)8 UserRole (org.onebusaway.users.model.UserRole)8 HashSet (java.util.HashSet)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 UserDetail (org.onebusaway.admin.model.ui.UserDetail)5 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 PostConstruct (javax.annotation.PostConstruct)3 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 UserPropertiesV2 (org.onebusaway.users.model.properties.UserPropertiesV2)2