SecurityContextImpl implements SecurityContext { @Override public void secure(final String permission, final Runnable runnable) { final Boolean currentCheckType = checkTypeThreadLocal.get(); if (Boolean.FALSE.equals(currentCheckType)) { runnable.run(); } else { if (permission == null || checkAdmin()) { try { checkTypeThreadLocal.set(Boolean.FALSE); runnable.run(); } finally { checkTypeThreadLocal.set(currentCheckType); } } else { checkLogin(); checkAppPermission(permission); runnable.run(); } } } @Inject  SecurityContextImpl(
            final UserDocumentPermissionsCache userDocumentPermissionsCache,
            final UserGroupsCache userGroupsCache,
            final UserAppPermissionsCache userAppPermissionsCache,
            final UserCache userCache,
            final ProcessingUserIdentityProvider processingUserIdentityProvider); @Override String getUserId(); @Override UserIdentity getUserIdentity(); @Override UserIdentity createIdentity(final String userId); @Override boolean isLoggedIn(); @Override boolean isAdmin(); @Override boolean isProcessingUser(); @Override boolean hasAppPermission(final String permission); @Override boolean hasDocumentPermission(final String documentUuid, final String permission); @Override T asUserResult(final UserIdentity userIdentity, final Supplier<T> supplier); @Override void asUser(final UserIdentity userIdentity, final Runnable runnable); @Override T asProcessingUserResult(final Supplier<T> supplier); @Override void asProcessingUser(final Runnable runnable); @Override T useAsReadResult(final Supplier<T> supplier); @Override void useAsRead(final Runnable runnable); @Override void secure(final String permission, final Runnable runnable); @Override T secureResult(final String permission, final Supplier<T> supplier); @Override void secure(final Runnable runnable); @Override T secureResult(final Supplier<T> supplier); @Override void insecure(final Runnable runnable); @Override T insecureResult(final Supplier<T> supplier);  }
@Test void test() { assertThatThrownBy(() -> { final SecurityContext securityContext = new SecurityContextImpl(null, null, null, null, null); securityContext.secure(Assertions::fail); }).isInstanceOf(AuthenticationException.class); }