Search in sources :

Example 26 with UserIndexKey

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

Example 27 with UserIndexKey

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

Example 28 with UserIndexKey

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);
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey) User(org.onebusaway.users.model.User) UserRole(org.onebusaway.users.model.UserRole) UserPropertiesV2(org.onebusaway.users.model.properties.UserPropertiesV2) Date(java.util.Date) Test(org.junit.Test)

Example 29 with UserIndexKey

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

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

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