use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class ProxyTrustingFilter method becomeUser.
// cloned from SecurityHelper and adapted to add a default location to the session
protected void becomeUser(final String principalName) {
UserSession session = null;
Locale locale = Locale.getDefault();
ITenantedPrincipleNameResolver tenantedUserNameUtils = PentahoSystem.get(ITenantedPrincipleNameResolver.class, "tenantedUserNameUtils", null);
if (tenantedUserNameUtils != null) {
session = new UserSession(principalName, locale, false, null);
ITenant tenant = tenantedUserNameUtils.getTenant(principalName);
session.setAttribute(IPentahoSession.TENANT_ID_KEY, tenant.getId());
session.setAuthenticated(tenant.getId(), principalName);
} else {
session = new UserSession(principalName, locale, false, null);
session.setAuthenticated(principalName);
}
PentahoSessionHolder.setSession(session);
Authentication auth = SecurityHelper.getInstance().createAuthentication(principalName);
SecurityContextHolder.getContext().setAuthentication(auth);
PentahoSystem.sessionStartup(PentahoSessionHolder.getSession(), null);
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class FileServiceTest method setUp.
@Before
public void setUp() throws ObjectFactoryException {
fileService = spy(new FileService());
fileService.defaultUnifiedRepositoryWebService = mock(DefaultUnifiedRepositoryWebService.class);
fileService.repository = mock(IUnifiedRepository.class);
fileService.policy = mock(IAuthorizationPolicy.class);
PentahoSystem.init();
ITenant tenat = mock(ITenant.class);
resolver = mock(ITenantedPrincipleNameResolver.class);
doReturn(tenat).when(resolver).getTenant(anyString());
doReturn(REAL_USER).when(resolver).getPrincipleName(anyString());
policy = mock(IAuthorizationPolicy.class);
pentahoObjectFactory = mock(IPentahoObjectFactory.class);
platformImporter = mock(IPlatformImporter.class);
when(pentahoObjectFactory.objectDefined(anyString())).thenReturn(true);
when(pentahoObjectFactory.get(this.anyClass(), anyString(), any(IPentahoSession.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
if (invocation.getArguments()[0].equals(IAuthorizationPolicy.class)) {
return policy;
}
if (invocation.getArguments()[0].equals(ITenantedPrincipleNameResolver.class)) {
return resolver;
}
if (invocation.getArguments()[0].equals(IPlatformImporter.class)) {
return platformImporter;
}
return null;
}
});
PentahoSystem.registerObjectFactory(pentahoObjectFactory);
IPentahoSession session = mock(IPentahoSession.class);
doReturn("sampleSession").when(session).getName();
PentahoSessionHolder.setSession(session);
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class JdbcUserRoleListServiceTest method testGetAllUsernamesInRoleForTenant.
@Test
public void testGetAllUsernamesInRoleForTenant() throws Exception {
ITenant defaultTenant = new Tenant("/pentaho/tenant0", true);
login("admin", defaultTenant);
JdbcUserRoleListService dao = makePopulatedJdbcUserRoleListService();
dao.setAllUsernamesInRoleQuery(// $NON-NLS-1$
"SELECT DISTINCT(USERNAME) AS USERNAME FROM AUTHORITIES WHERE AUTHORITY = ? ORDER BY 1");
dao.afterPropertiesSet();
// $NON-NLS-1$
List<String> allUsers = dao.getUsersInRole(defaultTenant, "ROLE_TELLER");
// $NON-NLS-1$
assertTrue("User List should not be empty", allUsers.size() > 0);
for (String username : allUsers) {
// $NON-NLS-1$
System.out.println("ROLE_TELLER User: " + username);
}
try {
allUsers = dao.getUsersInRole(new Tenant("/pentaho", true), "ROLE_TELLER");
} catch (UnsupportedOperationException uoe) {
assertNotNull(uoe);
}
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class DefaultLdapUserRoleListServiceTest method testGetUsernamesInRole1ForTenant.
@Test
public void testGetUsernamesInRole1ForTenant() {
ITenant defaultTenant = new Tenant("/pentaho/tenant0", true);
login("suzy", defaultTenant);
SearchControls con1 = new SearchControls();
// $NON-NLS-1$
con1.setReturningAttributes(new String[] { "uid" });
LdapSearchParamsFactory paramFactory = // $NON-NLS-1$//$NON-NLS-2$
new LdapSearchParamsFactoryImpl("ou=users", "(businessCategory=cn={0}*)", con1);
// $NON-NLS-1$
Transformer transformer1 = new SearchResultToAttrValueList("uid");
GrantedAuthorityToString transformer2 = new GrantedAuthorityToString();
LdapSearch usernamesInRoleSearch = new GenericLdapSearch(getContextSource(), paramFactory, transformer1, transformer2);
DefaultLdapUserRoleListService userRoleListService = getDefaultLdapUserRoleListService();
userRoleListService.setUsernamesInRoleSearch(usernamesInRoleSearch);
// $NON-NLS-1$
List<String> res = userRoleListService.getUsersInRole(defaultTenant, "DEV");
// $NON-NLS-1$
assertTrue(res.contains("pat"));
// $NON-NLS-1$
assertTrue(res.contains("tiffany"));
if (logger.isDebugEnabled()) {
// $NON-NLS-1$
logger.debug("results of getUsernamesInRole1(): " + res);
}
try {
userRoleListService.getUsersInRole(new Tenant("/pentaho", true), "DEV");
} catch (UnsupportedOperationException uoe) {
assertNotNull(uoe);
}
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class DefaultLdapUserRoleListServiceTest method testGetAllUserNames1ForTenant.
@Test
public void testGetAllUserNames1ForTenant() throws Exception {
ITenant defaultTenant = new Tenant("/pentaho/tenant0", true);
login("suzy", defaultTenant);
SearchControls con1 = new SearchControls();
// $NON-NLS-1$
con1.setReturningAttributes(new String[] { "uniqueMember" });
LdapSearchParamsFactoryImpl paramFactory = // $NON-NLS-1$//$NON-NLS-2$
new LdapSearchParamsFactoryImpl("ou=groups", "(objectClass=groupOfUniqueNames)", con1);
paramFactory.afterPropertiesSet();
// $NON-NLS-1$ //$NON-NLS-2$
Transformer transformer1 = new SearchResultToAttrValueList("uniqueMember", "uid");
GenericLdapSearch allUsernamesSearch = new GenericLdapSearch(getContextSource(), paramFactory, transformer1);
allUsernamesSearch.afterPropertiesSet();
DefaultLdapUserRoleListService userRoleListService = getDefaultLdapUserRoleListService();
userRoleListService.setAllUsernamesSearch(allUsernamesSearch);
List res = userRoleListService.getAllUsers(defaultTenant);
// $NON-NLS-1$
assertTrue(res.contains("pat"));
// $NON-NLS-1$
assertTrue(res.contains("admin"));
if (logger.isDebugEnabled()) {
// $NON-NLS-1$
logger.debug("results of getAllUserNames1(): " + res);
}
try {
userRoleListService.getAllUsers(new Tenant("/pentaho", true));
} catch (UnsupportedOperationException uoe) {
assertNotNull(uoe);
}
}
Aggregations