Search in sources :

Example 91 with User

use of org.opencastproject.security.api.User in project opencast by opencast.

the class MessageSignatureDto method toMessageSignature.

/**
 * Returns the business object of this message signature
 *
 * @return the business object model of this message signature
 */
public MessageSignature toMessageSignature(UserDirectoryService userDirectoryService) {
    final Option<EmailAddress> reply;
    if (replyTo != null && replyToName != null) {
        reply = some(new EmailAddress(replyTo, replyToName));
    } else {
        reply = none();
    }
    User user = userDirectoryService.loadUser(creator);
    return new MessageSignature(id, name, user, new EmailAddress(sender, senderName), reply, signature, creationDate);
}
Also used : User(org.opencastproject.security.api.User) MessageSignature(org.opencastproject.messages.MessageSignature) EmailAddress(org.opencastproject.kernel.mail.EmailAddress)

Example 92 with User

use of org.opencastproject.security.api.User in project opencast by opencast.

the class MailServiceTest method testCRUDMessageSignature.

@Test
public void testCRUDMessageSignature() {
    User admin = new JaxbUser("george@test.com", null, "George", "george@test.com", "test", new DefaultOrganization(), new HashSet<JaxbRole>());
    User help = new JaxbUser("frank@test.com", null, "Frank", "frank@test.com", "test", new DefaultOrganization(), new HashSet<JaxbRole>());
    MessageSignature signatureAdmin = MessageSignature.messageSignature("Administrator", admin, EmailAddress.emailAddress("admin@test.com", "Dr. Admin"), "Sincerly");
    MessageSignature signatureHelp = MessageSignature.messageSignature("Helpdesk", help, EmailAddress.emailAddress("help@test.com", "Mr. Help"), "Sincerly");
    List<MessageSignature> signatures;
    // Create
    try {
        signatureAdmin = mailService.updateMessageSignature(signatureAdmin);
        signatureHelp = mailService.updateMessageSignature(signatureHelp);
    } catch (MailServiceException e) {
        fail("Not able to save a message signature entity: " + e.getMessage());
    }
    // Read
    try {
        signatures = mailService.getMessageSignatures();
        assertEquals(2, signatures.size());
        assertTrue(signatures.contains(signatureAdmin) && signatures.contains(signatureHelp));
    } catch (MailServiceException e) {
        fail("Not able to get the message signatures: " + e.getMessage());
    }
    // Update
    try {
        signatureHelp.setCreator(admin);
        signatureHelp = mailService.updateMessageSignature(signatureHelp);
        signatures = mailService.getMessageSignatures();
        assertEquals(2, signatures.size());
        assertTrue(signatures.contains(signatureHelp));
    } catch (MailServiceException e) {
        fail("Not able to update a message signature entity: " + e.getMessage());
    }
    // Delete
    try {
        mailService.deleteMessageSignature(signatureAdmin.getId());
        signatures = mailService.getMessageSignatures();
        assertEquals(1, signatures.size());
        assertTrue(signatures.contains(signatureHelp));
    } catch (MailServiceException e) {
        fail("Not able to delete the message signature " + signatureAdmin.getName() + ": " + e.getMessage());
    } catch (NotFoundException e) {
        fail("Not able to get the message signatures: " + e.getMessage());
    }
}
Also used : User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) JaxbRole(org.opencastproject.security.api.JaxbRole) NotFoundException(org.opencastproject.util.NotFoundException) JaxbUser(org.opencastproject.security.api.JaxbUser) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Test(org.junit.Test)

Example 93 with User

use of org.opencastproject.security.api.User in project opencast by opencast.

the class UserSettingsTest method toJsonInputSettingAndSignatureExpectedAllInJson.

