Search in sources :

Example 36 with UserIndex

use of org.onebusaway.users.model.UserIndex 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 37 with UserIndex

use of org.onebusaway.users.model.UserIndex 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)

Example 38 with UserIndex

use of org.onebusaway.users.model.UserIndex in project onebusaway-application-modules by camsys.

the class UserManagementServiceImpl method createUser.

@Override
public boolean createUser(String userName, String password, boolean admin) {
    UserIndex userIndex = userService.getOrCreateUserForUsernameAndPassword(userName, password);
    if (userIndex == null)
        return false;
    if (admin) {
        User user = userIndex.getUser();
        // Enable admin role
        userService.enableAdminRoleForUser(user, false);
        // Disable operator role. User can either be admin or operator but not both
        disableOperatorRole(user);
    }
    log.info("User '{}' created successfully", userName);
    return true;
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) User(org.onebusaway.users.model.User)

Example 39 with UserIndex

use of org.onebusaway.users.model.UserIndex in project onebusaway-application-modules by camsys.

the class UserManagementServiceImplTest method testUpdateUserRole.

@Test
public void testUpdateUserRole() {
    Integer userId = 1;
    UserDetail userDetail = mock(UserDetail.class);
    UserIndex userIndex = mock(UserIndex.class);
    UserRole userRole = mock(UserRole.class);
    Set<UserIndex> userIndices = new HashSet<UserIndex>();
    userIndices.add(userIndex);
    Set<UserRole> userRoles = new HashSet<UserRole>();
    userRoles.add(userRole);
    when(userRole.getName()).thenReturn("ROLE_USER");
    buildUserDetail(userId, userDetail, "");
    when(userService.getUserForId(userId)).thenReturn(user);
    when(user.getUserIndices()).thenReturn(userIndices);
    when(user.getRoles()).thenReturn(userRoles);
    boolean success = service.updateUser(userDetail);
    assertTrue("User's password updated successfully", success);
    verify(passwordEncoder, times(0)).encodePassword("", "admin");
    verify(authoritiesService).getUserRoleForName("ROLE_ADMINISTRATOR");
    verify(userDao).saveOrUpdateUser(user);
}
Also used : UserDetail(org.onebusaway.admin.model.ui.UserDetail) UserIndex(org.onebusaway.users.model.UserIndex) UserRole(org.onebusaway.users.model.UserRole) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 40 with UserIndex

use of org.onebusaway.users.model.UserIndex in project onebusaway-application-modules by camsys.

the class UserManagementServiceImplTest method testDeactivateUser.

@Test
public void testDeactivateUser() {
    Integer userId = 1;
    UserDetail userDetail = mock(UserDetail.class);
    buildUserDetail(userId, userDetail, "password");
    UserIndex userIndex = mock(UserIndex.class);
    Set<UserIndex> userIndices = new HashSet<UserIndex>();
    userIndices.add(userIndex);
    when(userService.getUserForId(userId)).thenReturn(user);
    when(user.getUserIndices()).thenReturn(userIndices);
    boolean success = service.deactivateUser(userDetail);
    assertTrue("User deactivated successfully", success);
    verify(userDao).deleteUserIndex(isA(UserIndex.class));
    verify(userDao).saveOrUpdateUser(user);
}
Also used : UserDetail(org.onebusaway.admin.model.ui.UserDetail) UserIndex(org.onebusaway.users.model.UserIndex) HashSet(java.util.HashSet) Test(org.junit.Test)

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