Java Code Examples for org.apache.nifi.util.StringUtils#EMPTY

The following examples show how to use org.apache.nifi.util.StringUtils#EMPTY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NiFiAnonymousAuthenticationProviderTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testAnonymousDisabledNotSecure() throws Exception {
    final NiFiProperties nifiProperties = Mockito.mock(NiFiProperties.class);
    when(nifiProperties.isAnonymousAuthenticationAllowed()).thenReturn(false);

    final NiFiAnonymousAuthenticationProvider anonymousAuthenticationProvider = new NiFiAnonymousAuthenticationProvider(nifiProperties, mock(Authorizer.class));

    final NiFiAnonymousAuthenticationRequestToken authenticationRequest = new NiFiAnonymousAuthenticationRequestToken(false, StringUtils.EMPTY);

    final NiFiAuthenticationToken authentication = (NiFiAuthenticationToken) anonymousAuthenticationProvider.authenticate(authenticationRequest);
    final NiFiUserDetails userDetails = (NiFiUserDetails) authentication.getDetails();
    assertTrue(userDetails.getNiFiUser().isAnonymous());
}
 
Example 2
Source File: NiFiAnonymousAuthenticationProviderTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testAnonymousEnabledNotSecure() throws Exception {
    final NiFiProperties nifiProperties = Mockito.mock(NiFiProperties.class);
    when(nifiProperties.isAnonymousAuthenticationAllowed()).thenReturn(true);

    final NiFiAnonymousAuthenticationProvider anonymousAuthenticationProvider = new NiFiAnonymousAuthenticationProvider(nifiProperties, mock(Authorizer.class));

    final NiFiAnonymousAuthenticationRequestToken authenticationRequest = new NiFiAnonymousAuthenticationRequestToken(false, StringUtils.EMPTY);

    final NiFiAuthenticationToken authentication = (NiFiAuthenticationToken) anonymousAuthenticationProvider.authenticate(authenticationRequest);
    final NiFiUserDetails userDetails = (NiFiUserDetails) authentication.getDetails();
    assertTrue(userDetails.getNiFiUser().isAnonymous());
}
 
Example 3
Source File: NiFiAnonymousAuthenticationProviderTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test(expected = InvalidAuthenticationException.class)
public void testAnonymousDisabledSecure() throws Exception {
    final NiFiProperties nifiProperties = Mockito.mock(NiFiProperties.class);
    when(nifiProperties.isAnonymousAuthenticationAllowed()).thenReturn(false);

    final NiFiAnonymousAuthenticationProvider anonymousAuthenticationProvider = new NiFiAnonymousAuthenticationProvider(nifiProperties, mock(Authorizer.class));

    final NiFiAnonymousAuthenticationRequestToken authenticationRequest = new NiFiAnonymousAuthenticationRequestToken(true, StringUtils.EMPTY);

    anonymousAuthenticationProvider.authenticate(authenticationRequest);
}
 
Example 4
Source File: NiFiAnonymousAuthenticationProviderTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testAnonymousEnabledSecure() throws Exception {
    final NiFiProperties nifiProperties = Mockito.mock(NiFiProperties.class);
    when(nifiProperties.isAnonymousAuthenticationAllowed()).thenReturn(true);

    final NiFiAnonymousAuthenticationProvider anonymousAuthenticationProvider = new NiFiAnonymousAuthenticationProvider(nifiProperties, mock(Authorizer.class));

    final NiFiAnonymousAuthenticationRequestToken authenticationRequest = new NiFiAnonymousAuthenticationRequestToken(true, StringUtils.EMPTY);

    final NiFiAuthenticationToken authentication = (NiFiAuthenticationToken) anonymousAuthenticationProvider.authenticate(authenticationRequest);
    final NiFiUserDetails userDetails = (NiFiUserDetails) authentication.getDetails();
    assertTrue(userDetails.getNiFiUser().isAnonymous());
}
 
Example 5
Source File: AccessControlHelper.java    From nifi with Apache License 2.0 4 votes vote down vote up
public AccessControlHelper(final String nifiPropertiesPath) throws Exception {
    // configure the location of the nifi properties
    File nifiPropertiesFile = new File(nifiPropertiesPath);
    System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, nifiPropertiesFile.getAbsolutePath());
    NiFiProperties props = NiFiProperties.createBasicNiFiProperties(null);
    flowXmlPath = props.getProperty(NiFiProperties.FLOW_CONFIGURATION_FILE);

    final File libTargetDir = new File("target/test-classes/access-control/lib");
    libTargetDir.mkdirs();

    final File libSourceDir = new File("src/test/resources/lib");
    for (final File libFile : libSourceDir.listFiles()) {
        final File libDestFile = new File(libTargetDir, libFile.getName());
        Files.copy(libFile.toPath(), libDestFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
    }

    final Bundle systemBundle = SystemBundle.create(props);
    NarUnpacker.unpackNars(props, systemBundle);
    NarClassLoadersHolder.getInstance().init(props.getFrameworkWorkingDirectory(), props.getExtensionsWorkingDirectory());

    // load extensions
    final ExtensionDiscoveringManager extensionManager = new StandardExtensionDiscoveringManager();
    extensionManager.discoverExtensions(systemBundle, NarClassLoadersHolder.getInstance().getBundles());
    ExtensionManagerHolder.init(extensionManager);

    // start the server
    server = new NiFiTestServer("src/main/webapp", CONTEXT_PATH, props);
    server.startServer();
    server.loadFlow();

    // get the base url
    baseUrl = server.getBaseUrl() + CONTEXT_PATH;

    // create the users - user purposefully decoupled from clientId (same user different browsers tabs)
    readUser = new NiFiTestUser(server.getClient(), NiFiTestAuthorizer.READ_USER_DN);
    writeUser = new NiFiTestUser(server.getClient(), NiFiTestAuthorizer.WRITE_USER_DN);
    readWriteUser = new NiFiTestUser(server.getClient(), NiFiTestAuthorizer.READ_WRITE_USER_DN);
    noneUser = new NiFiTestUser(server.getClient(), NiFiTestAuthorizer.NONE_USER_DN);
    privilegedUser = new NiFiTestUser(server.getClient(), NiFiTestAuthorizer.PRIVILEGED_USER_DN);
    executeCodeUser = new NiFiTestUser(server.getClient(), NiFiTestAuthorizer.EXECUTED_CODE_USER_DN);
    anonymousUser = new NiFiTestUser(server.getClient(), StringUtils.EMPTY);

    // populate the initial data flow
    NiFiWebApiTest.populateFlow(server.getClient(), baseUrl, readWriteUser, READ_WRITE_CLIENT_ID);
}