use of org.neo4j.internal.kernel.api.security.AuthSubject in project neo4j by neo4j.
the class AuthorizationFilterTest method shouldAuthorizeWhenPasswordChangeRequired.
@Test
void shouldAuthorizeWhenPasswordChangeRequired() throws Exception {
// Given
final AuthorizationEnabledFilter filter = newFilter();
String credentials = Base64.encodeBase64String("foo:bar".getBytes(UTF_8));
BasicLoginContext loginContext = mock(BasicLoginContext.class);
AuthSubject authSubject = mock(AuthSubject.class);
when(servletRequest.getRemoteAddr()).thenReturn("client");
when(servletRequest.getRemotePort()).thenReturn(1337);
when(servletRequest.getServerName()).thenReturn("server");
when(servletRequest.getServerPort()).thenReturn(42);
when(servletRequest.getMethod()).thenReturn("GET");
when(servletRequest.getContextPath()).thenReturn("/db/data");
when(servletRequest.getRequestURL()).thenReturn(new StringBuffer("http://bar.baz:7474/db/data/"));
when(servletRequest.getRequestURI()).thenReturn("/db/data/");
when(servletRequest.getHeader(HttpHeaders.AUTHORIZATION)).thenReturn("BASIC " + credentials);
when(authManager.login(argThat(new AuthTokenMatcher(authToken("foo", "bar"))), any())).thenReturn(loginContext);
when(loginContext.subject()).thenReturn(authSubject);
when(authSubject.getAuthenticationResult()).thenReturn(AuthenticationResult.PASSWORD_CHANGE_REQUIRED);
// When
filter.doFilter(servletRequest, servletResponse, filterChain);
// Then
verify(filterChain).doFilter(eq(new AuthorizedRequestWrapper(BASIC_AUTH, "foo", servletRequest, AUTH_DISABLED)), same(servletResponse));
}
use of org.neo4j.internal.kernel.api.security.AuthSubject in project neo4j by neo4j.
the class StubKernelTransaction method subjectOrAnonymous.
@Override
public AuthSubject subjectOrAnonymous() {
AuthSubject subject = mock(AuthSubject.class);
when(subject.username()).thenReturn("testUser");
return subject;
}
Aggregations