@Test
public void toJsonInputSettingAndSignatureExpectedAllInJson() throws Exception {
    InputStream stream = SeriesEndpointTest.class.getResourceAsStream("/user_settings_test_example.json");
    InputStreamReader reader = new InputStreamReader(stream);
    JSONObject expected = (JSONObject) new JSONParser().parse(reader);
    User creator = EasyMock.createMock(User.class);
    EasyMock.expect(creator.getName()).andReturn("Users Name").anyTimes();
    EasyMock.expect(creator.getUsername()).andReturn("username12").anyTimes();
    EasyMock.expect(creator.getEmail()).andReturn("adam@fake.com").anyTimes();
    EasyMock.replay(creator);
    EmailAddress sender = new EmailAddress("adam@fake.com", "Other Name");
    Option<EmailAddress> replyTo = none();
    DateTime dateTime = new DateTime(1401465634101L);
    dateTime.toDateTime(DateTimeZone.UTC);
    // MessageSignature messageSignature = new MessageSignature(10L, "Adam McKenzie", creator, sender, replyTo,
    // "This is the signature", dateTime.toDate(), nil(Comment.class));
    Collection<MessageSignature> signatures = new LinkedList<MessageSignature>();
    // signatures.add(messageSignature);
    UserSetting userSetting = new UserSetting(98, "Test Key", "Test Value");
    UserSettings userSettings = new UserSettings();
    userSettings.setTotal(1);
    userSettings.addUserSetting(userSetting);
    assertThat(expected.toJSONString(), SameJSONAs.sameJSONAs(userSettings.toJson().toJson()));
}
Also used : User(org.opencastproject.security.api.User) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) EmailAddress(org.opencastproject.kernel.mail.EmailAddress) DateTime(org.joda.time.DateTime) LinkedList(java.util.LinkedList) JSONObject(org.json.simple.JSONObject) JSONParser(org.json.simple.parser.JSONParser) MessageSignature(org.opencastproject.messages.MessageSignature) SeriesEndpointTest(org.opencastproject.adminui.endpoint.SeriesEndpointTest) Test(org.junit.Test)

Example 94 with User

use of org.opencastproject.security.api.User in project opencast by opencast.

the class UserSettingsServiceTest method before.

@Before
public void before() {
    User user = EasyMock.createNiceMock(User.class);
    EasyMock.expect(user.getUsername()).andReturn(USER_NAME);
    EasyMock.replay(user);
    Organization organization = EasyMock.createNiceMock(Organization.class);
    EasyMock.expect(organization.getId()).andReturn(ORG).anyTimes();
    EasyMock.replay(organization);
    securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
    EasyMock.replay(securityService);
    userDirectoryService = EasyMock.createNiceMock(UserDirectoryService.class);
    EasyMock.expect(userDirectoryService.loadUser(USER_NAME)).andReturn(user).anyTimes();
    EasyMock.replay(userDirectoryService);
}
Also used : User(org.opencastproject.security.api.User) Organization(org.opencastproject.security.api.Organization) SecurityService(org.opencastproject.security.api.SecurityService) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) Before(org.junit.Before)

Example 95 with User

use of org.opencastproject.security.api.User in project opencast by opencast.

the class DownloadDistributionServiceImplTest method setUp.

