use of org.onebusaway.users.model.User 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.User 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.User in project onebusaway-application-modules by camsys.
the class UserManagementServiceImplTest method testCreateUser.
@Test
public void testCreateUser() {
UserIndex userIndex = mock(UserIndex.class);
when(userService.getOrCreateUserForUsernameAndPassword("operator", "password")).thenReturn(userIndex);
boolean success = service.createUser("operator", "password", false);
assertTrue("Expecting user to be created successfully", success);
verify(userService).getOrCreateUserForUsernameAndPassword("operator", "password");
verify(userService, times(0)).enableAdminRoleForUser(isA(User.class), isA(Boolean.class));
}
use of org.onebusaway.users.model.User in project onebusaway-application-modules by camsys.
the class UserManagementServiceImpl method getUserDetails.
@Override
public List<UserDetail> getUserDetails(final int start, final int maxResults) {
List<UserDetail> userDetails = new ArrayList<UserDetail>();
List<User> users = hibernateTemplate.execute(new HibernateCallback<List<User>>() {
@SuppressWarnings("unchecked")
@Override
public List<User> doInHibernate(Session session) throws HibernateException, SQLException {
Criteria criteria = session.createCriteria(User.class).createCriteria("userIndices").add(Restrictions.eq("id.type", UserIndexTypes.USERNAME)).setFirstResult(start).setMaxResults(maxResults);
List<User> users = criteria.list();
return users;
}
});
if (!users.isEmpty()) {
for (User user : users) {
if (!user.getUserIndices().isEmpty()) {
UserDetail userDetail = buildUserDetail(user);
userDetails.add(userDetail);
}
}
}
log.debug("Returning user details");
return userDetails;
}
use of org.onebusaway.users.model.User in project onebusaway-application-modules by camsys.
the class UserManagementServiceImpl method getUserDetail.
@Override
public UserDetail getUserDetail(final String userName) {
List<User> users = hibernateTemplate.execute(new HibernateCallback<List<User>>() {
@SuppressWarnings("unchecked")
@Override
public List<User> doInHibernate(Session session) throws HibernateException, SQLException {
Criteria criteria = session.createCriteria(User.class).createCriteria("userIndices").add(Restrictions.like("id.value", userName));
List<User> users = criteria.list();
return users;
}
});
UserDetail userDetail = null;
if (!users.isEmpty()) {
userDetail = buildUserDetail(users.get(0));
}
log.debug("Returning user details for user : {}", userName);
return userDetail;
}
Aggregations