Search in sources :

Example 1 with ServerConfig

use of io.pravega.auth.ServerConfig in project pravega by pravega.

the class PasswordAuthHandlerTest method initializeFailsIfAccountFileConfigMissing.

@Test(expected = CompletionException.class)
public void initializeFailsIfAccountFileConfigMissing() {
    PasswordAuthHandler authHandler = new PasswordAuthHandler();
    ServerConfig serverConfig = new ServerConfig() {

        @Override
        public Properties toAuthHandlerProperties() {
            Properties props = new Properties();
            props.setProperty(AuthPluginConfig.BASIC_AUTHPLUGIN_DATABASE, "/random/file");
            return props;
        }
    };
    authHandler.initialize(serverConfig);
}
Also used : ServerConfig(io.pravega.auth.ServerConfig) Properties(java.util.Properties) Test(org.junit.Test)

Example 2 with ServerConfig

use of io.pravega.auth.ServerConfig in project pravega by pravega.

the class PasswordAuthHandlerTest method initializeFailsIfPropertiesIsNull.

// region Tests verifying authentication
@Test
public void initializeFailsIfPropertiesIsNull() {
    PasswordAuthHandler objectUnderTest = new PasswordAuthHandler();
    AssertExtensions.assertThrows(NullPointerException.class, () -> {
        // Declaration is necessary to avoid ambiguity of the following call.
        Properties props = null;
        objectUnderTest.initialize(props);
    });
    AssertExtensions.assertThrows(NullPointerException.class, () -> {
        // Declaration is necessary to avoid ambiguity of the following call.
        ServerConfig serverConfig = null;
        objectUnderTest.initialize(serverConfig);
    });
}
Also used : ServerConfig(io.pravega.auth.ServerConfig) Properties(java.util.Properties) Test(org.junit.Test)

Example 3 with ServerConfig

use of io.pravega.auth.ServerConfig in project pravega by pravega.

the class PasswordAuthHandlerTest method initializeWorksWithValidAclsAndComments.

@SneakyThrows
@Test
public void initializeWorksWithValidAclsAndComments() {
    PasswordAuthHandler authHandler = new PasswordAuthHandler();
    try (PasswordAuthHandlerInput pwdInputFile = new PasswordAuthHandlerInput("PasswordAuthHandlerTest.init", ".txt")) {
        String encryptedPassword = StrongPasswordProcessor.builder().build().encryptPassword("some_password");
        List<PasswordAuthHandlerInput.Entry> entries = Arrays.asList(PasswordAuthHandlerInput.Entry.of("admin", encryptedPassword, "prn::*,READ_UPDATE;"), PasswordAuthHandlerInput.Entry.of("appaccount", encryptedPassword, "prn::/scope:scope1,READ_UPDATE;"), PasswordAuthHandlerInput.Entry.of("#commented", encryptedPassword, "prn::"));
        pwdInputFile.postEntries(entries);
        authHandler.initialize(new ServerConfig() {

            @Override
            public Properties toAuthHandlerProperties() {
                Properties props = new Properties();
                props.setProperty(AuthPluginConfig.BASIC_AUTHPLUGIN_DATABASE, pwdInputFile.getFile().getAbsolutePath());
                return props;
            }
        });
        ConcurrentHashMap<String, AccessControlList> aclsByUser = authHandler.getAclsByUser();
        assertEquals(2, aclsByUser.size());
        assertTrue(aclsByUser.containsKey("admin"));
        assertEquals("prn::/scope:scope1", aclsByUser.get("appaccount").getEntries().get(0).getResourcePattern());
        assertFalse(aclsByUser.containsKey("unauthorizeduser"));
    }
}
Also used : ServerConfig(io.pravega.auth.ServerConfig) PasswordAuthHandlerInput(io.pravega.shared.security.auth.PasswordAuthHandlerInput) Properties(java.util.Properties) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Aggregations

ServerConfig (io.pravega.auth.ServerConfig)3 Properties (java.util.Properties)3 Test (org.junit.Test)3 PasswordAuthHandlerInput (io.pravega.shared.security.auth.PasswordAuthHandlerInput)1 SneakyThrows (lombok.SneakyThrows)1