Search in sources :

Example 1 with IBackingRepositoryLifecycleManager

use of org.pentaho.platform.api.repository2.unified.IBackingRepositoryLifecycleManager in project pentaho-engineering-samples by pentaho.

the class PentahoSamlAuthenticationSuccessHandler method createUserHomeFolder.

private void createUserHomeFolder(final String username) {
    final ITenant tenantName = JcrTenantUtils.getTenant(username, true);
    final ISecurityHelper securityHelper = PentahoSystem.get(ISecurityHelper.class) != null ? PentahoSystem.get(ISecurityHelper.class) : SecurityHelper.getInstance();
    final IBackingRepositoryLifecycleManager lifecycleManager = PentahoSystem.get(IBackingRepositoryLifecycleManager.class);
    if (tenantName == null || securityHelper == null || lifecycleManager == null) {
        logger.error("null " + (tenantName == null ? "ITenant" : securityHelper == null ? "ISecurityHelper" : "IBackingRepositoryLifecycleManager"));
        return;
    }
    try {
        securityHelper.runAsSystem(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                // Execute new tenant with the tenant id from the logged in user
                lifecycleManager.newTenant(tenantName);
                return null;
            }
        });
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
    }
    try {
        securityHelper.runAsSystem(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                // Execute new tenant with the tenant id from the logged in user
                lifecycleManager.newUser(tenantName, username);
                return null;
            }
        });
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
    }
    try {
        // The newTenant() call should be executed as the system (or more correctly the tenantAdmin)
        securityHelper.runAsSystem(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                lifecycleManager.newTenant();
                return null;
            }
        });
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
    }
    try {
        // run as user to populate SecurityContextHolder and PentahoSessionHolder since Spring Security events are
        // fired before SecurityContextHolder is set
        securityHelper.runAsUser(username, new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                lifecycleManager.newUser();
                return null;
            }
        });
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
    }
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) ISecurityHelper(org.pentaho.platform.api.engine.ISecurityHelper) ServletException(javax.servlet.ServletException) ProxyException(org.pentaho.platform.proxy.impl.ProxyException) IOException(java.io.IOException) IBackingRepositoryLifecycleManager(org.pentaho.platform.api.repository2.unified.IBackingRepositoryLifecycleManager)

Example 2 with IBackingRepositoryLifecycleManager

use of org.pentaho.platform.api.repository2.unified.IBackingRepositoryLifecycleManager in project pentaho-platform by pentaho.

the class BackingRepositoryLifecycleManagerAuthenticationSuccessListener method onApplicationEvent.

// ~ Methods
// =========================================================================================================
public void onApplicationEvent(final ApplicationEvent event) {
    if (event instanceof AuthenticationSuccessEvent || event instanceof InteractiveAuthenticationSuccessEvent) {
        // $NON-NLS-1$
        logger.debug("received AbstractAuthenticationEvent");
        // Get the lifecycle manager for this event
        final IBackingRepositoryLifecycleManager lifecycleManager = getLifecycleManager();
        // Execute new tenant with the tenant id from the logged in user
        final AbstractAuthenticationEvent aEvent = (AbstractAuthenticationEvent) event;
        final String principalName = aEvent.getAuthentication().getName();
        try {
            getSecurityHelper().runAsSystem(new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    // Execute new tenant with the tenant id from the logged in user
                    lifecycleManager.newTenant(JcrTenantUtils.getTenant(principalName, true));
                    return null;
                }
            });
        } catch (Exception e) {
            logger.error(e.getLocalizedMessage(), e);
        }
        try {
            getSecurityHelper().runAsSystem(new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    // Execute new tenant with the tenant id from the logged in user
                    lifecycleManager.newUser(JcrTenantUtils.getTenant(principalName, true), JcrTenantUtils.getPrincipalName(principalName, true));
                    return null;
                }
            });
        } catch (Exception e) {
            logger.error(e.getLocalizedMessage(), e);
        }
        try {
            // The newTenant() call should be executed as the system (or more correctly the tenantAdmin)
            getSecurityHelper().runAsSystem(new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    lifecycleManager.newTenant();
                    return null;
                }
            });
        } catch (Exception e) {
            logger.error(e.getLocalizedMessage(), e);
        }
        try {
            // run as user to populate SecurityContextHolder and PentahoSessionHolder since Spring Security events are
            // fired
            // before SecurityContextHolder is set
            getSecurityHelper().runAsUser(principalName, new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    lifecycleManager.newUser();
                    return null;
                }
            });
        } catch (Exception e) {
            logger.error(e.getLocalizedMessage(), e);
        }
        logger.info("The user \"" + principalName + "\"" + " connected to repository");
    }
}
Also used : InteractiveAuthenticationSuccessEvent(org.springframework.security.authentication.event.InteractiveAuthenticationSuccessEvent) InteractiveAuthenticationSuccessEvent(org.springframework.security.authentication.event.InteractiveAuthenticationSuccessEvent) AuthenticationSuccessEvent(org.springframework.security.authentication.event.AuthenticationSuccessEvent) AbstractAuthenticationEvent(org.springframework.security.authentication.event.AbstractAuthenticationEvent) IBackingRepositoryLifecycleManager(org.pentaho.platform.api.repository2.unified.IBackingRepositoryLifecycleManager)

Aggregations

IBackingRepositoryLifecycleManager (org.pentaho.platform.api.repository2.unified.IBackingRepositoryLifecycleManager)2 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 ISecurityHelper (org.pentaho.platform.api.engine.ISecurityHelper)1 ITenant (org.pentaho.platform.api.mt.ITenant)1 ProxyException (org.pentaho.platform.proxy.impl.ProxyException)1 AbstractAuthenticationEvent (org.springframework.security.authentication.event.AbstractAuthenticationEvent)1 AuthenticationSuccessEvent (org.springframework.security.authentication.event.AuthenticationSuccessEvent)1 InteractiveAuthenticationSuccessEvent (org.springframework.security.authentication.event.InteractiveAuthenticationSuccessEvent)1