Search in sources :

Example 1 with Encryption

use of org.apache.karaf.jaas.modules.Encryption in project fabric8 by jboss-fuse.

the class ZookeeperLoginModule method checkPassword.

public boolean checkPassword(String plain, String encrypted) {
    Encryption encryption = encryptionSupport.getEncryption();
    String encryptionPrefix = encryptionSupport.getEncryptionPrefix();
    String encryptionSuffix = encryptionSupport.getEncryptionSuffix();
    if (encryption == null) {
        return plain.equals(encrypted);
    } else {
        boolean prefix = encryptionPrefix == null || encrypted.startsWith(encryptionPrefix);
        boolean suffix = encryptionSuffix == null || encrypted.endsWith(encryptionSuffix);
        if (prefix && suffix) {
            encrypted = encrypted.substring(encryptionPrefix != null ? encryptionPrefix.length() : 0, encrypted.length() - (encryptionSuffix != null ? encryptionSuffix.length() : 0));
            return encryption.checkPassword(plain, encrypted);
        } else {
            return plain.equals(encrypted);
        }
    }
}
Also used : Encryption(org.apache.karaf.jaas.modules.Encryption)

Example 2 with Encryption

use of org.apache.karaf.jaas.modules.Encryption in project karaf by apache.

the class AutoEncryptionSupport method getEncryptedPassword.

String getEncryptedPassword(String password) {
    Encryption encryption = encryptionSupport.getEncryption();
    String encryptionPrefix = encryptionSupport.getEncryptionPrefix();
    String encryptionSuffix = encryptionSupport.getEncryptionSuffix();
    if (encryption == null) {
        return password;
    } else {
        boolean prefix = encryptionPrefix == null || password.startsWith(encryptionPrefix);
        boolean suffix = encryptionSuffix == null || password.endsWith(encryptionSuffix);
        if (prefix && suffix) {
            return password;
        } else {
            String p = encryption.encryptPassword(password);
            if (encryptionPrefix != null) {
                p = encryptionPrefix + p;
            }
            if (encryptionSuffix != null) {
                p = p + encryptionSuffix;
            }
            return p;
        }
    }
}
Also used : Encryption(org.apache.karaf.jaas.modules.Encryption)

Example 3 with Encryption

use of org.apache.karaf.jaas.modules.Encryption in project fabric8 by jboss-fuse.

the class ZookeeperLoginModule method getEncryptedPassword.

public String getEncryptedPassword(String password) {
    Encryption encryption = encryptionSupport.getEncryption();
    String encryptionPrefix = encryptionSupport.getEncryptionPrefix();
    String encryptionSuffix = encryptionSupport.getEncryptionSuffix();
    if (encryption == null) {
        return password;
    } else {
        boolean prefix = encryptionPrefix == null || password.startsWith(encryptionPrefix);
        boolean suffix = encryptionSuffix == null || password.endsWith(encryptionSuffix);
        if (prefix && suffix) {
            return password;
        } else {
            String p = encryption.encryptPassword(password);
            if (encryptionPrefix != null) {
                p = encryptionPrefix + p;
            }
            if (encryptionSuffix != null) {
                p = p + encryptionSuffix;
            }
            return p;
        }
    }
}
Also used : Encryption(org.apache.karaf.jaas.modules.Encryption)

Example 4 with Encryption

use of org.apache.karaf.jaas.modules.Encryption in project fabric8 by jboss-fuse.

the class DataStoreBootstrapTemplate method addUsersToZookeeper.

/**
 * Adds users to the Zookeeper registry.
 */
private EncryptionSupport addUsersToZookeeper(CuratorFramework curator, Map<String, String> users) throws Exception {
    Pattern p = Pattern.compile("([^,]+),(.+)");
    Map<String, Object> options = new HashMap<String, Object>();
    options.put("encryption.prefix", "{CRYPT}");
    options.put("encryption.suffix", "{CRYPT}");
    options.put("encryption.enabled", "true");
    options.put("encryption.algorithm", "MD5");
    options.put("encryption.encoding", "hexadecimal");
    Encryption encryption = null;
    EncryptionSupport encryptionSupport = null;
    Bundle bundle = FrameworkUtil.getBundle(getClass());
    if (bundle != null) {
        options.put(BundleContext.class.getName(), bundle.getBundleContext());
        try {
            encryptionSupport = new EncryptionSupport(options);
            encryption = encryptionSupport.getEncryption();
        } catch (Exception e) {
        // Ignore
        }
    }
    StringBuilder sb = new StringBuilder();
    sb.append("\n");
    for (Map.Entry<String, String> entry : users.entrySet()) {
        String user = entry.getKey();
        Matcher m = p.matcher(entry.getValue());
        if (m.matches() && m.groupCount() >= 2) {
            String password = m.group(1).trim();
            if (encryptionSupport != null && encryption != null) {
                if (!password.startsWith(encryptionSupport.getEncryptionPrefix()) || !password.endsWith(encryptionSupport.getEncryptionSuffix())) {
                    password = encryptionSupport.getEncryptionPrefix() + encryption.encryptPassword(m.group(1)).trim() + encryptionSupport.getEncryptionSuffix();
                }
            }
            String roles = m.group(2).trim();
            sb.append(user).append("=").append(password).append(",").append(roles).append("\n");
        }
    }
    sb.append("_g_\\:admin=admin,admin,manager,viewer,Operator,Maintainer,Deployer,Auditor,Administrator,SuperUser\n");
    String allUsers = sb.toString();
    ZooKeeperUtils.createDefault(curator, "/fabric/authentication/users", allUsers);
    return encryptionSupport;
}
Also used : Pattern(java.util.regex.Pattern) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) Bundle(org.osgi.framework.Bundle) Encryption(org.apache.karaf.jaas.modules.Encryption) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) EncryptionSupport(org.apache.karaf.jaas.modules.encryption.EncryptionSupport) BundleContext(org.osgi.framework.BundleContext)

Aggregations

Encryption (org.apache.karaf.jaas.modules.Encryption)4 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 EncryptionSupport (org.apache.karaf.jaas.modules.encryption.EncryptionSupport)1 Bundle (org.osgi.framework.Bundle)1 BundleContext (org.osgi.framework.BundleContext)1