private Key(AuthInfo authInfo, String revisionId) { this.user = authInfo.getUserID(); this.principals = authInfo.getPrincipals(); this.revisionId = revisionId; }
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 testCreateFromSubjectWithPrincipals() { Subject subject = new Subject(); subject.getPrincipals().addAll(PRINCIPALS); AuthInfo info = AuthInfoImpl.createFromSubject(subject); assertNull(info.getUserID()); assertEquals(PRINCIPALS, info.getPrincipals()); assertEquals(0, info.getAttributeNames().length); }
@Override public boolean init(@NotNull Session session, @NotNull Root root, @NotNull NamePathMapper namePathMapper, boolean isWorkspaceImport, int uuidBehavior, @NotNull ReferenceChangeTracker referenceTracker, @NotNull SecurityProvider securityProvider) { isSystemSession = root.getContentSession().getAuthInfo().getPrincipals().contains(SystemPrincipal.INSTANCE); return true; }
@Override public String getUserID() { return sd.getAuthInfo().getUserID(); }
@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(); } } }
@Override public String[] getAttributeNames() { Set<String> names = newTreeSet(sessionContext.getAttributes().keySet()); Collections.addAll(names, sd.getAuthInfo().getAttributeNames()); return names.toArray(new String[names.size()]); }
@Override public Object getAttribute(String name) { Object attribute = sd.getAuthInfo().getAttribute(name); if (attribute == null) { attribute = sessionContext.getAttributes().get(name); } return attribute; }
@Nonnull private Set<Principal> getPrincipals() { return root.getContentSession().getAuthInfo().getPrincipals(); }
@Test public void testCreateAuthInfoFromEmptySubject() { AuthInfo info = AuthInfoImpl.createFromSubject(new Subject()); assertNull(info.getUserID()); assertEquals(0, info.getAttributeNames().length); assertTrue(info.getPrincipals().isEmpty()); } }
@Override public String getUserID() { return sd.getAuthInfo().getUserID(); }
@Override public String[] getAttributeNames() { Set<String> names = newTreeSet(sessionContext.getAttributes().keySet()); Collections.addAll(names, sd.getAuthInfo().getAttributeNames()); return names.toArray(new String[names.size()]); }
@Override public Object getAttribute(String name) { Object attribute = sd.getAuthInfo().getAttribute(name); if (attribute == null) { attribute = sessionContext.getAttributes().get(name); } return attribute; }
private boolean impersonate(AuthInfo info, User user) { try { if (user.getID().equals(info.getUserID())) { log.debug("User " + info.getUserID() + " wants to impersonate himself -> success."); return true; } else { log.debug("User " + info.getUserID() + " wants to impersonate " + user.getID()); Subject subject = new Subject(true, info.getPrincipals(), Collections.emptySet(), Collections.emptySet()); return user.getImpersonation().allows(subject); } } catch (RepositoryException e) { log.debug("Error while validating impersonation: {}", e.getMessage()); } return false; }
@NotNull private Set<Principal> getPrincipals() { return root.getContentSession().getAuthInfo().getPrincipals(); }
@Test public void testCreateFromSubjectWithPrivateSimpleCredentials() { Subject subject = new Subject(); subject.getPrivateCredentials().add(new SimpleCredentials(USER_ID, new char[0])); AuthInfo info = AuthInfoImpl.createFromSubject(subject); assertNull(info.getUserID()); assertTrue(info.getPrincipals().isEmpty()); assertEquals(0, info.getAttributeNames().length); }
@Override public String getUserID() { return sd.getAuthInfo().getUserID(); }
@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 String[] getAttributeNames() { Set<String> names = newTreeSet(sessionContext.getAttributes().keySet()); Collections.addAll(names, sd.getAuthInfo().getAttributeNames()); return names.toArray(new String[names.size()]); }
@Override public Object getAttribute(String name) { Object attribute = sd.getAuthInfo().getAttribute(name); if (attribute == null) { attribute = sessionContext.getAttributes().get(name); } return attribute; }