Search in sources :

Example 6 with StrongPasswordProcessor

use of io.pravega.shared.security.crypto.StrongPasswordProcessor in project pravega by pravega.

the class ControllerGrpcListStreamsTest method preparePasswordInputFileEntries.

// region Private methods
private List<PasswordAuthHandlerInput.Entry> preparePasswordInputFileEntries(Map<String, String> entries) {
    StrongPasswordProcessor passwordProcessor = StrongPasswordProcessor.builder().build();
    try {
        String encryptedPassword = passwordProcessor.encryptPassword("1111_aaaa");
        List<PasswordAuthHandlerInput.Entry> result = new ArrayList<>();
        entries.forEach((k, v) -> result.add(PasswordAuthHandlerInput.Entry.of(k, encryptedPassword, v)));
        return result;
    } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
        throw new RuntimeException(e);
    }
}
Also used : StrongPasswordProcessor(io.pravega.shared.security.crypto.StrongPasswordProcessor) ArrayList(java.util.ArrayList) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException)

Example 7 with StrongPasswordProcessor

use of io.pravega.shared.security.crypto.StrongPasswordProcessor in project pravega by pravega.

the class StrongPasswordProcessorTest method checkPassword.

@Test
public void checkPassword() throws InvalidKeySpecException, NoSuchAlgorithmException {
    StrongPasswordProcessor processor = StrongPasswordProcessor.builder().iterations(5000).build();
    String encrypted = processor.encryptPassword("1111_aaaa");
    StrongPasswordProcessor secondProcessor = StrongPasswordProcessor.builder().iterations(5000).build();
    secondProcessor.checkPassword("1111_aaaa".toCharArray(), encrypted);
    StrongPasswordProcessor failingProcessor = StrongPasswordProcessor.builder().iterations(1000).build();
    Assert.assertTrue("Passwords with different iterations should not match", !encrypted.equals(failingProcessor.encryptPassword("1111_aaaa")));
}
Also used : StrongPasswordProcessor(io.pravega.shared.security.crypto.StrongPasswordProcessor) Test(org.junit.Test)

Example 8 with StrongPasswordProcessor

use of io.pravega.shared.security.crypto.StrongPasswordProcessor in project pravega by pravega.

the class PasswordEncryptorTool method main.

public static void main(String[] args) throws InvalidKeySpecException, NoSuchAlgorithmException {
    String userName = args[0];
    String userPassword = args[1];
    StrongPasswordProcessor passwordEncryptor = StrongPasswordProcessor.builder().build();
    String encryptedPassword = passwordEncryptor.encryptPassword(userPassword);
    System.out.println(encryptedPassword);
}
Also used : StrongPasswordProcessor(io.pravega.shared.security.crypto.StrongPasswordProcessor)

Example 9 with StrongPasswordProcessor

use of io.pravega.shared.security.crypto.StrongPasswordProcessor in project pravega by pravega.

the class PasswordValidatorTool method main.

public static void main(String[] args) throws InvalidKeySpecException, NoSuchAlgorithmException {
    String userName = args[0];
    String userPassword = args[1];
    String encryptedPassword = args[2];
    StrongPasswordProcessor passwordEncryptor = StrongPasswordProcessor.builder().build();
    System.out.println(passwordEncryptor.checkPassword(userPassword.toCharArray(), encryptedPassword));
}
Also used : StrongPasswordProcessor(io.pravega.shared.security.crypto.StrongPasswordProcessor)

Example 10 with StrongPasswordProcessor

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

Aggregations

StrongPasswordProcessor (io.pravega.shared.security.crypto.StrongPasswordProcessor)10 FileWriter (java.io.FileWriter)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)3 StatusRuntimeException (io.grpc.StatusRuntimeException)2 AuthFileUtils.credentialsAndAclAsString (io.pravega.auth.AuthFileUtils.credentialsAndAclAsString)2 AuthHandlerManager (io.pravega.shared.rest.security.AuthHandlerManager)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 SocketConnectionFactoryImpl (io.pravega.client.connection.impl.SocketConnectionFactoryImpl)1 ControllerService (io.pravega.controller.server.ControllerService)1 LocalController (io.pravega.controller.server.eventProcessor.LocalController)1 StreamMetadataResourceImpl (io.pravega.controller.server.rest.resources.StreamMetadataResourceImpl)1 RESTServer (io.pravega.shared.rest.RESTServer)1 PasswordAuthHandlerInput (io.pravega.shared.security.auth.PasswordAuthHandlerInput)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 SneakyThrows (lombok.SneakyThrows)1 Before (org.junit.Before)1