Search in sources :

Example 81 with BaseSecurity

use of org.olat.basesecurity.BaseSecurity in project OpenOLAT by OpenOLAT.

the class CatalogTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    id1 = JunitTestHelper.createAndPersistIdentityAsUser("rest-catalog-one");
    JunitTestHelper.createAndPersistIdentityAsUser("rest-catalog-two");
    BaseSecurity securityManager = BaseSecurityManager.getInstance();
    admin = securityManager.findIdentityByName("administrator");
    // create a catalog
    root1 = catalogManager.getRootCatalogEntries().get(0);
    entry1 = catalogManager.createCatalogEntry();
    entry1.setType(CatalogEntry.TYPE_NODE);
    entry1.setName("Entry-1");
    entry1.setDescription("Entry-description-1");
    entry1.setOwnerGroup(securityManager.createAndPersistSecurityGroup());
    catalogManager.addCatalogEntry(root1, entry1);
    DBFactory.getInstance().intermediateCommit();
    entry1 = catalogManager.loadCatalogEntry(entry1);
    securityManager.addIdentityToSecurityGroup(admin, entry1.getOwnerGroup());
    subEntry11 = catalogManager.createCatalogEntry();
    subEntry11.setType(CatalogEntry.TYPE_NODE);
    subEntry11.setName("Sub-entry-11");
    subEntry11.setDescription("Sub-entry-description-11");
    catalogManager.addCatalogEntry(entry1, subEntry11);
    subEntry12 = catalogManager.createCatalogEntry();
    subEntry12.setType(CatalogEntry.TYPE_NODE);
    subEntry12.setName("Sub-entry-12");
    subEntry12.setDescription("Sub-entry-description-12");
    catalogManager.addCatalogEntry(entry1, subEntry12);
    entry2 = catalogManager.createCatalogEntry();
    entry2.setType(CatalogEntry.TYPE_NODE);
    entry2.setName("Entry-2");
    entry2.setDescription("Entry-description-2");
    catalogManager.addCatalogEntry(root1, entry2);
    entryToMove1 = catalogManager.createCatalogEntry();
    entryToMove1.setType(CatalogEntry.TYPE_NODE);
    entryToMove1.setName("Entry-1-to-move");
    entryToMove1.setDescription("Entry-description-1-to-move");
    catalogManager.addCatalogEntry(root1, entryToMove1);
    entryToMove2 = catalogManager.createCatalogEntry();
    entryToMove2.setType(CatalogEntry.TYPE_NODE);
    entryToMove2.setName("Entry-2-to-move");
    entryToMove2.setDescription("Entry-description-2-to-move");
    catalogManager.addCatalogEntry(root1, entryToMove2);
    subEntry13move = catalogManager.createCatalogEntry();
    subEntry13move.setType(CatalogEntry.TYPE_NODE);
    subEntry13move.setName("Sub-entry-13-move target");
    subEntry13move.setDescription("Sub-entry-description-13-move target");
    catalogManager.addCatalogEntry(root1, subEntry13move);
    DBFactory.getInstance().intermediateCommit();
}
Also used : BaseSecurity(org.olat.basesecurity.BaseSecurity) Before(org.junit.Before)

Example 82 with BaseSecurity

use of org.olat.basesecurity.BaseSecurity in project OpenOLAT by OpenOLAT.

the class NotificationsWebService method subscribe.

@PUT
@Path("subscribers")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response subscribe(PublisherVO publisherVO, @Context HttpServletRequest request) {
    if (!isAdmin(request)) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    NotificationsManager notificationsMgr = NotificationsManager.getInstance();
    BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
    SubscriptionContext subscriptionContext = new SubscriptionContext(publisherVO.getResName(), publisherVO.getResId(), publisherVO.getSubidentifier());
    PublisherData publisherData = new PublisherData(publisherVO.getType(), publisherVO.getData(), publisherVO.getBusinessPath());
    List<UserVO> userVoes = publisherVO.getUsers();
    List<Long> identityKeys = new ArrayList<>();
    for (UserVO userVo : userVoes) {
        identityKeys.add(userVo.getKey());
    }
    List<Identity> identities = securityManager.loadIdentityByKeys(identityKeys);
    notificationsMgr.subscribe(identities, subscriptionContext, publisherData);
    return Response.ok().build();
}
Also used : UserVO(org.olat.user.restapi.UserVO) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) ArrayList(java.util.ArrayList) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Identity(org.olat.core.id.Identity) PublisherData(org.olat.core.commons.services.notifications.PublisherData) BaseSecurity(org.olat.basesecurity.BaseSecurity) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 83 with BaseSecurity

use of org.olat.basesecurity.BaseSecurity in project OpenOLAT by OpenOLAT.

the class DENManager method removeDateInUserCalendar.

/**
 * Removes this event in all calendars of enrolled users
 * @param oldEvent
 */
