use of com.synopsys.integration.alert.component.authentication.security.ldap.LdapManager in project hub-alert by blackducksoftware.
the class AuthenticationActionsTestIT method testAuthenticationLDAPUserIT.
@Test
public void testAuthenticationLDAPUserIT() throws Exception {
HttpServletRequest servletRequest = new MockHttpServletRequest();
HttpServletResponse servletResponse = new MockHttpServletResponse();
Authentication authentication = Mockito.mock(Authentication.class);
Mockito.when(authentication.isAuthenticated()).thenReturn(true);
LdapAuthenticationProvider ldapAuthenticationProvider = Mockito.mock(LdapAuthenticationProvider.class);
Mockito.when(ldapAuthenticationProvider.authenticate(Mockito.any(Authentication.class))).thenReturn(authentication);
LdapManager mockLdapManager = Mockito.mock(LdapManager.class);
Mockito.when(mockLdapManager.isLdapEnabled()).thenReturn(true);
Mockito.when(mockLdapManager.getAuthenticationProvider()).thenReturn(Optional.of(ldapAuthenticationProvider));
AuthenticationActions authenticationActions = new AuthenticationActions(authenticationProvider, csrfTokenRepository);
ActionResponse<Void> response = authenticationActions.authenticateUser(servletRequest, servletResponse, mockLoginRestModel.createRestModel());
assertTrue(response.isSuccessful());
assertFalse(response.hasContent());
}
use of com.synopsys.integration.alert.component.authentication.security.ldap.LdapManager in project hub-alert by blackducksoftware.
the class AuthenticationActionsTestIT method testAuthenticationLDAPExceptionIT.
@Test
public void testAuthenticationLDAPExceptionIT() throws Exception {
HttpServletRequest servletRequest = new MockHttpServletRequest();
HttpServletResponse servletResponse = new MockHttpServletResponse();
Authentication authentication = Mockito.mock(Authentication.class);
Mockito.when(authentication.isAuthenticated()).thenReturn(true);
LdapAuthenticationProvider ldapAuthenticationProvider = Mockito.mock(LdapAuthenticationProvider.class);
Mockito.when(ldapAuthenticationProvider.authenticate(Mockito.any(Authentication.class))).thenReturn(authentication);
LdapManager mockLdapManager = Mockito.mock(LdapManager.class);
Mockito.when(mockLdapManager.isLdapEnabled()).thenReturn(true);
Mockito.when(mockLdapManager.getAuthenticationProvider()).thenThrow(new AlertConfigurationException("LDAP CONFIG EXCEPTION"));
DaoAuthenticationProvider databaseProvider = Mockito.mock(DaoAuthenticationProvider.class);
Mockito.when(databaseProvider.authenticate(Mockito.any(Authentication.class))).thenReturn(authentication);
AuthenticationEventManager authenticationEventManager = Mockito.mock(AuthenticationEventManager.class);
Mockito.doNothing().when(authenticationEventManager).sendAuthenticationEvent(Mockito.any(), Mockito.eq(AuthenticationType.LDAP));
RoleAccessor roleAccessor = Mockito.mock(RoleAccessor.class);
AlertDatabaseAuthenticationPerformer alertDatabaseAuthenticationPerformer = new AlertDatabaseAuthenticationPerformer(authenticationEventManager, roleAccessor, databaseProvider);
LdapAuthenticationPerformer ldapAuthenticationPerformer = new LdapAuthenticationPerformer(authenticationEventManager, roleAccessor, mockLdapManager);
AlertAuthenticationProvider authenticationProvider = new AlertAuthenticationProvider(List.of(ldapAuthenticationPerformer, alertDatabaseAuthenticationPerformer));
AuthenticationActions authenticationActions = new AuthenticationActions(authenticationProvider, csrfTokenRepository);
ActionResponse<Void> response = authenticationActions.authenticateUser(servletRequest, servletResponse, mockLoginRestModel.createRestModel());
assertTrue(response.isError());
Mockito.verify(databaseProvider).authenticate(Mockito.any(Authentication.class));
}
Aggregations