Search in sources :

Example 1 with UserIndexKey

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

Example 2 with UserIndexKey

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;
}
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 UserIndexKey

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

Example 4 with UserIndexKey

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

Example 5 with UserIndexKey

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();
}
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) Cacheable(org.onebusaway.container.cache.Cacheable) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

UserIndexKey (org.onebusaway.users.model.UserIndexKey)30 UserIndex (org.onebusaway.users.model.UserIndex)22 User (org.onebusaway.users.model.User)16 UserBean (org.onebusaway.users.client.model.UserBean)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 Test (org.junit.Test)4 IndexedUserDetails (org.onebusaway.users.model.IndexedUserDetails)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 PostConstruct (javax.annotation.PostConstruct)2 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 DefaultUserAuthenticationToken (org.onebusaway.users.impl.authentication.DefaultUserAuthenticationToken)2 UserRole (org.onebusaway.users.model.UserRole)2 UserPropertiesV2 (org.onebusaway.users.model.properties.UserPropertiesV2)2