Search in sources :

Example 6 with StandaloneSession

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

the class SessionCachingMetadataDomainRepositoryTest method shouldNotUseDomainIdsCacheIfDisabled.

@Test
public void shouldNotUseDomainIdsCacheIfDisabled() throws Exception {
    MockSessionAwareMetadataDomainRepository mock = spy(new MockSessionAwareMetadataDomainRepository());
    PentahoSessionHolder.setSession(new StandaloneSession("session", "1"));
    SessionCachingMetadataDomainRepository repo = new SessionCachingMetadataDomainRepository(mock);
    Domain domain = new Domain();
    domain.setId("id");
    mock.setPersistedDomains(domain);
    ICacheManager manager = mock(ICacheManager.class);
    repo.cacheManager = manager;
    repo.domainIdsCacheEnabled = false;
    Set<String> domainIds = repo.getDomainIds();
    assertEquals(1, domainIds.size());
    assertTrue(domainIds.contains("id"));
    verify(mock, times(1)).getDomainIds();
    verify(mock, times(1)).reloadDomains();
    verify(manager, times(0)).getFromRegionCache("metadata-domain-repository", "domain-id-cache-for-session:1");
    verify(manager, times(0)).addCacheRegion("domain-id-cache-for-session:1");
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) MockSessionAwareMetadataDomainRepository(org.pentaho.test.platform.plugin.services.metadata.MockSessionAwareMetadataDomainRepository) ICacheManager(org.pentaho.platform.api.engine.ICacheManager) Domain(org.pentaho.metadata.model.Domain) Test(org.junit.Test)

Example 7 with StandaloneSession

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

the class ZipExportProcessorTest method init.

