Search in sources :

Example 16 with Activate

use of org.apache.felix.scr.annotations.Activate in project sling by apache.

the class JobManagerTestComponent method activate.

@Activate
public void activate(Map<String, Object> props) {
    for (int i = 0; i < 10; i++) {
        Job job = jobManager.newJobBuilder(Types.jobQueue(TOPIC), Types.jobType(AsyncJobConsumer.JOB_TYPE)).addProperties(Collections.singletonMap("jobtest", (Object) "jobtest")).add();
        assertNotNull(job);
        LOGGER.info("Started Job {} ", job.getId());
    }
    // then start 10 sync jobs.
    for (int i = 0; i < 10; i++) {
        Job job = jobManager.newJobBuilder(Types.jobQueue(TOPIC), Types.jobType(FullySyncJob.JOB_TYPE)).addProperties(Collections.singletonMap("jobtest", (Object) "jobtest")).add();
        assertNotNull(job);
        LOGGER.info("Started Job {} ", job.getId());
    }
}
Also used : Job(org.apache.sling.jobs.Job) Activate(org.apache.felix.scr.annotations.Activate)

Example 17 with Activate

use of org.apache.felix.scr.annotations.Activate in project sling by apache.

the class Init method activate.

@Activate
public void activate() throws Exception {
    try {
        final String defaultAgentUserName = "distribution-agent-user";
        final String serviceUserName = "testDistributionUser";
        final String distributorUserName = "testDistributorUser";
        Session session = slingRepository.login(new SimpleCredentials("admin", "admin".toCharArray()));
        JackrabbitSession jackrabittSession = (JackrabbitSession) session;
        UserManager userManager = jackrabittSession.getUserManager();
        User serviceUser = createOrGetServiceUser(userManager, serviceUserName);
        if (serviceUser != null) {
            AccessControlUtils.addAccessControlEntry(session, "/var/sling/distribution/packages", serviceUser.getPrincipal(), new String[] { Privilege.JCR_ALL }, true);
            AccessControlUtils.addAccessControlEntry(session, "/content", serviceUser.getPrincipal(), new String[] { Privilege.JCR_ALL }, true);
            AccessControlUtils.addAccessControlEntry(session, null, serviceUser.getPrincipal(), new String[] { Privilege.JCR_ALL }, true);
        }
        Authorizable distributorUser = createOrGetRegularUser(userManager, distributorUserName);
        JcrUtils.getOrCreateByPath("/content", "sling:Folder", session);
        if (distributorUser != null) {
            AccessControlUtils.addAccessControlEntry(session, "/var/sling/distribution/packages", distributorUser.getPrincipal(), new String[] { Privilege.JCR_ALL }, true);
            AccessControlUtils.addAccessControlEntry(session, "/content", distributorUser.getPrincipal(), new String[] { Privilege.JCR_ALL }, true);
            AccessControlUtils.addAccessControlEntry(session, "/libs/sling/distribution", distributorUser.getPrincipal(), new String[] { Privilege.JCR_ALL }, true);
            AccessControlUtils.addAccessControlEntry(session, "/etc/distribution", distributorUser.getPrincipal(), new String[] { Privilege.JCR_ALL }, true);
            AccessControlUtils.addAccessControlEntry(session, null, distributorUser.getPrincipal(), new String[] { Privilege.JCR_ALL }, true);
        }
        User defaultAgentUser = createOrGetServiceUser(userManager, defaultAgentUserName);
        if (defaultAgentUser != null) {
            AccessControlUtils.addAccessControlEntry(session, "/var/sling/distribution/packages", defaultAgentUser.getPrincipal(), new String[] { Privilege.JCR_ALL }, true);
            ((User) distributorUser).getImpersonation().grantImpersonation(defaultAgentUser.getPrincipal());
            serviceUser.getImpersonation().grantImpersonation(defaultAgentUser.getPrincipal());
        }
        session.save();
        session.logout();
    } catch (Throwable t) {
        log.error("cannot create user", t);
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) User(org.apache.jackrabbit.api.security.user.User) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Activate(org.apache.felix.scr.annotations.Activate)

Example 18 with Activate

use of org.apache.felix.scr.annotations.Activate in project sling by apache.

the class TenantProviderImpl method activate.

@Activate
protected void activate(final BundleContext bundleContext, final Map<String, Object> properties) {
    this.tenantRootPath = PropertiesUtil.toString(properties.get(TENANT_ROOT), RESOURCE_TENANT_ROOT);
    this.adapterFactory = new TenantAdapterFactory(bundleContext, this, PropertiesUtil.toStringArray(properties.get(TENANT_PATH_MATCHER), DEFAULT_PATH_MATCHER));
    this.plugin = new WebConsolePlugin(bundleContext, this);
}
Also used : WebConsolePlugin(org.apache.sling.tenant.internal.console.WebConsolePlugin) Activate(org.apache.felix.scr.annotations.Activate)

Example 19 with Activate

use of org.apache.felix.scr.annotations.Activate in project sling by apache.

the class StartupFilterImpl method activate.

@Activate
protected void activate(final BundleContext ctx, final Map<String, Object> properties) throws InterruptedException {
    bundleContext = ctx;
    providersTracker = new ServiceTracker(bundleContext, StartupInfoProvider.class, null);
    providersTracker.open();
    Object prop = properties.get(DEFAULT_MESSAGE_PROP);
    defaultMessage = prop == null ? DEFAULT_MESSAGE : prop.toString();
    prop = properties.get(ACTIVE_BY_DEFAULT_PROP);
    defaultFilterActive = (prop instanceof Boolean ? (Boolean) prop : false);
    prop = bundleContext.getProperty(FRAMEWORK_PROP_MANAGER_ROOT);
    managerRoot = prop == null ? DEFAULT_MANAGER_ROOT : prop.toString();
    if (defaultFilterActive) {
        enable();
    }
    log.info("Activated, enabled={}, managerRoot={}", isEnabled(), managerRoot);
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker) StartupInfoProvider(org.apache.sling.startupfilter.StartupInfoProvider) Activate(org.apache.felix.scr.annotations.Activate)

Example 20 with Activate

use of org.apache.felix.scr.annotations.Activate in project sling by apache.

the class SuperimposingManagerImpl method activate.

// ---------- SCR Integration
@Activate
protected synchronized void activate(final ComponentContext ctx) throws LoginException, RepositoryException {
    // check enabled state
    @SuppressWarnings("unchecked") final Dictionary<String, Object> props = ctx.getProperties();
    this.enabled = PropertiesUtil.toBoolean(props.get(ENABLED_PROPERTY), ENABLED_DEFAULT);
    log.debug("Config: " + "Enabled={} ", enabled);
    if (!isEnabled()) {
        return;
    }
    // get "find all" queries
    this.findAllQueries = PropertiesUtil.toStringArray(props.get(FINDALLQUERIES_PROPERTY), new String[] { FINDALLQUERIES_DEFAULT });
    this.obervationPaths = PropertiesUtil.toStringArray(props.get(OBSERVATION_PATHS_PROPERTY), new String[] { OBSERVATION_PATHS_DEFAULT });
    if (null == resolver) {
        bundleContext = ctx.getBundleContext();
        resolver = resolverFactory.getAdministrativeResourceResolver(null);
        // Watch for events on the root to register/deregister superimposings at runtime
        // For each observed path create an event listener object which redirects the event to the main class
        final Session session = resolver.adaptTo(Session.class);
        if (session != null) {
            this.observationEventListeners = new EventListener[this.obervationPaths.length];
            for (int i = 0; i < this.obervationPaths.length; i++) {
                this.observationEventListeners[i] = new EventListener() {

                    public void onEvent(EventIterator events) {
                        SuperimposingManagerImpl.this.onEvent(events);
                    }
                };
                session.getWorkspace().getObservationManager().addEventListener(this.observationEventListeners[i], Event.NODE_ADDED | Event.NODE_REMOVED | Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED, // absolute path
                this.obervationPaths[i], // isDeep
                true, // uuids
                null, // node types
                null, // noLocal
                true);
            }
        }
        // register all superimposing definitions that already exist
        initialization = Executors.newSingleThreadExecutor().submit(new Runnable() {

            public void run() {
                try {
                    registerAllSuperimposings();
                } catch (Throwable ex) {
                    log.warn("Error registering existing superimposing resources on service startup.", ex);
                }
            }
        });
    }
}
Also used : EventListener(javax.jcr.observation.EventListener) EventIterator(javax.jcr.observation.EventIterator) Session(javax.jcr.Session) Activate(org.apache.felix.scr.annotations.Activate)

Aggregations

Activate (org.apache.felix.scr.annotations.Activate)153 ConfigurationException (org.osgi.service.cm.ConfigurationException)31 ServiceTracker (org.osgi.util.tracker.ServiceTracker)20 BundleContext (org.osgi.framework.BundleContext)19 File (java.io.File)15 OsgiWhiteboard (org.apache.jackrabbit.oak.osgi.OsgiWhiteboard)12 URL (java.net.URL)11 Hashtable (java.util.Hashtable)11 ServiceReference (org.osgi.framework.ServiceReference)11 ServiceTrackerCustomizer (org.osgi.util.tracker.ServiceTrackerCustomizer)9 HashSet (java.util.HashSet)8 IOException (java.io.IOException)7 HashMap (java.util.HashMap)7 Map (java.util.Map)6 Session (javax.jcr.Session)5 StandardMBean (javax.management.StandardMBean)5 Whiteboard (org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard)5 Filter (org.osgi.framework.Filter)5 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4