Search in sources :

Example 86 with NiFiProperties

use of org.apache.nifi.util.NiFiProperties in project nifi by apache.

the class TlsToolkitStandaloneTest method testKeyPasswordArg.

@Test
public void testKeyPasswordArg() throws Exception {
    String testKey = "testKey";
    runAndAssertExitCode(ExitCode.SUCCESS, "-o", tempDir.getAbsolutePath(), "-K", testKey, "-n", TlsConfig.DEFAULT_HOSTNAME);
    X509Certificate x509Certificate = checkLoadCertPrivateKey(TlsConfig.DEFAULT_KEY_PAIR_ALGORITHM);
    Properties nifiProperties = checkHostDirAndReturnNifiProperties(TlsConfig.DEFAULT_HOSTNAME, x509Certificate);
    assertEquals(testKey, nifiProperties.getProperty(NiFiProperties.SECURITY_KEY_PASSWD));
}
Also used : Properties(java.util.Properties) NiFiProperties(org.apache.nifi.util.NiFiProperties) X509Certificate(java.security.cert.X509Certificate) Test(org.junit.Test) TlsHelperTest(org.apache.nifi.toolkit.tls.util.TlsHelperTest) TlsCertificateAuthorityTest(org.apache.nifi.toolkit.tls.service.TlsCertificateAuthorityTest)

Example 87 with NiFiProperties

use of org.apache.nifi.util.NiFiProperties in project nifi by apache.

the class TlsToolkitStandaloneTest method testKeyStorePasswordArg.

@Test
public void testKeyStorePasswordArg() throws Exception {
    String testKeyStore = "testKeyStore";
    runAndAssertExitCode(ExitCode.SUCCESS, "-o", tempDir.getAbsolutePath(), "-S", testKeyStore, "-n", TlsConfig.DEFAULT_HOSTNAME);
    X509Certificate x509Certificate = checkLoadCertPrivateKey(TlsConfig.DEFAULT_KEY_PAIR_ALGORITHM);
    Properties nifiProperties = checkHostDirAndReturnNifiProperties(TlsConfig.DEFAULT_HOSTNAME, x509Certificate);
    assertEquals(testKeyStore, nifiProperties.getProperty(NiFiProperties.SECURITY_KEYSTORE_PASSWD));
}
Also used : Properties(java.util.Properties) NiFiProperties(org.apache.nifi.util.NiFiProperties) X509Certificate(java.security.cert.X509Certificate) Test(org.junit.Test) TlsHelperTest(org.apache.nifi.toolkit.tls.util.TlsHelperTest) TlsCertificateAuthorityTest(org.apache.nifi.toolkit.tls.service.TlsCertificateAuthorityTest)

Example 88 with NiFiProperties

use of org.apache.nifi.util.NiFiProperties in project nifi by apache.

the class FlowResource method getAboutInfo.

/**
 * Retrieves details about this NiFi to put in the About dialog.
 *
 * @return An aboutEntity.
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("about")
@ApiOperation(value = "Retrieves details about this NiFi to put in the About dialog", response = AboutEntity.class, authorizations = { @Authorization(value = "Read - /flow") })
@ApiResponses(value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") })
public Response getAboutInfo() {
    authorizeFlow();
    // create the about dto
    final AboutDTO aboutDTO = new AboutDTO();
    aboutDTO.setTitle("NiFi");
    aboutDTO.setUri(generateResourceUri());
    aboutDTO.setTimezone(new Date());
    // get the content viewer url
    final NiFiProperties properties = getProperties();
    aboutDTO.setContentViewerUrl(properties.getProperty(NiFiProperties.CONTENT_VIEWER_URL));
    final Bundle frameworkBundle = NarClassLoaders.getInstance().getFrameworkBundle();
    if (frameworkBundle != null) {
        final BundleDetails frameworkDetails = frameworkBundle.getBundleDetails();
        // set the version
        aboutDTO.setVersion(frameworkDetails.getCoordinate().getVersion());
        // Get build info
        aboutDTO.setBuildTag(frameworkDetails.getBuildTag());
        aboutDTO.setBuildRevision(frameworkDetails.getBuildRevision());
        aboutDTO.setBuildBranch(frameworkDetails.getBuildBranch());
        aboutDTO.setBuildTimestamp(frameworkDetails.getBuildTimestampDate());
    }
    // create the response entity
    final AboutEntity entity = new AboutEntity();
    entity.setAbout(aboutDTO);
    // generate the response
    return generateOkResponse(entity).build();
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) BundleDetails(org.apache.nifi.bundle.BundleDetails) Bundle(org.apache.nifi.bundle.Bundle) AboutEntity(org.apache.nifi.web.api.entity.AboutEntity) AboutDTO(org.apache.nifi.web.api.dto.AboutDTO) Date(java.util.Date) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 89 with NiFiProperties

use of org.apache.nifi.util.NiFiProperties in project nifi by apache.

the class KnoxAuthenticationFilter method attemptAuthentication.

@Override
public Authentication attemptAuthentication(final HttpServletRequest request) {
    // only support knox login when running securely
    if (!request.isSecure()) {
        return null;
    }
    // ensure knox sso support is enabled
    final NiFiProperties properties = getProperties();
    if (!properties.isKnoxSsoEnabled()) {
        return null;
    }
    // get the principal out of the user token
    final String knoxJwt = getJwtFromCookie(request, properties.getKnoxCookieName());
    // if there is no cookie, return null to attempt another authentication
    if (knoxJwt == null) {
        return null;
    } else {
        // otherwise create the authentication request token
        return new KnoxAuthenticationRequestToken(knoxJwt, request.getRemoteAddr());
    }
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties)

Example 90 with NiFiProperties

use of org.apache.nifi.util.NiFiProperties in project nifi by apache.

the class NiFiAuthenticationProviderTest method testPatternPropertyWithNoCorrespondingValueProperty.

@Test
public void testPatternPropertyWithNoCorrespondingValueProperty() {
    Properties properties = new Properties();
    properties.setProperty("nifi.security.identity.mapping.pattern.dn", "");
    final NiFiProperties nifiProperties = getNiFiProperties(properties);
    TestableNiFiAuthenticationProvider provider = new TestableNiFiAuthenticationProvider(nifiProperties);
    List<IdentityMapping> mappings = provider.getMappings();
    assertEquals(0, mappings.size());
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) IdentityMapping(org.apache.nifi.authorization.util.IdentityMapping) Properties(java.util.Properties) NiFiProperties(org.apache.nifi.util.NiFiProperties) Test(org.junit.Test)

Aggregations

NiFiProperties (org.apache.nifi.util.NiFiProperties)98 Test (org.junit.Test)63 HashMap (java.util.HashMap)28 Properties (java.util.Properties)24 File (java.io.File)16 Bundle (org.apache.nifi.bundle.Bundle)13 Matchers.anyString (org.mockito.Matchers.anyString)13 IOException (java.io.IOException)10 HashSet (java.util.HashSet)10 Map (java.util.Map)8 X509Certificate (java.security.cert.X509Certificate)7 Mockito.anyString (org.mockito.Mockito.anyString)7 InputStream (java.io.InputStream)6 ArrayList (java.util.ArrayList)6 SystemBundle (org.apache.nifi.nar.SystemBundle)6 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 IdentityMapping (org.apache.nifi.authorization.util.IdentityMapping)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 FileInputStream (java.io.FileInputStream)4