Search in sources :

Example 1 with AccepttoMultifactorAuthenticationProperties

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

the class AccepttoApiUtilsTests method verifyUserInvalidData.

@Test
public void verifyUserInvalidData() 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("__.. ..___$$$@@@");
    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);
        assertTrue(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 2 with AccepttoMultifactorAuthenticationProperties

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

the class AccepttoApiUtilsTests method verifyGroup.

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

Example 3 with AccepttoMultifactorAuthenticationProperties

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

the class AccepttoApiUtilsTests method verifyInvalidUser.

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

Example 4 with AccepttoMultifactorAuthenticationProperties

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

the class AccepttoApiUtilsTests method verifyAuthenticate.

@Test
public void verifyAuthenticate() throws Exception {
    val properties = new AccepttoMultifactorAuthenticationProperties();
    properties.setGroupAttribute("group");
    properties.setEmailAttribute("email");
    properties.setApplicationId("appid");
    properties.setSecret("p@$$w0rd");
    properties.setRegistrationApiUrl("http://localhost:9285");
    properties.setOrganizationId("org-id");
    properties.setOrganizationSecret("255724611137f7eb0280dd76b0546eea4bca1c7ba1");
    val principal = CoreAuthenticationTestUtils.getPrincipal(Map.of("email", List.of("cas@example.org"), "group", List.of("staff")));
    val authentication = CoreAuthenticationTestUtils.getAuthentication(principal);
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    request.setRemoteAddr("185.86.151.11");
    request.setLocalAddr("185.88.151.11");
    request.setCookies(new Cookie("jwt", UUID.randomUUID().toString()));
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    AccepttoWebflowUtils.setEGuardianUserId(context, "eguardian-userid");
    WebUtils.putCredential(context, new AccepttoEmailCredential("cas@example.org"));
    val keyGen = KeyPairGenerator.getInstance("RSA");
    val pair = keyGen.generateKeyPair();
    val priv = pair.getPrivate();
    val pub = pair.getPublic();
    val payload = MAPPER.writeValueAsString(Map.of("uid", "casuser"));
    val jwt = EncodingUtils.signJwsRSASha512(priv, payload.getBytes(StandardCharsets.UTF_8), Map.of());
    var data = MAPPER.writeValueAsString(Map.of("content", new String(jwt, StandardCharsets.UTF_8)));
    try (val webServer = new MockWebServer(9285, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
        webServer.start();
        val results = AccepttoApiUtils.authenticate(authentication, properties, context, pub);
        assertNotNull(results);
    }
    try (val webServer = new MockWebServer(9285, new ByteArrayResource(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
        webServer.start();
        val results = AccepttoApiUtils.authenticate(authentication, properties, context, pub);
        assertTrue(results.isEmpty());
    }
}
Also used : lombok.val(lombok.val) Cookie(javax.servlet.http.Cookie) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) AccepttoMultifactorAuthenticationProperties(org.apereo.cas.configuration.model.support.mfa.AccepttoMultifactorAuthenticationProperties) MockRequestContext(org.springframework.webflow.test.MockRequestContext) ByteArrayResource(org.springframework.core.io.ByteArrayResource) MockServletContext(org.apereo.cas.util.MockServletContext) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockWebServer(org.apereo.cas.util.MockWebServer) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 5 with AccepttoMultifactorAuthenticationProperties

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

the class AccepttoApiUtilsTests method verifyQR.

@Test
public void verifyQR() 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 hash = AccepttoApiUtils.generateQRCodeHash(authentication, properties, UUID.randomUUID().toString());
    assertNotNull(hash);
    assertNotNull(AccepttoApiUtils.decodeInvitationToken(hash));
}
Also used : lombok.val(lombok.val) AccepttoMultifactorAuthenticationProperties(org.apereo.cas.configuration.model.support.mfa.AccepttoMultifactorAuthenticationProperties) 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