@Override public void start() { realm = securityRealmFactory.getRealm(); if (realm != null) { authenticator = requireNonNull(realm.doGetAuthenticator(), "No authenticator available"); externalUsersProvider = requireNonNull(realm.getUsersProvider(), "No users provider available"); externalGroupsProvider = realm.getGroupsProvider(); } }
private void executeStartWithGroupSync() { when(realm.doGetAuthenticator()).thenReturn(authenticator); when(realm.getUsersProvider()).thenReturn(externalUsersProvider); when(realm.getGroupsProvider()).thenReturn(externalGroupsProvider); when(securityRealmFactory.getRealm()).thenReturn(realm); underTest.start(); }
private void executeStartWithoutGroupSync() { when(realm.doGetAuthenticator()).thenReturn(authenticator); when(realm.getUsersProvider()).thenReturn(externalUsersProvider); when(securityRealmFactory.getRealm()).thenReturn(realm); underTest.start(); }
@Test public void doGetAuthenticator() { final Authenticator authenticator = mock(Authenticator.class); SecurityRealm realm = new SecurityRealm() { @Override public Authenticator doGetAuthenticator() { return authenticator; } }; assertThat(realm.doGetAuthenticator()).isSameAs(authenticator); assertThat(realm.getLoginPasswordAuthenticator()).isNull(); }
@Test public void fail_to_start_when_no_user_provider() { when(realm.doGetAuthenticator()).thenReturn(authenticator); when(realm.getUsersProvider()).thenReturn(null); when(securityRealmFactory.getRealm()).thenReturn(realm); expectedException.expect(NullPointerException.class); expectedException.expectMessage("No users provider available"); underTest.start(); }
@Test public void getLoginPasswordAuthenticator_deprecated_method_replaced_by_getAuthenticator() { final LoginPasswordAuthenticator deprecatedAuthenticator = mock(LoginPasswordAuthenticator.class); SecurityRealm realm = new SecurityRealm() { @Override public LoginPasswordAuthenticator getLoginPasswordAuthenticator() { return deprecatedAuthenticator; } }; Authenticator proxy = realm.doGetAuthenticator(); Authenticator.Context context = new Authenticator.Context("foo", "bar", mock(HttpServletRequest.class)); proxy.doAuthenticate(context); verify(deprecatedAuthenticator).authenticate("foo", "bar"); } }
@Test public void fail_to_start_when_no_authenticator() { when(realm.doGetAuthenticator()).thenReturn(null); when(securityRealmFactory.getRealm()).thenReturn(realm); expectedException.expect(NullPointerException.class); expectedException.expectMessage("No authenticator available"); underTest.start(); }
@Override public void start() { realm = securityRealmFactory.getRealm(); if (realm != null) { authenticator = requireNonNull(realm.doGetAuthenticator(), "No authenticator available"); externalUsersProvider = requireNonNull(realm.getUsersProvider(), "No users provider available"); externalGroupsProvider = realm.getGroupsProvider(); } }