Search in sources :

Example 86 with StandaloneSession

use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.

the class AggregateObjectFactoryTest method testCombined.

@Test
public void testCombined() throws Exception {
    StandaloneSession session = new StandaloneSession();
    StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory();
    ConfigurableApplicationContext context = new FileSystemXmlApplicationContext("src/test/resources/solution/system/pentahoObjects.spring.xml");
    factory.init(null, context);
    StandaloneSpringPentahoObjectFactory factory2 = new StandaloneSpringPentahoObjectFactory();
    factory2.init("src/test/resources/solution/system/pentahoObjects.spring.xml", null);
    StandaloneObjectFactory factory3 = new StandaloneObjectFactory();
    factory3.init(null, null);
    factory3.defineObject("MimeTypeListener", MimeTypeListener.class.getName(), IPentahoDefinableObjectFactory.Scope.GLOBAL);
    AggregateObjectFactory aggFactory = (AggregateObjectFactory) PentahoSystem.getObjectFactory();
    aggFactory.registerObjectFactory(factory3);
    List<MimeTypeListener> mimes = aggFactory.getAll(MimeTypeListener.class, session);
    assertEquals(6, mimes.size());
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) StandaloneObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory) IMimeTypeListener(org.pentaho.platform.api.engine.IMimeTypeListener) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory) AggregateObjectFactory(org.pentaho.platform.engine.core.system.objfac.AggregateObjectFactory) Test(org.junit.Test)

Example 87 with StandaloneSession

use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.

the class AggregateObjectFactoryTest method testRegistration.

/**
 * Two Spring PentahoObjectFactories with the same underlying applicationContext should not be registered twice. This
 * case tests that the AggregateObjectFactory's set implementation is working properly.
 *
 * @throws Exception
 */
@Test
public void testRegistration() throws Exception {
    StandaloneSession session = new StandaloneSession();
    StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory();
    ConfigurableApplicationContext context = new FileSystemXmlApplicationContext("src/test/resources/solution/system/pentahoObjects.spring.xml");
    factory.init(null, context);
    StandaloneSpringPentahoObjectFactory factory2 = new StandaloneSpringPentahoObjectFactory();
    factory2.init(null, context);
    AggregateObjectFactory aggFactory = (AggregateObjectFactory) PentahoSystem.getObjectFactory();
    aggFactory.registerObjectFactory(factory);
    aggFactory.registerObjectFactory(factory2);
    List<MimeTypeListener> mimes = aggFactory.getAll(MimeTypeListener.class, session);
    assertEquals(5, mimes.size());
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IMimeTypeListener(org.pentaho.platform.api.engine.IMimeTypeListener) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory) AggregateObjectFactory(org.pentaho.platform.engine.core.system.objfac.AggregateObjectFactory) Test(org.junit.Test)

Example 88 with StandaloneSession

use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.

the class AggregateObjectFactoryTest method testRegisteredButNotPublishingAnythingApplicationContext.

/**
 * Two Spring PentahoObjectFactories with the same underlying applicationContext should not be registered twice. This
 * case tests that the AggregateObjectFactory's set implementation is working properly.
 *
 * @throws Exception
 */
@Test
public void testRegisteredButNotPublishingAnythingApplicationContext() throws Exception {
    PublishedBeanRegistry.reset();
    StandaloneSession session = new StandaloneSession();
    StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory();
    ConfigurableApplicationContext context = new FileSystemXmlApplicationContext("src/test/resources/solution/system/registeredButNotPublishing.spring.xml");
    // this was causing an exception.
    factory.init(null, context);
    AggregateObjectFactory aggFactory = (AggregateObjectFactory) PentahoSystem.getObjectFactory();
    aggFactory.registerObjectFactory(factory);
    assertEquals(0, PublishedBeanRegistry.getRegisteredFactories().size());
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory) AggregateObjectFactory(org.pentaho.platform.engine.core.system.objfac.AggregateObjectFactory) Test(org.junit.Test)

