AbstractLoginModule implements LoginModule { @Nullable protected UserManager getUserManager() { UserManager userManager = null; SecurityProvider sp = getSecurityProvider(); Root r = getRoot(); if (r != null && sp != null) { UserConfiguration uc = securityProvider.getConfiguration(UserConfiguration.class); userManager = uc.getUserManager(r, NamePathMapper.DEFAULT); } if (userManager == null && callbackHandler != null) { try { UserManagerCallback userCallBack = new UserManagerCallback(); callbackHandler.handle(new Callback[]{userCallBack}); userManager = userCallBack.getUserManager(); } catch (IOException | UnsupportedCallbackException e) { onError(); log.error(e.getMessage(), e); } } return userManager; }  @Override void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options); @Override boolean logout(); @Override boolean abort(); static final String SHARED_KEY_CREDENTIALS; static final String SHARED_KEY_LOGIN_NAME; static final String SHARED_KEY_ATTRIBUTES; static final String SHARED_KEY_PRE_AUTH_LOGIN; }
@Test public void testGetUserManagerFromCallback() { AbstractLoginModule loginModule = initLoginModule(new TestCallbackHandler(mock(UserManager.class))); UserManager userManager = loginModule.getUserManager(); assertNotNull(userManager); assertSame(userManager, loginModule.getUserManager()); }
@Test public void testGetUserManagerFromIncompleteCallback() { AbstractLoginModule loginModule = initLoginModule(new TestCallbackHandler()); assertNull(loginModule.getUserManager()); }
@Test public void testGetUserManagerIOException() { AbstractLoginModule loginModule = initLoginModule(new ThrowingCallbackHandler(true)); assertNull(loginModule.getUserManager()); }
@Test public void testGetUserManagerUnsupportedCallbackException() { AbstractLoginModule loginModule = initLoginModule(new ThrowingCallbackHandler(false)); assertNull(loginModule.getUserManager()); }
@Test public void testGetUserManagerWithRepositoryCallbackHandler() throws Exception { Root r = mock(Root.class); ContentSession cs = when(mock(ContentSession.class).getLatestRoot()).thenReturn(r).getMock(); ContentRepository cp = when(mock(ContentRepository.class).login(null, null)).thenReturn(cs).getMock(); UserManager um = mock(UserManager.class); UserConfiguration uc = when(mock(UserConfiguration.class).getUserManager(r, NamePathMapper.DEFAULT)).thenReturn(um).getMock(); SecurityProvider sp = when(mock(SecurityProvider.class).getConfiguration(UserConfiguration.class)).thenReturn(uc).getMock(); CallbackHandler cbh = new TestCallbackHandler(cp, sp); AbstractLoginModule loginModule = initLoginModule(cbh); assertEquals(um, loginModule.getUserManager()); }
@Test public void testGetUserManagerMissingCallbackHandler() { AbstractLoginModule loginModule = initLoginModule((CallbackHandler) null); assertNull(loginModule.getUserManager()); }
@Test public void testGetUserManagerMissingRoot() throws Exception { ContentRepository cp = when(mock(ContentRepository.class).login(null, null)).thenReturn(mock(ContentSession.class)).getMock(); CallbackHandler cbh = new TestCallbackHandler(cp, mock(SecurityProvider.class)); AbstractLoginModule loginModule = initLoginModule(cbh); assertNull(loginModule.getUserManager()); }
@Test public void testGetUserManagerMissingSecurityProvider() throws Exception { ContentSession cs = when(mock(ContentSession.class).getLatestRoot()).thenReturn(mock(Root.class)).getMock(); ContentRepository cp = when(mock(ContentRepository.class).login(null, null)).thenReturn(cs).getMock(); CallbackHandler cbh = new TestCallbackHandler(cp, null); AbstractLoginModule loginModule = initLoginModule(cbh); assertNull(loginModule.getUserManager()); }