Search in sources :

Example 1 with PasswordAuthHandlerInput

use of io.pravega.shared.security.auth.PasswordAuthHandlerInput in project pravega by pravega.

the class BatchClientAuthTest method createAuthFile.

private static File createAuthFile() {
    @SuppressWarnings("resource") PasswordAuthHandlerInput result = new PasswordAuthHandlerInput("BatchClientAuth", ".txt");
    StrongPasswordProcessor passwordProcessor = StrongPasswordProcessor.builder().build();
    try {
        String encryptedPassword = passwordProcessor.encryptPassword("1111_aaaa");
        List<PasswordAuthHandlerInput.Entry> entries = Arrays.asList(PasswordAuthHandlerInput.Entry.of("admin", encryptedPassword, "prn::*,READ_UPDATE;"), PasswordAuthHandlerInput.Entry.of("appaccount", encryptedPassword, "prn::*,READ_UPDATE;"), PasswordAuthHandlerInput.Entry.of("unauthorizeduser", encryptedPassword, "prn::"));
        result.postEntries(entries);
    } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
        throw new RuntimeException(e);
    }
    return result.getFile();
}
Also used : StrongPasswordProcessor(io.pravega.shared.security.crypto.StrongPasswordProcessor) StatusRuntimeException(io.grpc.StatusRuntimeException) PasswordAuthHandlerInput(io.pravega.shared.security.auth.PasswordAuthHandlerInput) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException)

Example 2 with PasswordAuthHandlerInput

use of io.pravega.shared.security.auth.PasswordAuthHandlerInput 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)

Example 3 with PasswordAuthHandlerInput

use of io.pravega.shared.security.auth.PasswordAuthHandlerInput in project pravega by pravega.

the class ClusterWrapper method createAuthFile.

private File createAuthFile(List<PasswordAuthHandlerInput.Entry> entries) {
    PasswordAuthHandlerInput result = new PasswordAuthHandlerInput(UUID.randomUUID().toString(), ".txt");
    result.postEntries(entries);
    log.debug("Posted entries to [{}] file", result.getFile().getPath());
    return result.getFile();
}
Also used : PasswordAuthHandlerInput(io.pravega.shared.security.auth.PasswordAuthHandlerInput)

Aggregations

PasswordAuthHandlerInput (io.pravega.shared.security.auth.PasswordAuthHandlerInput)3 StatusRuntimeException (io.grpc.StatusRuntimeException)1 ServerConfig (io.pravega.auth.ServerConfig)1 StrongPasswordProcessor (io.pravega.shared.security.crypto.StrongPasswordProcessor)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)1 Properties (java.util.Properties)1 SneakyThrows (lombok.SneakyThrows)1 Test (org.junit.Test)1