use of org.opencastproject.security.impl.jpa.JpaUser in project opencast by opencast.
the class ContributorsListProviderTest method setUp.
@Before
public void setUp() throws Exception {
String expectedFormat = "{\"organization\":\"mh_default\",\"username\":\"akm220\",\"presentation\":\"Adam McKenzie\"}";
organization = new JpaOrganization(ORG_ID, "name", null, null, null, null);
users = new ArrayList<User>();
user1 = new JpaUser("user1", "pass", organization, "User 1", "email1", "provider1", true);
user2 = new JpaUser("user2", "pass", organization, "User 2", "email1", "provider1", true);
user3 = new JpaUser("user3", "pass", organization, null, "email1", "provider1", true);
user4 = new JpaUser("user4", "pass", organization, "User 1", "email3", "provider1", true);
users.add(user1);
users.add(user2);
users.add(user3);
users.add(user4);
userDirectoryService = new UserDirectoryService() {
private Iterator<User> iterator;
@Override
public User loadUser(String userName) {
return null;
}
@Override
public Iterator<User> getUsers() {
return null;
}
@Override
public Iterator<User> findUsers(String query, int offset, int limit) {
iterator = users.iterator();
List<User> filteredList = new ArrayList<User>();
int i = 0;
while ((filteredList.size() < limit || limit == 0) && iterator.hasNext()) {
User item = iterator.next();
if (i++ >= offset) {
filteredList.add(item);
}
}
return filteredList.iterator();
}
@Override
public long countUsers() {
return users.size();
}
@Override
public void invalidate(String userName) {
return;
}
};
List<String> contributors = new ArrayList<String>();
contributors.add("User 1");
contributors.add("User 5");
searchIndex = EasyMock.createNiceMock(AbstractSearchIndex.class);
EasyMock.expect(searchIndex.getTermsForField(EasyMock.anyString(), EasyMock.anyObject(Option.class))).andReturn(contributors).anyTimes();
contributorsListProvider = new ContributorsListProvider();
contributorsListProvider.setUserDirectoryService(userDirectoryService);
contributorsListProvider.setIndex(searchIndex);
EasyMock.replay(searchIndex);
}
use of org.opencastproject.security.impl.jpa.JpaUser in project opencast by opencast.
the class UsersListProviderTest method setUp.
@Before
public void setUp() throws Exception {
users = new ArrayList<User>();
user1 = new JpaUser("user1", "pass", null, "user1", "email1", "provider1", true);
user2 = new JpaUser("user2", "pass", null, "user2", "email1", "provider1", true);
user3 = new JpaUser("user3", "pass", null, "user3", "email1", "provider1", true);
user4 = new JpaUser("user4", "pass", null, "user1", "email3", "provider1", true);
users.add(user1);
users.add(user2);
users.add(user3);
users.add(user4);
userDirectoryService = new UserDirectoryService() {
private Iterator<User> iterator;
@Override
public User loadUser(String userName) {
return null;
}
@Override
public Iterator<User> getUsers() {
return null;
}
@Override
public Iterator<User> findUsers(String query, int offset, int limit) {
iterator = users.iterator();
List<User> filteredList = new ArrayList<User>();
int i = 0;
while ((filteredList.size() < limit || limit == 0) && iterator.hasNext()) {
User item = iterator.next();
if (i++ >= offset) {
filteredList.add(item);
}
}
return filteredList.iterator();
}
@Override
public long countUsers() {
return users.size();
}
@Override
public void invalidate(String userName) {
return;
}
};
usersListProvider = new UsersListProvider();
usersListProvider.setUserDirectoryService(userDirectoryService);
}
use of org.opencastproject.security.impl.jpa.JpaUser in project opencast by opencast.
the class UserAndSeriesLoader method loadLdapUser.
/**
* Load a user for testing the ldap provider
*
* @param organizationId
* the organization
*/
protected void loadLdapUser(String organizationId) {
Set<JpaRole> ldapUserRoles = new HashSet<>();
ldapUserRoles.add(new JpaRole(USER_ROLE, getOrganization(organizationId)));
// This is the public identifier for Josh Holtzman in the UC Berkeley Directory, which is available for anonymous
// binding.
String ldapUserId = "231693";
if (jpaUserProvider.loadUser(ldapUserId, organizationId) == null) {
try {
jpaUserProvider.addUser(new JpaUser(ldapUserId, "ldap", getOrganization(organizationId), jpaUserProvider.getName(), true, ldapUserRoles));
logger.debug("Added ldap user '{}' into organization '{}'", ldapUserId, organizationId);
} catch (UnauthorizedException ex) {
logger.error("Unable to add an administrative user because you have not enough permissions.");
}
}
}
use of org.opencastproject.security.impl.jpa.JpaUser in project opencast by opencast.
the class UserAndSeriesLoader method load.
/**
* Loads demo users into persistence.
*
* @param rolePrefix
* the role prefix
* @param numPerSeries
* the number of users to load per series
* @param additionalRoles
* any additional roles to add for each user
* @param orgId
* the organization id
*/
protected void load(String rolePrefix, int numPerSeries, String[] additionalRoles, String orgId) {
String lowerCasePrefix = rolePrefix.toLowerCase();
int totalUsers = numPerSeries * NUM_SERIES;
logger.info("Adding sample {}s, usernames and passwords are {}1/{}1... {}{}/{}{}", lowerCasePrefix, lowerCasePrefix, lowerCasePrefix, lowerCasePrefix, totalUsers, lowerCasePrefix, totalUsers);
for (int i = 1; i <= totalUsers; i++) {
if (jpaUserProvider.loadUser(lowerCasePrefix + i, orgId) == null) {
Set<JpaRole> roleSet = new HashSet<>();
for (String additionalRole : additionalRoles) {
roleSet.add(new JpaRole(additionalRole, getOrganization(orgId)));
}
roleSet.add(new JpaRole(SERIES_PREFIX + (((i - 1) % NUM_SERIES) + 1) + "_" + rolePrefix, getOrganization(orgId)));
JpaUser user = new JpaUser(lowerCasePrefix + i, lowerCasePrefix + i, getOrganization(orgId), jpaUserProvider.getName(), true, roleSet);
try {
jpaUserProvider.addUser(user);
logger.debug("Added {}", user);
} catch (Exception e) {
logger.warn("Can not add {}: {}", user, e);
}
}
}
}
use of org.opencastproject.security.impl.jpa.JpaUser in project opencast by opencast.
the class UserDirectoryPersistenceUtil method findUser.
/**
* Returns the persisted user by the user id and organization id
*
* @param id
* the user's unique id
* @param organizationId
* the organization id
* @param emf
* the entity manager factory
* @return the user or <code>null</code> if not found
*/
public static JpaUser findUser(long id, String organizationId, EntityManagerFactory emf) {
EntityManager em = null;
try {
em = emf.createEntityManager();
Query q = em.createNamedQuery("User.findByIdAndOrg");
q.setParameter("id", id);
q.setParameter("org", organizationId);
return (JpaUser) q.getSingleResult();
} catch (NoResultException e) {
return null;
} finally {
if (em != null)
em.close();
}
}
Aggregations