private void removeDateInUserCalendar(KalendarEvent oldEvent) {
    String[] participants = oldEvent.getParticipants();
    // no users to update, cancel
    if (participants == null)
        return;
    BaseSecurity manager = BaseSecurityManager.getInstance();
    CalendarManager calManager = CoreSpringFactory.getImpl(CalendarManager.class);
    for (String participant : participants) {
        Identity identity = manager.findIdentityByName(participant);
        if (identity != null) {
            Kalendar userCal = calManager.getPersonalCalendar(identity).getKalendar();
            List<KalendarEvent> userEvents = new ArrayList<>();
            userEvents.addAll(userCal.getEvents());
            for (KalendarEvent userEvent : userEvents) {
                String sourceNodeId = userEvent.getSourceNodeId();
                if (sourceNodeId != null && sourceNodeId.equals(oldEvent.getSourceNodeId())) {
                    calManager.removeEventFrom(userCal, userEvent);
                }
            }
        }
    }
}
Also used : CalendarManager(org.olat.commons.calendar.CalendarManager) Kalendar(org.olat.commons.calendar.model.Kalendar) ArrayList(java.util.ArrayList) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Identity(org.olat.core.id.Identity) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 84 with BaseSecurity

use of org.olat.basesecurity.BaseSecurity in project OpenOLAT by OpenOLAT.

the class DENManager method getSelectedEventParticipants.

/**
 * Little helper method, that gives you all participants of the selected events in the list
 * @param dataList
 * @param selection BitSet
 * @return list of Identities
 */
protected List<Identity> getSelectedEventParticipants(List<KalendarEvent> dataList, BitSet selection) {
    List<Identity> identities = new ArrayList<Identity>();
    BaseSecurity manager = BaseSecurityManager.getInstance();
    for (int i = 0; i < dataList.size(); i++) {
        if (selection.get(i)) {
            String[] parts = dataList.get(i).getParticipants();
            if (parts != null) {
                for (String participant : parts) {
                    Identity identity = manager.findIdentityByName(participant);
                    if (identity != null) {
                        identities.add(identity);
                    }
                }
            }
        }
    }
    return identities;
}
Also used : ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 85 with BaseSecurity

use of org.olat.basesecurity.BaseSecurity in project OpenOLAT by OpenOLAT.

the class DENManager method addDateInUserCalendar.

/**
 * Add this event in the calendar of an enrolled user
 * @param newEvent
 */
private void addDateInUserCalendar(KalendarEvent newEvent) {
    String[] participants = newEvent.getParticipants();
    // no users to update, cancel
    if (participants == null)
        return;
    BaseSecurity manager = BaseSecurityManager.getInstance();
    CalendarManager calManager = CoreSpringFactory.getImpl(CalendarManager.class);
    for (String participant : participants) {
        Identity identity = manager.findIdentityByName(participant);
        if (identity != null) {
            Kalendar userCal = calManager.getPersonalCalendar(identity).getKalendar();
            List<KalendarEvent> userEvents = new ArrayList<>();
            userEvents.addAll(userCal.getEvents());
            String eventId = CodeHelper.getGlobalForeverUniqueID();
            KalendarEvent userNewEvent = new KalendarEvent(eventId, null, newEvent.getSubject(), newEvent.getBegin(), newEvent.getEnd());
            userNewEvent.setLocation(newEvent.getLocation());
            userNewEvent.setSourceNodeId(newEvent.getSourceNodeId());
            userNewEvent.setClassification(KalendarEvent.CLASS_PRIVATE);
            List<KalendarEventLink> kalendarEventLinks = userNewEvent.getKalendarEventLinks();
            kalendarEventLinks.clear();
            kalendarEventLinks.addAll(newEvent.getKalendarEventLinks());
            calManager.addEventTo(userCal, userNewEvent);
        }
    }
}
Also used : CalendarManager(org.olat.commons.calendar.CalendarManager) Kalendar(org.olat.commons.calendar.model.Kalendar) ArrayList(java.util.ArrayList) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) KalendarEventLink(org.olat.commons.calendar.model.KalendarEventLink) Identity(org.olat.core.id.Identity) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Aggregations

BaseSecurity (org.olat.basesecurity.BaseSecurity)116 Identity (org.olat.core.id.Identity)88 Path (javax.ws.rs.Path)48 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)28 PUT (javax.ws.rs.PUT)24 Produces (javax.ws.rs.Produces)22 SecurityGroup (org.olat.basesecurity.SecurityGroup)20 RepositoryEntry (org.olat.repository.RepositoryEntry)20 DELETE (javax.ws.rs.DELETE)14 Authentication (org.olat.basesecurity.Authentication)14 MailPackage (org.olat.core.util.mail.MailPackage)14 RepositoryManager (org.olat.repository.RepositoryManager)14 Consumes (javax.ws.rs.Consumes)12 WebApplicationException (javax.ws.rs.WebApplicationException)12 CertificatesManager (org.olat.course.certificate.CertificatesManager)10 OLATResource (org.olat.resource.OLATResource)10 OLATResourceManager (org.olat.resource.OLATResourceManager)10 ArrayList (java.util.ArrayList)8 GET (javax.ws.rs.GET)8 IdentitiesAddEvent (org.olat.admin.securitygroup.gui.IdentitiesAddEvent)8