@Test public void testMondrianOneToOneUserRoleListMapper() throws Exception { final IConnectionUserRoleMapper mapper = new MondrianOneToOneUserRoleListMapper(); try { String[] roles = SecurityHelper.getInstance() .runAsUser( "simplebob", new Callable<String[]>() { @Override public String[] call() throws Exception { return mapper.mapConnectionRoles( PentahoSessionHolder.getSession(), "SteelWheelsRoles"); } }); Assert.assertNotNull(roles); Assert.assertEquals(2, roles.length); Assert.assertEquals("Role1", roles[0]); Assert.assertEquals("Role2", roles[1]); } catch (PentahoAccessControlException e) { Assert.fail(e.getMessage()); } }
@Test public void testLookupMapUserRoleListMapper() throws Exception { Map<String, String> lookup = new HashMap<String, String>(); lookup.put("ceo", "Role1"); lookup.put("Not Pentaho", "Role2"); lookup.put("Not Mondrian or Pentaho", "Role3"); final MondrianLookupMapUserRoleListMapper mapper = new MondrianLookupMapUserRoleListMapper(); mapper.setLookupMap(lookup); try { String[] roles = SecurityHelper.getInstance() .runAsUser( "admin", new Callable<String[]>() { @Override public String[] call() throws Exception { return mapper.mapConnectionRoles( PentahoSessionHolder.getSession(), "SteelWheelsRoles"); } }); Assert.assertNotNull(roles); Assert.assertEquals(1, roles.length); Assert.assertEquals("Role1", roles[0]); } catch (PentahoAccessControlException e) { Assert.fail(e.getMessage()); } }
@Test public void testMondrianUserSessionUserRoleListMapper() throws Exception { final MondrianUserSessionUserRoleListMapper mapper = new MondrianUserSessionUserRoleListMapper(); mapper.setSessionProperty("rolesAttribute"); try { String[] roles = SecurityHelper.getInstance() .runAsUser( "admin", new Callable<String[]>() { @Override public String[] call() throws Exception { IPentahoSession session = PentahoSessionHolder.getSession(); session.setAttribute( "rolesAttribute", new Object[] {"mondrianRole1", "mondrianRole2", "mondrianRole3"}); return mapper.mapConnectionRoles(session, "SteelWheelsRoles"); } }); Assert.assertNotNull(roles); Assert.assertEquals(3, roles.length); Assert.assertEquals("mondrianRole1", roles[0]); Assert.assertEquals("mondrianRole2", roles[1]); Assert.assertEquals("mondrianRole3", roles[2]); } catch (PentahoAccessControlException e) { Assert.fail(e.getMessage()); } }
@Test public void testNoMatchLookupMapUserRoleListMapper() throws Exception { Map<String, String> lookup = new HashMap<String, String>(); lookup.put("No Match", "Role1"); lookup.put("No Match Here Either", "Role2"); final MondrianLookupMapUserRoleListMapper mapper = new MondrianLookupMapUserRoleListMapper(); mapper.setLookupMap(lookup); mapper.setFailOnEmptyRoleList(true); try { SecurityHelper.getInstance() .runAsUser( "admin", new Callable<String[]>() { @Override public String[] call() throws Exception { return mapper.mapConnectionRoles( PentahoSessionHolder.getSession(), "SteelWheelsRoles"); } }); Assert.fail(); } catch (PentahoAccessControlException e) { // no op. } mapper.setFailOnEmptyRoleList(false); try { String[] roles = SecurityHelper.getInstance() .runAsUser( "admin", new Callable<String[]>() { @Override public String[] call() throws Exception { return mapper.mapConnectionRoles( PentahoSessionHolder.getSession(), "SteelWheelsRoles"); } }); Assert.assertNull(roles); } catch (PentahoAccessControlException e) { Assert.fail(e.getMessage()); } }
@Test public void testNoMatchMondrianOneToOneUserRoleListMapper() throws Exception { final MondrianOneToOneUserRoleListMapper mapper = new MondrianOneToOneUserRoleListMapper(); mapper.setFailOnEmptyRoleList(true); try { SecurityHelper.getInstance() .runAsUser( "admin", new Callable<String[]>() { @Override public String[] call() throws Exception { return mapper.mapConnectionRoles( PentahoSessionHolder.getSession(), "SteelWheelsRoles"); } }); Assert.fail(); } catch (PentahoAccessControlException e) { // No op. } mapper.setFailOnEmptyRoleList(false); try { String[] roles = SecurityHelper.getInstance() .runAsUser( "simplebob", new Callable<String[]>() { @Override public String[] call() throws Exception { return mapper.mapConnectionRoles( PentahoSessionHolder.getSession(), "SteelWheelsRoles"); } }); Assert.assertArrayEquals(new String[] {"Role1", "Role2"}, roles); } catch (PentahoAccessControlException e) { Assert.fail(e.getMessage()); } }
@Test public void testNoMatchMondrianUserSessionUserRoleListMapper() throws Exception { final MondrianUserSessionUserRoleListMapper mapper = new MondrianUserSessionUserRoleListMapper(); mapper.setSessionProperty("rolesAttribute"); try { String[] roles = SecurityHelper.getInstance() .runAsUser( "admin", new Callable<String[]>() { @Override public String[] call() throws Exception { return mapper.mapConnectionRoles( PentahoSessionHolder.getSession(), "SteelWheelsRoles"); } }); Assert.assertNull(roles); } catch (PentahoAccessControlException e) { Assert.fail(e.getMessage()); } }