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;
}
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;
}
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;
}
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);
}
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);
}
Aggregations