@Before
public void setUp() throws Exception {
    final File mediaPackageRoot = new File(getClass().getResource("/mediapackage.xml").toURI()).getParentFile();
    mp = MediaPackageParser.getFromXml(IOUtils.toString(getClass().getResourceAsStream("/mediapackage.xml"), "UTF-8"));
    distributionRoot = new File(mediaPackageRoot, "static");
    service = new DownloadDistributionServiceImpl();
    StatusLine statusLine = EasyMock.createNiceMock(StatusLine.class);
    EasyMock.expect(statusLine.getStatusCode()).andReturn(HttpServletResponse.SC_OK).anyTimes();
    EasyMock.replay(statusLine);
    HttpResponse response = EasyMock.createNiceMock(HttpResponse.class);
    EasyMock.expect(response.getStatusLine()).andReturn(statusLine).anyTimes();
    EasyMock.replay(response);
    final TrustedHttpClient httpClient = EasyMock.createNiceMock(TrustedHttpClient.class);
    EasyMock.expect(httpClient.execute((HttpUriRequest) EasyMock.anyObject())).andReturn(response).anyTimes();
    EasyMock.expect(httpClient.run((HttpUriRequest) EasyMock.anyObject())).andAnswer(new IAnswer<Function<Function<HttpResponse, Object>, Either<Exception, Object>>>() {

        @Override
        public Function<Function<HttpResponse, Object>, Either<Exception, Object>> answer() throws Throwable {
            HttpUriRequest req = (HttpUriRequest) EasyMock.getCurrentArguments()[0];
            return StandAloneTrustedHttpClientImpl.run(httpClient, req);
        }
    }).anyTimes();
    EasyMock.replay(httpClient);
    defaultOrganization = new DefaultOrganization();
    User anonymous = new JaxbUser("anonymous", "test", defaultOrganization, new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, defaultOrganization));
    UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
    EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(anonymous).anyTimes();
    EasyMock.replay(userDirectoryService);
    service.setUserDirectoryService(userDirectoryService);
    Organization organization = new DefaultOrganization();
    OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
    EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
    EasyMock.replay(organizationDirectoryService);
    service.setOrganizationDirectoryService(organizationDirectoryService);
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(anonymous).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
    EasyMock.replay(securityService);
    service.setSecurityService(securityService);
    serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
    service.setServiceRegistry(serviceRegistry);
    service.setTrustedHttpClient(httpClient);
    final Workspace workspace = EasyMock.createNiceMock(Workspace.class);
    service.setWorkspace(workspace);
    EasyMock.expect(workspace.get((URI) EasyMock.anyObject())).andAnswer(new IAnswer<File>() {

        @Override
        public File answer() throws Throwable {
            final URI uri = (URI) EasyMock.getCurrentArguments()[0];
            final String[] pathElems = uri.getPath().split("/");
            final String file = pathElems[pathElems.length - 1];
            return new File(mediaPackageRoot, file);
        }
    }).anyTimes();
    EasyMock.replay(workspace);
    BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
    EasyMock.expect(bc.getProperty("org.opencastproject.download.directory")).andReturn(distributionRoot.toString()).anyTimes();
    EasyMock.expect(bc.getProperty("org.opencastproject.download.url")).andReturn(UrlSupport.DEFAULT_BASE_URL).anyTimes();
    ComponentContext cc = EasyMock.createNiceMock(ComponentContext.class);
    Dictionary<String, Object> p = new Hashtable<String, Object>();
    p.put(DistributionService.CONFIG_KEY_STORE_TYPE, "download");
    EasyMock.expect(cc.getProperties()).andReturn(p).anyTimes();
    EasyMock.expect(cc.getBundleContext()).andReturn(bc).anyTimes();
    EasyMock.replay(bc, cc);
    service.activate(cc);
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) JaxbUser(org.opencastproject.security.api.JaxbUser) URI(java.net.URI) Function(org.opencastproject.util.data.Function) SecurityService(org.opencastproject.security.api.SecurityService) Either(org.opencastproject.util.data.Either) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) TrustedHttpClient(org.opencastproject.security.api.TrustedHttpClient) ComponentContext(org.osgi.service.component.ComponentContext) Hashtable(java.util.Hashtable) HttpResponse(org.apache.http.HttpResponse) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) StatusLine(org.apache.http.StatusLine) IAnswer(org.easymock.IAnswer) JaxbRole(org.opencastproject.security.api.JaxbRole) File(java.io.File) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Workspace(org.opencastproject.workspace.api.Workspace) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Aggregations

User (org.opencastproject.security.api.User)156 Organization (org.opencastproject.security.api.Organization)61 JaxbUser (org.opencastproject.security.api.JaxbUser)60 JaxbRole (org.opencastproject.security.api.JaxbRole)49 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)44 SecurityService (org.opencastproject.security.api.SecurityService)43 NotFoundException (org.opencastproject.util.NotFoundException)32 Before (org.junit.Before)31 Test (org.junit.Test)27 ArrayList (java.util.ArrayList)26 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)24 JaxbOrganization (org.opencastproject.security.api.JaxbOrganization)23 AccessControlList (org.opencastproject.security.api.AccessControlList)21 Role (org.opencastproject.security.api.Role)21 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)21 HashSet (java.util.HashSet)20 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)18 JpaUser (org.opencastproject.security.impl.jpa.JpaUser)17 IOException (java.io.IOException)16 MediaPackage (org.opencastproject.mediapackage.MediaPackage)16