use of org.opencastproject.security.api.JaxbOrganization in project opencast by opencast.
the class GenericUrlSigningProviderTest method setUpClass.
@BeforeClass
public static void setUpClass() throws Exception {
/* Create mockup for organization a */
JaxbOrganization organizationA = EasyMock.createNiceMock(JaxbOrganization.class);
EasyMock.expect(organizationA.getId()).andReturn(ORGANIZATION_A_ID).anyTimes();
EasyMock.replay(organizationA);
SecurityService securityServiceA = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityServiceA.getOrganization()).andReturn(organizationA).anyTimes();
EasyMock.replay(securityServiceA);
signerA = new GenericUrlSigningProvider();
signerA.setSecurityService(securityServiceA);
/* Create mockup for organization b */
JaxbOrganization organizationB = EasyMock.createNiceMock(JaxbOrganization.class);
EasyMock.expect(organizationB.getId()).andReturn(ORGANIZATION_B_ID).anyTimes();
EasyMock.replay(organizationB);
SecurityService securityServiceB = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityServiceB.getOrganization()).andReturn(organizationB).anyTimes();
EasyMock.replay(securityServiceB);
signerB = new GenericUrlSigningProvider();
signerB.setSecurityService(securityServiceB);
properties = new Properties();
/* To indicate that specific tests are not supposed to test multi-tenant capabilities, we just set an alias */
signer = signerA;
}
use of org.opencastproject.security.api.JaxbOrganization in project opencast by opencast.
the class JobTest method setUp.
@Before
public void setUp() throws Exception {
final EntityManagerFactory emf = newTestEntityManagerFactory(ServiceRegistryJpaImpl.PERSISTENCE_UNIT);
serviceRegistry = new ServiceRegistryJpaImpl();
serviceRegistry.setEntityManagerFactory(emf);
serviceRegistry.activate(null);
Organization organization = new DefaultOrganization();
OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
EasyMock.replay(organizationDirectoryService);
serviceRegistry.setOrganizationDirectoryService(organizationDirectoryService);
JaxbOrganization jaxbOrganization = JaxbOrganization.fromOrganization(organization);
User anonymous = new JaxbUser("anonymous", "test", jaxbOrganization, new JaxbRole(jaxbOrganization.getAnonymousRole(), jaxbOrganization));
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andReturn(anonymous).anyTimes();
EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
EasyMock.replay(securityService);
serviceRegistry.setSecurityService(securityService);
// register the hosts
serviceRegistry.registerHost(LOCALHOST, "127.0.0.1", 1024, 1, 1.0f);
serviceRegistry.registerHost(REMOTEHOST, "127.0.0.1", 1024, 1, 1.0f);
// register some service instances
regType1Localhost = (ServiceRegistrationJpaImpl) serviceRegistry.registerService(JOB_TYPE_1, LOCALHOST, PATH);
regType1Remotehost = (ServiceRegistrationJpaImpl) serviceRegistry.registerService(JOB_TYPE_1, REMOTEHOST, PATH);
regType2Localhost = (ServiceRegistrationJpaImpl) serviceRegistry.registerService(JOB_TYPE_2, LOCALHOST, PATH);
regType2Remotehost = (ServiceRegistrationJpaImpl) serviceRegistry.registerService(JOB_TYPE_2, REMOTEHOST, PATH);
penv = persistenceEnvironment(emf);
}
use of org.opencastproject.security.api.JaxbOrganization in project opencast by opencast.
the class SeriesServiceSolrTest method setUp.
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
// Mock up a security service
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
JaxbOrganization org = new JaxbOrganization("mh-default-org");
User user = new JaxbUser("admin", "test", org, new JaxbRole(SecurityConstants.GLOBAL_ADMIN_ROLE, org));
EasyMock.expect(securityService.getOrganization()).andReturn(org).anyTimes();
EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
EasyMock.replay(securityService);
index = new SeriesServiceSolrIndex();
index.solrRoot = PathSupport.concat("target", Long.toString(System.currentTimeMillis()));
dcService = new DublinCoreCatalogService();
index.setDublinCoreService(dcService);
index.setSecurityService(securityService);
index.activate(null);
InputStream in = null;
try {
in = getClass().getResourceAsStream("/dublincore.xml");
testCatalog = dcService.load(in);
} finally {
IOUtils.closeQuietly(in);
}
}
use of org.opencastproject.security.api.JaxbOrganization in project opencast by opencast.
the class UserAndRoleDirectoryServiceImpl method mergeUsers.
/**
* Merges two representations of a user, as returned by two different user providers. The set or roles from the
* provided users will be merged into one set.
*
* @param user1
* the first user to merge
* @param user2
* the second user to merge
* @return a user with a merged set of roles
*/
protected User mergeUsers(User user1, User user2) {
HashSet<JaxbRole> mergedRoles = new HashSet<JaxbRole>();
for (Role role : user1.getRoles()) {
mergedRoles.add(JaxbRole.fromRole(role));
}
for (Role role : user2.getRoles()) {
mergedRoles.add(JaxbRole.fromRole(role));
}
String name = StringUtils.isNotBlank(user1.getName()) ? user1.getName() : user2.getName();
String email = StringUtils.isNotBlank(user1.getEmail()) ? user1.getEmail() : user2.getEmail();
String password = user1.getPassword() == null ? user2.getPassword() : user1.getPassword();
boolean manageable = user1.isManageable() || user2.isManageable() ? true : false;
JaxbOrganization organization = JaxbOrganization.fromOrganization(user1.getOrganization());
String provider = StringUtils.join(Collections.nonNullList(user1.getProvider(), user2.getProvider()), ",");
JaxbUser jaxbUser = new JaxbUser(user1.getUsername(), password, name, email, provider, organization, mergedRoles);
jaxbUser.setManageable(manageable);
return jaxbUser;
}
use of org.opencastproject.security.api.JaxbOrganization in project opencast by opencast.
the class CustomRoleProvider method findRoles.
/**
* @see org.opencastproject.security.api.RoleProvider#findRoles(String, Role.Target, int, int)
*/
@Override
public Iterator<Role> findRoles(String query, Role.Target target, int offset, int limit) {
if (query == null)
throw new IllegalArgumentException("Query must be set");
Organization organization = securityService.getOrganization();
// Match the custom regular expression first if this is an ACL role query
if ((target == Role.Target.ACL) && (rolematch != null)) {
String exactQuery = StringUtils.removeEnd(query, "%");
Matcher m = rolematch.matcher(exactQuery);
if (m.matches()) {
List<Role> roles = new LinkedList<Role>();
JaxbOrganization jaxbOrganization = JaxbOrganization.fromOrganization(organization);
roles.add(new JaxbRole(exactQuery, jaxbOrganization, "Custom Role", Role.Type.EXTERNAL));
return roles.iterator();
}
}
// Otherwise match on the custom roles specified in a list
return Stream.$(roles).filter(filterByName._2(query)).drop(offset).apply(limit > 0 ? StreamOp.<String>id().take(limit) : StreamOp.<String>id()).map(toRole._2(organization)).iterator();
}
Aggregations