@Override public Object getAttribute(String name) { Object attribute = sd.getAuthInfo().getAttribute(name); if (attribute == null) { attribute = sessionContext.getAttributes().get(name); } return attribute; }
private static void assertAttributes(@NotNull Map<String, ?> expected, @NotNull AuthInfo info) { assertEquals(expected.size(), info.getAttributeNames().length); for (String aName : info.getAttributeNames()) { assertEquals(expected.get(aName), info.getAttribute(aName)); } }
@Test public void testLoginWithAttributes( ) throws Exception { ContentSession cs = null; try { createTestUser(); SimpleCredentials sc = new SimpleCredentials(USER_ID, USER_PW.toCharArray()); sc.setAttribute("attr", "value"); cs = login(sc); AuthInfo authInfo = cs.getAuthInfo(); assertTrue(Arrays.asList(authInfo.getAttributeNames()).contains("attr")); assertEquals("value", authInfo.getAttribute("attr")); cs.close(); } finally { if (cs != null) { cs.close(); } } }
@Override public Object getAttribute(String name) { Object attribute = sd.getAuthInfo().getAttribute(name); if (attribute == null) { attribute = sessionContext.getAttributes().get(name); } return attribute; }
@Test public void testImpersonationWithAttributes() throws Exception { ContentSession cs = null; try { createTestUser(); SimpleCredentials sc = new SimpleCredentials(USER_ID, USER_PW.toCharArray()); cs = login(sc); AuthInfo authInfo = cs.getAuthInfo(); cs.close(); cs = null; sc = new SimpleCredentials(USER_ID, new char[0]); sc.setAttribute("attr", "value"); ImpersonationCredentials ic = new ImpersonationCredentials(sc, authInfo); cs = login(ic); authInfo = cs.getAuthInfo(); assertTrue(Arrays.asList(authInfo.getAttributeNames()).contains("attr")); assertEquals("value", authInfo.getAttribute("attr")); } finally { if (cs != null) { cs.close(); } } }
@Override public Object getAttribute(String name) { Object attribute = sd.getAuthInfo().getAttribute(name); if (attribute == null) { attribute = sessionContext.getAttributes().get(name); } return attribute; }
@Test public void testLoginSetsAuthInfo() throws Exception { ContentSession cs = null; try { SimpleCredentials sc = new SimpleCredentials(USER_ID, USER_PWD.toCharArray()); sc.setAttribute("attr", "val"); cs = login(sc); AuthInfo ai = cs.getAuthInfo(); assertEquals(USER_ID, ai.getUserID()); assertEquals("val", ai.getAttribute("attr")); } finally { if (cs != null) { cs.close(); } } }