Example 89 with StandaloneSession

use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.

the class DefaultLdapUserRoleListServiceTest method login.

/**
 * Logs in with given username.
 *
 * @param username
 *          username of user
 * @param tenant
 *          tenant to which this user belongs
 * @tenantAdmin true to add the tenant admin authority to the user's roles
 */
protected void login(final String username, final ITenant tenant) {
    StandaloneSession pentahoSession = new StandaloneSession(username);
    pentahoSession.setAuthenticated(username);
    pentahoSession.setAttribute(IPentahoSession.TENANT_ID_KEY, tenant.getId());
    final String password = "password";
    List<GrantedAuthority> authList = new ArrayList<GrantedAuthority>();
    authList.add(new SimpleGrantedAuthority("TenantAdmin"));
    authList.add(new SimpleGrantedAuthority("Authenticated"));
    UserDetails userDetails = new User(username, password, true, true, true, true, authList);
    Authentication auth = new UsernamePasswordAuthenticationToken(userDetails, password, authList);
    PentahoSessionHolder.setSession(pentahoSession);
    // this line necessary for Spring Security's MethodSecurityInterceptor
    SecurityContextHolder.getContext().setAuthentication(auth);
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) UserDetails(org.springframework.security.core.userdetails.UserDetails) User(org.springframework.security.core.userdetails.User) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) Authentication(org.springframework.security.core.Authentication) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) StringToGrantedAuthority(org.pentaho.platform.plugin.services.security.userrole.ldap.transform.StringToGrantedAuthority) ArrayList(java.util.ArrayList) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) GrantedAuthorityToString(org.pentaho.platform.plugin.services.security.userrole.ldap.transform.GrantedAuthorityToString)

Example 90 with StandaloneSession

use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.

the class WsdlPageTest method setUp.

@Before
public void setUp() {
    beforeTestCfg = AxisWebServiceManager.currentAxisConfiguration;
    beforeTestCtx = AxisWebServiceManager.currentAxisConfigContext;
    AxisConfiguration axisCfg = new AxisConfiguration();
    AxisWebServiceManager.currentAxisConfiguration = axisCfg;
    AxisWebServiceManager.currentAxisConfigContext = new ConfigurationContext(axisCfg);
    out = new ByteArrayOutputStream();
    IOutputHandler outputHandler = new SimpleOutputHandler(out, false);
    outputHandler.setMimeTypeListener(new MimeTypeListener());
    StandaloneSession session = new StandaloneSession("test");
    StubServiceSetup serviceSetup = new StubServiceSetup();
    serviceSetup.setSession(session);
    contentGenerator = new AxisServiceWsdlGenerator();
    contentGenerator.setOutputHandler(outputHandler);
    contentGenerator.setMessagesList(new ArrayList<String>());
    contentGenerator.setSession(session);
    contentGenerator.setUrlFactory(new SimpleUrlFactory(BASE_URL + "?"));
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisServiceWsdlGenerator(org.pentaho.platform.plugin.services.webservices.content.AxisServiceWsdlGenerator) IOutputHandler(org.pentaho.platform.api.engine.IOutputHandler) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) Before(org.junit.Before)

Aggregations

StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)218 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)74 ArrayList (java.util.ArrayList)46 Authentication (org.springframework.security.core.Authentication)39 Test (org.junit.Test)38 OutputStream (java.io.OutputStream)34 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)30 GrantedAuthority (org.springframework.security.core.GrantedAuthority)30 User (org.springframework.security.core.userdetails.User)30 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)29 UserDetails (org.springframework.security.core.userdetails.UserDetails)29 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)24 File (java.io.File)21 SimpleParameterProvider (org.pentaho.platform.engine.core.solution.SimpleParameterProvider)21 StandaloneObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory)21 StandaloneSpringPentahoObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)21 IPentahoUser (org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)20 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)20 HashMap (java.util.HashMap)16 Before (org.junit.Before)16