@Before
public void init() throws IOException, PlatformInitializationException, DomainIdNullException, DomainAlreadyExistsException, DomainStorageException {
    List<Locale> availableLocales = java.util.Collections.singletonList(LOCALE_DEFAULT);
    Properties localePropertries = new Properties();
    localePropertries.setProperty("name1", "value1");
    final RepositoryFile file0 = new RepositoryFile.Builder("").path("/").id("/").folder(true).build();
    final RepositoryFile file1 = new RepositoryFile.Builder("home").path("/home/").id("/home/").folder(true).build();
    final RepositoryFile file2 = new RepositoryFile.Builder("test user").path("/home/test user/").id("/home/test user/").folder(true).build();
    final RepositoryFile file3 = new RepositoryFile.Builder("two words").path("/home/test user/two words/").id("/home/test user/two words/").folder(true).build();
    final RepositoryFile fileX = new RepositoryFile.Builder("eval (+)%.prpt").path("/home/test user/two words/eval (+)%.prpt").id("/home/test user/two words/eval (+)%.prpt").folder(false).build();
    final RepositoryFile[] repoFiles = new RepositoryFile[] { file0, file1, file2, file3, fileX };
    final Map<Serializable, RepositoryFile> repoFilesMap = new HashMap<Serializable, RepositoryFile>();
    for (RepositoryFile f : repoFiles) {
        repoFilesMap.put(f.getId(), f);
    }
    repo = mock(IUnifiedRepository.class);
    final Answer<RepositoryFile> answerRepoGetFile = new Answer<RepositoryFile>() {

        @Override
        public RepositoryFile answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            final Object fileId = args[0];
            return getRepoFile(repoFilesMap, fileId);
        }
    };
    Mockito.doAnswer(answerRepoGetFile).when(repo).getFile(anyString());
    Mockito.doAnswer(answerRepoGetFile).when(repo).getFile(anyString(), Mockito.anyBoolean());
    Mockito.doAnswer(answerRepoGetFile).when(repo).getFile(anyString(), Mockito.anyBoolean(), any(IPentahoLocale.class));
    Mockito.doAnswer(answerRepoGetFile).when(repo).getFile(anyString(), any(IPentahoLocale.class));
    Mockito.doAnswer(answerRepoGetFile).when(repo).getFileById(any(Serializable.class));
    Mockito.doAnswer(answerRepoGetFile).when(repo).getFileById(any(Serializable.class), Mockito.anyBoolean());
    Mockito.doAnswer(answerRepoGetFile).when(repo).getFileById(any(Serializable.class), Mockito.anyBoolean(), any(IPentahoLocale.class));
    Mockito.doAnswer(answerRepoGetFile).when(repo).getFileById(any(Serializable.class), any(IPentahoLocale.class));
    Answer<List<RepositoryFile>> answerRepoGetChildren = new Answer<List<RepositoryFile>>() {

        @Override
        public List<RepositoryFile> answer(InvocationOnMock invocation) throws Throwable {
            // returns the following item from <repoFiles>
            RepositoryRequest r = (RepositoryRequest) invocation.getArguments()[0];
            String path = r.getPath();
            RepositoryFile thisFile = getRepoFile(repoFilesMap, path);
            if (thisFile == null || !thisFile.isFolder()) {
                return Collections.emptyList();
            }
            for (int i = 0, n = repoFiles.length - 1; i < n; i++) {
                RepositoryFile iFile = repoFiles[i];
                if (iFile == thisFile || iFile.getId().equals(thisFile.getId())) {
                    return Collections.singletonList(repoFiles[i + 1]);
                }
            }
            return Collections.emptyList();
        }
    };
    Mockito.doAnswer(answerRepoGetChildren).when(repo).getChildren(any(RepositoryRequest.class));
    doReturn(availableLocales).when(repo).getAvailableLocalesForFile(Mockito.any(RepositoryFile.class));
    doReturn(availableLocales).when(repo).getAvailableLocalesForFileById(Mockito.any(Serializable.class));
    doReturn(availableLocales).when(repo).getAvailableLocalesForFileByPath(Mockito.any(String.class));
    doReturn(localePropertries).when(repo).getLocalePropertiesForFileById(Mockito.any(File.class), Mockito.anyString());
    RepositoryFileSid sid = mock(RepositoryFileSid.class);
    doReturn("testUser").when(sid).getName();
    doReturn(Type.USER).when(sid).getType();
    final RepositoryFileAcl mockAcl = mock(RepositoryFileAcl.class);
    doReturn(sid).when(mockAcl).getOwner();
    doReturn(mockAcl).when(repo).getAcl(any(Serializable.class));
    Answer<IRepositoryFileData> answerGetDataForRead = new Answer<IRepositoryFileData>() {

        @Override
        public IRepositoryFileData answer(InvocationOnMock invocation) throws Throwable {
            Serializable id = (Serializable) invocation.getArguments()[0];
            RepositoryFile file = getRepoFile(repoFilesMap, id);
            if (!file.isFolder()) {
                return new SimpleRepositoryFileData(new ByteArrayInputStream(new byte[0]), "UTF-8", MIME_PRPT.getName());
            }
            return null;
        }
    };
    doAnswer(answerGetDataForRead).when(repo).getDataForRead(Mockito.any(Serializable.class), Mockito.any(Class.class));
    exportHandler = new DefaultExportHandler();
    defaultConverter = new StreamConverter(repo);
    PentahoSystem.clearObjectFactory();
    microPlatform = new MicroPlatform(getSolutionPath());
    microPlatform.defineInstance(IUnifiedRepository.class, repo);
    // microPlatform.defineInstance( IPlatformMimeResolver.class, mimeResolver );
    microPlatform.defineInstance(ISolutionEngine.class, Mockito.mock(SolutionEngine.class));
    microPlatform.defineInstance(IDatasourceMgmtService.class, Mockito.mock(IDatasourceMgmtService.class));
    microPlatform.start();
    exportSession = new StandaloneSession();
    PentahoSessionHolder.setStrategyName(PentahoSessionHolder.MODE_GLOBAL);
    PentahoSessionHolder.setSession(exportSession);
}
Also used : Locale(java.util.Locale) IPentahoLocale(org.pentaho.platform.api.locale.IPentahoLocale) IRepositoryFileData(org.pentaho.platform.api.repository2.unified.IRepositoryFileData) Serializable(java.io.Serializable) HashMap(java.util.HashMap) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) Matchers.anyString(org.mockito.Matchers.anyString) Properties(java.util.Properties) IDatasourceMgmtService(org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService) RepositoryFileSid(org.pentaho.platform.api.repository2.unified.RepositoryFileSid) SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) List(java.util.List) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) SolutionEngine(org.pentaho.platform.engine.services.solution.SolutionEngine) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) ByteArrayInputStream(java.io.ByteArrayInputStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IPentahoLocale(org.pentaho.platform.api.locale.IPentahoLocale) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Before(org.junit.Before)

Example 8 with StandaloneSession

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

the class UserRoleDaoResource_RolesUpdatedTest method setUp.

@Before
public void setUp() {
    UserRoleDaoService service = mock(UserRoleDaoService.class);
    doReturn(new RoleListWrapper(allRoles)).when(service).getRolesForUser(eq(SESSION_USER_NAME));
    resource = new UserRoleDaoResource(mock(IRoleAuthorizationPolicyRoleBindingDao.class), mock(ITenantManager.class), new ArrayList<String>(), ROLE_NAME_ADMINISTRATOR, service);
    session = new StandaloneSession(SESSION_USER_NAME);
    resource = spy(resource);
    doReturn(session).when(resource).getSession();
    userRoleDao = mock(IUserRoleDao.class);
    doReturn(new ArrayList<IPentahoRole>()).when(userRoleDao).getRoles(any(ITenant.class));
    doReturn(mock(ITenant.class)).when(resource).getTenant(anyString());
    doReturn(userRoleDao).when(resource).getUserRoleDao();
    doReturn(true).when(resource).canAdminister();
}
Also used : UserRoleDaoService(org.pentaho.platform.web.http.api.resources.services.UserRoleDaoService) ITenant(org.pentaho.platform.api.mt.ITenant) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) ArrayList(java.util.ArrayList) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) Before(org.junit.Before)

