@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; }
private Delegatee(@NotNull SyncHandler handler, @NotNull ExternalIdentityProvider idp, @NotNull ContentSession systemSession, @NotNull SecurityProvider securityProvider, int batchSize) { this.handler = handler; this.idp = idp; this.systemSession = systemSession; this.batchSize = batchSize; root = systemSession.getLatestRoot(); userMgr = securityProvider.getConfiguration(UserConfiguration.class).getUserManager(root, NamePathMapper.DEFAULT); context = handler.createContext(idp, userMgr, new ValueFactoryImpl(root, NamePathMapper.DEFAULT)); log.info("Created delegatee for SyncMBean with session: {} {}", systemSession, systemSession.getAuthInfo().getUserID()); }
private static <T> void logOperationDetails(ContentSession session, SessionOperation<T> ops) { if (readOperationLogger.isTraceEnabled() || writeOperationLogger.isTraceEnabled() || auditLogger.isDebugEnabled()) { Logger log = ops.isUpdate() ? writeOperationLogger : readOperationLogger; log.trace("[{}] {}", session, ops); //For a logout operation the auth info is not accessible if (!ops.isLogout() && !ops.isRefresh() && !ops.isSave() && ops.isUpdate()) { auditLogger.debug("[{}] [{}] {}", session.getAuthInfo().getUserID(), session, ops); } } }
@Override protected void beforeSuite() throws Exception { super.beforeSuite(); Credentials creds = (runAsAdmin) ? getCredentials() : new GuestCredentials(); cs = contentRepository.login(creds, null); subject = new Subject(true, cs.getAuthInfo().getPrincipals(), Collections.emptySet(), Collections.emptySet()); }
UserPrincipalProvider(@NotNull Root root, @NotNull UserConfiguration userConfiguration, @NotNull NamePathMapper namePathMapper) { this.root = root; this.config = userConfiguration; this.namePathMapper = namePathMapper; this.userProvider = new UserProvider(root, config.getParameters()); this.membershipProvider = new MembershipProvider(root, config.getParameters()); expiration = config.getParameters().getConfigValue(PARAM_CACHE_EXPIRATION, EXPIRATION_NO_CACHE); cacheEnabled = (expiration > EXPIRATION_NO_CACHE && root.getContentSession().getAuthInfo().getPrincipals().contains(SystemPrincipal.INSTANCE)); }
UserPrincipalProvider(@NotNull Root root, @NotNull UserConfiguration userConfiguration, @NotNull NamePathMapper namePathMapper) { this.root = root; this.config = userConfiguration; this.namePathMapper = namePathMapper; this.userProvider = new UserProvider(root, config.getParameters()); this.membershipProvider = new MembershipProvider(root, config.getParameters()); expiration = config.getParameters().getConfigValue(PARAM_CACHE_EXPIRATION, EXPIRATION_NO_CACHE); cacheEnabled = (expiration > EXPIRATION_NO_CACHE && root.getContentSession().getAuthInfo().getPrincipals().contains(SystemPrincipal.INSTANCE)); }
UserPrincipalProvider(@Nonnull Root root, @Nonnull UserConfiguration userConfiguration, @Nonnull NamePathMapper namePathMapper) { this.root = root; this.config = userConfiguration; this.namePathMapper = namePathMapper; this.userProvider = new UserProvider(root, config.getParameters()); this.membershipProvider = new MembershipProvider(root, config.getParameters()); expiration = config.getParameters().getConfigValue(PARAM_CACHE_EXPIRATION, EXPIRATION_NO_CACHE); cacheEnabled = (expiration > EXPIRATION_NO_CACHE && root.getContentSession().getAuthInfo().getPrincipals().contains(SystemPrincipal.INSTANCE)); }
@Override public void before() throws Exception { super.before(); cpp = createPermissionProvider(root.getContentSession().getAuthInfo().getPrincipals()); cppO = createPermissionProviderOR(root.getContentSession().getAuthInfo().getPrincipals()); }
@Test public void testGetPrincipals() throws Exception { String adminId = adminSession.getAuthInfo().getUserID(); Set<? extends Principal> principals = principalProvider.getPrincipals(adminId); assertNotNull(principals); assertFalse(principals.isEmpty()); assertTrue(principals.contains(EveryonePrincipal.getInstance())); for (Principal principal : principals) { assertNotNull(principalProvider.getPrincipal(principal.getName())); } }
@NotNull private TreePermission getTreePermission(@NotNull ContentSession cs, @NotNull String path) throws Exception { Root r = cs.getLatestRoot(); PermissionProvider pp = config.getPermissionProvider(r, cs.getWorkspaceName(), cs.getAuthInfo().getPrincipals()); Tree t = r.getTree(PathUtils.ROOT_PATH); TreePermission tp = pp.getTreePermission(t, TreePermission.EMPTY); for (String name : PathUtils.elements(path)) { t = t.getChild(name); tp = pp.getTreePermission(t, tp); } return tp; }
@Test public void testAnonymousID() throws RepositoryException, LoginException { testSession = login(new GuestCredentials()); String anonymousID = testSession.getAuthInfo().getUserID(); // EXERCISE: what value do you expect for 'anonymousID'? explain why. is there a solution without hardcoding? String expectedID = null; assertEquals(expectedID, anonymousID); }
@Test public void testAuthenticateImpersonationCredentials() throws Exception { SimpleCredentials sc = new SimpleCredentials(userId, new char[0]); assertTrue(authentication.authenticate(new ImpersonationCredentials(sc, adminSession.getAuthInfo()))); }
@Test public void testGuest() throws Exception { ContentSession cs = null; try { cs = login(new GuestCredentials()); assertEquals(UserConstants.DEFAULT_ANONYMOUS_ID, cs.getAuthInfo().getUserID()); } finally { if (cs != null) { cs.close(); } } }
private TreePermission getTreePermission(String path) throws Exception { ContentSession testSession = createTestSession(); PermissionProvider pp = config.getPermissionProvider(testSession.getLatestRoot(), testSession.getWorkspaceName(), testSession.getAuthInfo().getPrincipals()); return pp.getTreePermission(root.getTree(path), TreePermission.EMPTY); }
@Test public void testGuestLogin() throws Exception { try (ContentSession cs = login(new GuestCredentials())) { AuthInfo authInfo = cs.getAuthInfo(); String anonymousID = UserUtil.getAnonymousId(getUserConfiguration().getParameters()); assertEquals(anonymousID, authInfo.getUserID()); } }
@Test public void testNullLogin() throws Exception { ContentSession cs = login(null); try { AuthInfo authInfo = cs.getAuthInfo(); String anonymousID = UserUtil.getAnonymousId(getUserConfiguration().getParameters()); assertEquals(anonymousID, authInfo.getUserID()); } finally { cs.close(); } }
@Test public void testNullLogin() throws Exception { ContentSession cs = login(null); try { AuthInfo authInfo = cs.getAuthInfo(); String anonymousID = UserUtil.getAnonymousId(getUserConfiguration().getParameters()); assertEquals(anonymousID, authInfo.getUserID()); } finally { cs.close(); } }
@Test public void testLogin() throws Exception { TestCredentials creds = new TestCredentials("testUser"); ContentSession cs = login(creds); try { AuthInfo info = cs.getAuthInfo(); assertEquals("testUser", info.getUserID()); assertAttributes(getCredentialsSupport().getAttributes(creds), info); } finally { cs.close(); } }
@Override public void before() throws Exception { super.before(); ContentSession cs = root.getContentSession(); Set<Principal> testPrincipals = ImmutableSet.of(getTestUser().getPrincipal(), EveryonePrincipal.getInstance()); cppTestUser = createPermissionProvider(testPrincipals); defTestUser = getConfig(AuthorizationConfiguration.class).getPermissionProvider(root, cs.getWorkspaceName(), testPrincipals); Set<Principal> adminPrincipals = cs.getAuthInfo().getPrincipals(); cppAdminUser = createPermissionProvider(adminPrincipals); defAdminUser = getConfig(AuthorizationConfiguration.class).getPermissionProvider(root, cs.getWorkspaceName(), adminPrincipals); }
@Override public void before() throws Exception { super.before(); cppTestUser = createPermissionProvider(getTestUser().getPrincipal(), EveryonePrincipal.getInstance()); cppAdminUser = createPermissionProvider(root.getContentSession().getAuthInfo().getPrincipals()); pbp = new PrivilegeBitsProvider(readOnlyRoot); denied = pbp.getBits(JCR_ADD_CHILD_NODES, REP_ADD_PROPERTIES); }