Search in sources :

Example 6 with AccepttoMultifactorAuthenticationProperties

use of org.apereo.cas.configuration.model.support.mfa.AccepttoMultifactorAuthenticationProperties in project cas by apereo.

the class AccepttoApiUtilsTests method verifyEmail.

@Test
public void verifyEmail() {
    val authentication = CoreAuthenticationTestUtils.getAuthentication(CoreAuthenticationTestUtils.getPrincipal(Map.of("email", List.of("cas@example.org"))));
    val properties = new AccepttoMultifactorAuthenticationProperties();
    properties.setEmailAttribute("email");
    assertNotNull(AccepttoApiUtils.getUserEmail(authentication, properties));
}
Also used : lombok.val(lombok.val) AccepttoMultifactorAuthenticationProperties(org.apereo.cas.configuration.model.support.mfa.AccepttoMultifactorAuthenticationProperties) Test(org.junit.jupiter.api.Test)

Example 7 with AccepttoMultifactorAuthenticationProperties

use of org.apereo.cas.configuration.model.support.mfa.AccepttoMultifactorAuthenticationProperties in project cas by apereo.

the class AccepttoApiUtilsTests method verifyUserValid.

@Test
public void verifyUserValid() throws Exception {
    val properties = new AccepttoMultifactorAuthenticationProperties();
    properties.setGroupAttribute("group");
    properties.setEmailAttribute("email");
    properties.setApplicationId("appid");
    properties.setSecret("p@$$w0rd");
    properties.setApiUrl("http://localhost:9289");
    val principal = CoreAuthenticationTestUtils.getPrincipal(Map.of("email", List.of("cas@example.org"), "group", List.of("staff")));
    val authentication = CoreAuthenticationTestUtils.getAuthentication(principal);
    val data = MAPPER.writeValueAsString(Map.of("device_paired", "true"));
    try (val webServer = new MockWebServer(9289, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
        webServer.start();
        val user = AccepttoApiUtils.isUserValid(authentication, properties);
        assertFalse(user.isEmpty());
    }
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) AccepttoMultifactorAuthenticationProperties(org.apereo.cas.configuration.model.support.mfa.AccepttoMultifactorAuthenticationProperties) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test)

Example 8 with AccepttoMultifactorAuthenticationProperties

use of org.apereo.cas.configuration.model.support.mfa.AccepttoMultifactorAuthenticationProperties in project cas by apereo.

the class AccepttoApiUtilsTests method verifyUserDevicePaired.

@Test
public void verifyUserDevicePaired() throws Exception {
    val properties = new AccepttoMultifactorAuthenticationProperties();
    properties.setGroupAttribute("group");
    properties.setEmailAttribute("email");
    properties.setApplicationId("appid");
    properties.setSecret("p@$$w0rd");
    properties.setApiUrl("http://localhost:9288");
    val principal = CoreAuthenticationTestUtils.getPrincipal(Map.of("email", List.of("cas@example.org"), "group", List.of("staff")));
    val authentication = CoreAuthenticationTestUtils.getAuthentication(principal);
    val data = MAPPER.writeValueAsString(Map.of("device_paired", "true"));
    try (val webServer = new MockWebServer(9288, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
        webServer.start();
        assertTrue(AccepttoApiUtils.isUserDevicePaired(authentication, properties));
    }
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) AccepttoMultifactorAuthenticationProperties(org.apereo.cas.configuration.model.support.mfa.AccepttoMultifactorAuthenticationProperties) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)8 AccepttoMultifactorAuthenticationProperties (org.apereo.cas.configuration.model.support.mfa.AccepttoMultifactorAuthenticationProperties)8 Test (org.junit.jupiter.api.Test)8 MockWebServer (org.apereo.cas.util.MockWebServer)4 ByteArrayResource (org.springframework.core.io.ByteArrayResource)4 Cookie (javax.servlet.http.Cookie)1 MockServletContext (org.apereo.cas.util.MockServletContext)1 ClientInfo (org.apereo.inspektr.common.web.ClientInfo)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)1 MockRequestContext (org.springframework.webflow.test.MockRequestContext)1