Example 9 with StandaloneSession

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

the class AxisServiceExecutorTest method setUp.

@Before
public void setUp() throws Exception {
    StandaloneSession session = new StandaloneSession("test");
    StubServiceSetup serviceSetup = new StubServiceSetup();
    serviceSetup.setSession(session);
    AxisConfiguration axisCfg = serviceSetup.getAxisConfiguration();
    ConfigurationContext configContext = new ConfigurationContext(axisCfg);
    serviceSetup.loadServices();
    TransportInDescription tIn = new TransportInDescription(DEAFULT_TRANSPOT_PROTOCOL);
    StubTransportListener receiver = new StubTransportListener();
    tIn.setReceiver(receiver);
    axisCfg.addTransportIn(tIn);
    TransportOutDescription tOut = new TransportOutDescription(DEAFULT_TRANSPOT_PROTOCOL);
    StubTransportSender sender = new StubTransportSender();
    tOut.setSender(sender);
    axisCfg.addTransportOut(tOut);
    AxisWebServiceManager.currentAxisConfiguration = axisCfg;
    AxisWebServiceManager.currentAxisConfigContext = configContext;
    out = new ByteArrayOutputStream();
    IOutputHandler outputHandler = new SimpleOutputHandler(out, false);
    outputHandler.setMimeTypeListener(new MimeTypeListener());
    contentGenerator = new AxisServiceExecutor();
    contentGenerator.setOutputHandler(outputHandler);
    contentGenerator.setMessagesList(new ArrayList<String>());
    contentGenerator.setSession(session);
    contentGenerator.setUrlFactory(new SimpleUrlFactory(BASE_URL + "?"));
    assertNotNull("contentGenerator is null", contentGenerator);
    assertNotNull("Logger is null", contentGenerator.getLogger());
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) StubTransportSender(org.pentaho.test.platform.plugin.services.webservices.StubTransportSender) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) TransportInDescription(org.apache.axis2.description.TransportInDescription) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOutputHandler(org.pentaho.platform.api.engine.IOutputHandler) StubServiceSetup(org.pentaho.test.platform.plugin.services.webservices.StubServiceSetup) MimeTypeListener(org.pentaho.test.platform.plugin.services.webservices.MimeTypeListener) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) StubTransportListener(org.pentaho.test.platform.plugin.services.webservices.StubTransportListener) TransportOutDescription(org.apache.axis2.description.TransportOutDescription) Before(org.junit.Before)

Example 10 with StandaloneSession

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

the class RepositoryTenantManager method login.

protected void login(final String username, String tenantAdminRoleId) {
    StandaloneSession pentahoSession = new StandaloneSession(username);
    pentahoSession.setAuthenticated(null, username);
    PentahoSessionHolder.setSession(pentahoSession);
    final String password = "ignored";
    List<GrantedAuthority> authList = new ArrayList<GrantedAuthority>();
    authList.add(new SimpleGrantedAuthority(tenantAdminRoleId));
    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) ArrayList(java.util.ArrayList) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken)

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