use of org.opencastproject.security.api.JaxbUser in project opencast by opencast.
the class OrganizationPersistenceTest method setUp.
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
securityService = EasyMock.createNiceMock(SecurityService.class);
User user = new JaxbUser("admin", "test", new DefaultOrganization(), new JaxbRole(SecurityConstants.GLOBAL_ADMIN_ROLE, new DefaultOrganization()));
EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
EasyMock.replay(securityService);
organizationDatabase = new OrganizationDatabaseImpl();
organizationDatabase.setEntityManagerFactory(newTestEntityManagerFactory(PERSISTENCE_UNIT));
organizationDatabase.setSecurityService(securityService);
organizationDatabase.activate(null);
}
use of org.opencastproject.security.api.JaxbUser in project opencast by opencast.
the class SecurityServiceSpringImpl method getUser.
/**
* {@inheritDoc}
*
* @see org.opencastproject.security.api.SecurityService#getUser()
*/
@Override
public User getUser() throws IllegalStateException {
Organization org = getOrganization();
if (org == null)
throw new IllegalStateException("No organization is set in security context");
User delegatedUser = delegatedUserHolder.get();
if (delegatedUser != null) {
return delegatedUser;
}
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
JaxbOrganization jaxbOrganization = JaxbOrganization.fromOrganization(org);
if (auth != null) {
Object principal = auth.getPrincipal();
if ((principal != null) && (principal instanceof UserDetails)) {
UserDetails userDetails = (UserDetails) principal;
User user = null;
// If user exists, fetch it from the userDirectory
if (userDirectory != null) {
user = userDirectory.loadUser(userDetails.getUsername());
if (user == null) {
logger.debug("Authenticated user '{}' could not be found in any of the current UserProviders. Continuing anyway...", userDetails.getUsername());
}
} else {
logger.debug("No UserDirectory was found when trying to search for user '{}'", userDetails.getUsername());
}
// Add the roles (authorities) in the security context
Set<JaxbRole> roles = new HashSet<JaxbRole>();
Collection<? extends GrantedAuthority> authorities = auth.getAuthorities();
if (authorities != null) {
for (GrantedAuthority ga : authorities) {
roles.add(new JaxbRole(ga.getAuthority(), jaxbOrganization));
}
}
if (user == null) {
// No user was found. Create one to hold the auth information from the security context
user = new JaxbUser(userDetails.getUsername(), null, jaxbOrganization, roles);
} else {
// Combine the existing user with the roles in the security context
user = JaxbUser.fromUser(user, roles);
}
// Save the user to retrieve it quicker the next time(s) this method is called (by this thread)
delegatedUserHolder.set(user);
return user;
}
}
// Return the anonymous user by default
return SecurityUtil.createAnonymousUser(jaxbOrganization);
}
use of org.opencastproject.security.api.JaxbUser in project opencast by opencast.
the class XACMLSecurityTest method setUp.
@Before
public void setUp() throws Exception {
authzService = new XACMLAuthorizationService();
// Mock security service
securityService = EasyMock.createMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andAnswer(() -> new JaxbUser(currentUser, "test", organization, currentRoles)).anyTimes();
// Mock workspace
Workspace workspace = EasyMock.createMock(Workspace.class);
final Capture<InputStream> in = EasyMock.newCapture();
final Capture<URI> uri = EasyMock.newCapture();
EasyMock.expect(workspace.put(EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyString(), EasyMock.capture(in))).andAnswer(() -> {
final File file = testFolder.newFile();
FileOutputStream out = new FileOutputStream(file);
IOUtils.copyLarge(in.getValue(), out);
IOUtils.closeQuietly(out);
IOUtils.closeQuietly(in.getValue());
return file.toURI();
}).anyTimes();
EasyMock.expect(workspace.get(EasyMock.capture(uri))).andAnswer(() -> new File(uri.getValue())).anyTimes();
EasyMock.expect(workspace.read(EasyMock.capture(uri))).andAnswer(() -> new FileInputStream(uri.getValue().getPath())).anyTimes();
workspace.delete(EasyMock.anyObject(URI.class));
EasyMock.expectLastCall().anyTimes();
EasyMock.replay(securityService, workspace);
authzService.setWorkspace(workspace);
authzService.setSecurityService(securityService);
}
use of org.opencastproject.security.api.JaxbUser in project opencast by opencast.
the class TestSearchIndex method createSecurityService.
public static final SecurityService createSecurityService(DefaultOrganization organization) {
JaxbUser creator = new JaxbUser("creator", "password", "Creator", null, "test", organization, new HashSet<JaxbRole>());
SecurityService securityService = createNiceMock(SecurityService.class);
expect(securityService.getOrganization()).andReturn(organization).anyTimes();
expect(securityService.getUser()).andReturn(creator).anyTimes();
replay(securityService);
return securityService;
}
use of org.opencastproject.security.api.JaxbUser in project opencast by opencast.
the class SchedulerMigrationServiceTest method setUp.
@Before
public void setUp() throws Exception {
OrganizationDirectoryService orgDirService = createNiceMock(OrganizationDirectoryService.class);
expect(orgDirService.getOrganization(anyString())).andReturn(new DefaultOrganization()).anyTimes();
replay(orgDirService);
SecurityService securityService = createNiceMock(SecurityService.class);
expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
expect(securityService.getUser()).andReturn(new JaxbUser()).anyTimes();
replay(securityService);
SchedulerTransaction schedulerTransaction = createNiceMock(SchedulerTransaction.class);
replay(schedulerTransaction);
SchedulerService schedulerService = createNiceMock(SchedulerService.class);
expect(schedulerService.createTransaction(anyString())).andReturn(schedulerTransaction).anyTimes();
expect(schedulerService.search(anyObject(Opt.class), anyObject(Opt.class), anyObject(Opt.class), anyObject(Opt.class), anyObject(Opt.class))).andReturn(new ArrayList<>());
replay(schedulerService);
Workspace workspace = createNiceMock(Workspace.class);
expect(workspace.put(anyString(), anyString(), anyString(), anyObject(InputStream.class))).andReturn(new URI("test")).anyTimes();
replay(workspace);
AuthorizationService authorizationService = createNiceMock(AuthorizationService.class);
replay(authorizationService);
schedulerMigrationService.setAuthorizationService(authorizationService);
schedulerMigrationService.setOrganizationDirectoryService(orgDirService);
schedulerMigrationService.setSchedulerService(schedulerService);
schedulerMigrationService.setSecurityService(securityService);
schedulerMigrationService.setWorkspace(workspace);
}
Aggregations