Search in sources :

Example 6 with OtpAuthenticationToken

use of org.apache.nifi.web.security.token.OtpAuthenticationToken in project nifi by apache.

the class OtpServiceTest method testMaxUiExtensionTokenLimit.

@Test(expected = IllegalStateException.class)
public void testMaxUiExtensionTokenLimit() throws Exception {
    // ensure we'll try to loop past the limit
    for (int i = 1; i < OtpService.MAX_CACHE_SOFT_LIMIT + 10; i++) {
        try {
            final OtpAuthenticationToken authenticationToken = new OtpAuthenticationToken("user-identity-" + i);
            otpService.generateUiExtensionToken(authenticationToken);
        } catch (final IllegalStateException iae) {
            // ensure we failed when we've past the limit
            assertEquals(OtpService.MAX_CACHE_SOFT_LIMIT + 1, i);
            throw iae;
        }
    }
}
Also used : OtpAuthenticationToken(org.apache.nifi.web.security.token.OtpAuthenticationToken) Test(org.junit.Test)

Example 7 with OtpAuthenticationToken

use of org.apache.nifi.web.security.token.OtpAuthenticationToken in project nifi by apache.

the class OtpServiceTest method testUiExtensionTokenExpiration.

@Test(expected = OtpAuthenticationException.class)
public void testUiExtensionTokenExpiration() throws Exception {
    final OtpService otpServiceWithTightExpiration = new OtpService(2, TimeUnit.SECONDS);
    final OtpAuthenticationToken authenticationToken = new OtpAuthenticationToken(USER_1);
    final String downloadToken = otpServiceWithTightExpiration.generateUiExtensionToken(authenticationToken);
    // sleep for 4 seconds which should sufficiently expire the valid token
    Thread.sleep(4 * 1000);
    // attempt to get the token now that its expired
    otpServiceWithTightExpiration.getAuthenticationFromUiExtensionToken(downloadToken);
}
Also used : OtpAuthenticationToken(org.apache.nifi.web.security.token.OtpAuthenticationToken) Test(org.junit.Test)

Example 8 with OtpAuthenticationToken

use of org.apache.nifi.web.security.token.OtpAuthenticationToken in project nifi by apache.

the class OtpServiceTest method testMaxDownloadTokenLimit.

@Test(expected = IllegalStateException.class)
public void testMaxDownloadTokenLimit() throws Exception {
    // ensure we'll try to loop past the limit
    for (int i = 1; i < OtpService.MAX_CACHE_SOFT_LIMIT + 10; i++) {
        try {
            final OtpAuthenticationToken authenticationToken = new OtpAuthenticationToken("user-identity-" + i);
            otpService.generateDownloadToken(authenticationToken);
        } catch (final IllegalStateException iae) {
            // ensure we failed when we've past the limit
            assertEquals(OtpService.MAX_CACHE_SOFT_LIMIT + 1, i);
            throw iae;
        }
    }
}
Also used : OtpAuthenticationToken(org.apache.nifi.web.security.token.OtpAuthenticationToken) Test(org.junit.Test)

Aggregations

OtpAuthenticationToken (org.apache.nifi.web.security.token.OtpAuthenticationToken)8 Test (org.junit.Test)6 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 URI (java.net.URI)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 AccessDeniedException (org.apache.nifi.authorization.AccessDeniedException)2 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)2