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);
}
}
}
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;
}
}
}
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;
}
}
}
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;
}
Aggregations