Search in sources :

Example 16 with AbstractUaaEvent

use of org.cloudfoundry.identity.uaa.audit.event.AbstractUaaEvent in project uaa by cloudfoundry.

the class AbstractLdapMockMvcTest method setUp.

@BeforeEach
void setUp(@Autowired WebApplicationContext webApplicationContext, @Autowired MockMvc mockMvc, @Autowired ConfigurableApplicationContext configurableApplicationContext, @Autowired JdbcScimUserProvisioning jdbcScimUserProvisioning, @Autowired LoggingAuditService loggingAuditService) throws Exception {
    this.webApplicationContext = webApplicationContext;
    this.mockMvc = mockMvc;
    this.jdbcScimUserProvisioning = jdbcScimUserProvisioning;
    this.loggingAuditService = loggingAuditService;
    String userId = new RandomValueStringGenerator().generate().toLowerCase();
    zone = MockMvcUtils.createZoneForInvites(getMockMvc(), getWebApplicationContext(), userId, REDIRECT_URI, IdentityZoneHolder.getCurrentZoneId());
    LdapIdentityProviderDefinition definition = new LdapIdentityProviderDefinition();
    definition.setLdapProfileFile("ldap/" + ldapProfile);
    definition.setLdapGroupFile("ldap/" + ldapGroup);
    definition.setMaxGroupSearchDepth(10);
    definition.setBaseUrl(getLdapOrLdapSBaseUrl());
    definition.setBindUserDn("cn=admin,ou=Users,dc=test,dc=com");
    definition.setBindPassword("adminsecret");
    definition.setSkipSSLVerification(false);
    definition.setTlsConfiguration(tlsConfig);
    definition.setMailAttributeName("mail");
    definition.setReferral("ignore");
    provider = MockMvcUtils.createIdentityProvider(getMockMvc(), zone.getZone(), LDAP, definition);
    host = zone.getZone().getIdentityZone().getSubdomain() + ".localhost";
    IdentityZoneHolder.clear();
    listener = (ApplicationListener<AbstractUaaEvent>) mock(ApplicationListener.class);
    configurableApplicationContext.addApplicationListener(listener);
    ensureLdapServerIsRunning();
    testLogger = new InterceptingLogger();
    originalAuditServiceLogger = loggingAuditService.getLogger();
    loggingAuditService.setLogger(testLogger);
}
Also used : AbstractUaaEvent(org.cloudfoundry.identity.uaa.audit.event.AbstractUaaEvent) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) InterceptingLogger(org.cloudfoundry.identity.uaa.mock.util.InterceptingLogger) LdapIdentityProviderDefinition(org.cloudfoundry.identity.uaa.provider.LdapIdentityProviderDefinition) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 17 with AbstractUaaEvent

use of org.cloudfoundry.identity.uaa.audit.event.AbstractUaaEvent in project uaa by cloudfoundry.

the class AbstractLdapMockMvcTest method testAuthenticateFailure.

@Test
void testAuthenticateFailure() throws Exception {
    String username = "marissa3";
    String password = "ldapsadadasas";
    MockHttpServletRequestBuilder post = post("/authenticate").header(HOST, host).accept(MediaType.APPLICATION_JSON).param("username", username).param("password", password);
    getMockMvc().perform(post).andExpect(status().isUnauthorized());
    ArgumentCaptor<AbstractUaaEvent> captor = ArgumentCaptor.forClass(AbstractUaaEvent.class);
    verify(listener, atLeast(5)).onApplicationEvent(captor.capture());
    List<AbstractUaaEvent> allValues = captor.getAllValues();
    assertThat(allValues.get(4), instanceOf(IdentityProviderAuthenticationFailureEvent.class));
    IdentityProviderAuthenticationFailureEvent event = (IdentityProviderAuthenticationFailureEvent) allValues.get(4);
    assertEquals("marissa3", event.getUsername());
    assertEquals(OriginKeys.LDAP, event.getAuthenticationType());
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) IdentityProviderAuthenticationFailureEvent(org.cloudfoundry.identity.uaa.authentication.event.IdentityProviderAuthenticationFailureEvent) AbstractUaaEvent(org.cloudfoundry.identity.uaa.audit.event.AbstractUaaEvent) Test(org.junit.jupiter.api.Test)

Aggregations

AbstractUaaEvent (org.cloudfoundry.identity.uaa.audit.event.AbstractUaaEvent)17 Test (org.junit.jupiter.api.Test)14 ResultActions (org.springframework.test.web.servlet.ResultActions)8 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)8 ClientDetails (org.springframework.security.oauth2.provider.ClientDetails)6 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)6 MockHttpSession (org.springframework.mock.web.MockHttpSession)5 BeforeEach (org.junit.jupiter.api.BeforeEach)4 MfaAuthenticationSuccessEvent (org.cloudfoundry.identity.uaa.authentication.event.MfaAuthenticationSuccessEvent)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 RandomValueStringGenerator (org.springframework.security.oauth2.common.util.RandomValueStringGenerator)3 MockMvcResultHandlers.print (org.springframework.test.web.servlet.result.MockMvcResultHandlers.print)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 DefaultTestContext (org.cloudfoundry.identity.uaa.DefaultTestContext)2 Approval (org.cloudfoundry.identity.uaa.approval.Approval)2 AuditEventType (org.cloudfoundry.identity.uaa.audit.AuditEventType)2 IdentityProviderAuthenticationFailureEvent (org.cloudfoundry.identity.uaa.authentication.event.IdentityProviderAuthenticationFailureEvent)2 InterceptingLogger (org.cloudfoundry.identity.uaa.mock.util.InterceptingLogger)2 MockMvcUtils (org.cloudfoundry.identity.uaa.mock.util.MockMvcUtils)2 MockMvcUtils.httpBearer (org.cloudfoundry.identity.uaa.mock.util.MockMvcUtils.httpBearer)2