use of com.tremolosecurity.saml.Attribute in project OpenUnison by TremoloSecurity.
the class LoadToken method loadToken.
@Override
public Object loadToken(AuthInfo user, HttpSession session) throws Exception {
HashMap<String, String> token = new HashMap<String, String>();
Attribute attr = user.getAttribs().get(this.attributeName);
if (attr != null) {
String json = attr.getValues().get(0);
Gson gson = new Gson();
EncryptedMessage em = gson.fromJson(json, EncryptedMessage.class);
SecretKey key = GlobalEntries.getGlobalEntries().getConfigManager().getSecretKey(this.encryptionKey);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
IvParameterSpec spec = new IvParameterSpec(em.getIv());
cipher.init(Cipher.DECRYPT_MODE, key, spec);
byte[] bytes = cipher.doFinal(em.getMsg());
String password = new String(bytes);
token.put("Temporary Password", password);
} else {
token.put("Temporary Password", "No password found");
}
return token;
}
use of com.tremolosecurity.saml.Attribute in project OpenUnison by TremoloSecurity.
the class LoadToken method loadAttributeValue.
private String loadAttributeValue(String name, String label, HttpFilterConfig config) throws Exception {
Attribute attr = config.getAttribute(name);
if (attr == null) {
throw new Exception(label + " not found");
}
String val = attr.getValues().get(0);
logger.info(label + ": '" + val + "'");
return val;
}
use of com.tremolosecurity.saml.Attribute in project OpenUnison by TremoloSecurity.
the class AuthInfo method createLDAPEntry.
public LDAPEntry createLDAPEntry() {
LDAPAttributeSet attrs = new LDAPAttributeSet();
for (String name : this.attribs.keySet()) {
Attribute attr = this.attribs.get(name);
LDAPAttribute ldap = new LDAPAttribute(name);
for (String val : attr.getValues()) {
ldap.addValue(val);
}
attrs.add(ldap);
}
LDAPEntry entry = new LDAPEntry(this.userDN, attrs);
return entry;
}
use of com.tremolosecurity.saml.Attribute in project OpenUnison by TremoloSecurity.
the class ADProvider method doFindUser.
private User doFindUser(String userID, Set<String> attributes, StringBuffer filter, LDAPConnection con) throws LDAPException {
boolean externalUser = false;
LDAPSearchResults res = con.search(searchBase, 2, filter.toString(), this.toStringArray(attributes), false);
LDAPEntry ldapUser = null;
if (!res.hasMore()) {
ldapUser = getMyVDUser(filter);
if (ldapUser == null) {
return null;
} else {
externalUser = true;
}
} else {
try {
ldapUser = res.next();
while (res.hasMore()) res.next();
} catch (LDAPReferralException e) {
}
if (ldapUser == null) {
ldapUser = getMyVDUser(filter);
if (ldapUser == null) {
return null;
} else {
externalUser = true;
}
}
}
User user = new User(userID);
Iterator<LDAPAttribute> it = ldapUser.getAttributeSet().iterator();
while (it.hasNext()) {
LDAPAttribute attr = it.next();
Attribute userAttr = new Attribute(attr.getName());
String[] vals = attr.getStringValueArray();
for (int i = 0; i < vals.length; i++) {
userAttr.getValues().add(vals[i]);
}
user.getAttribs().put(userAttr.getName(), userAttr);
}
if (externalUser) {
/*if (ldapf.contains("\\,")) {
ldapf = ldapf.replaceAll("\\\\\\\\,","\\5C,");
} */
// ldapf = this.adEscape(ldapf);
res = con.search(searchBase, 2, equal(this.externalGroupAttr, ldapUser.getDN()).toString(), new String[] { "cn" }, false);
while (res.hasMore()) {
LDAPEntry group = null;
try {
group = res.next();
} catch (LDAPReferralException e) {
continue;
}
user.getGroups().add(group.getAttribute("cn").getStringValue());
}
} else {
StringBuffer f = new StringBuffer();
String ldapf = equal("member", ldapUser.getDN()).toString();
/*if (ldapf.contains("\\,")) {
ldapf = ldapf.replaceAll("[\\\\][,]","\\\\5C,");
} */
// ldapf = this.adEscape(ldapf);
res = con.search(searchBase, 2, ldapf, new String[] { "cn" }, false);
while (res.hasMore()) {
LDAPEntry group = null;
try {
group = res.next();
} catch (LDAPReferralException e) {
continue;
}
user.getGroups().add(group.getAttribute("cn").getStringValue());
}
}
return user;
}
use of com.tremolosecurity.saml.Attribute in project OpenUnison by TremoloSecurity.
the class ADProvider method createUser.
@Override
public void createUser(User user, Set<String> attributes, Map<String, Object> request) throws ProvisioningException {
String dn = this.getDN(user);
LDAPAttributeSet attrs = new LDAPAttributeSet();
attrs.add(new LDAPAttribute("objectClass", this.objectClass));
Iterator<String> userAttrs = user.getAttribs().keySet().iterator();
while (userAttrs.hasNext()) {
String attrName = userAttrs.next();
if (!attributes.contains(attrName)) {
continue;
} else if (attrName.equalsIgnoreCase("userAccountControl") && request.containsKey(ProvisioningUtil.SET_PASSWORD)) {
// we need set this AFTER the password
continue;
}
LDAPAttribute ldap = new LDAPAttribute(attrName);
Attribute attr = user.getAttribs().get(attrName);
Iterator<String> vals = attr.getValues().iterator();
while (vals.hasNext()) {
ldap.addValue(vals.next());
}
attrs.add(ldap);
}
LdapConnection con;
try {
con = this.ldapPool.getConnection();
} catch (Exception e) {
StringBuffer b = new StringBuffer();
b.append("Could not get LDAP connection ").append(user.getUserID());
throw new ProvisioningException(b.toString(), e);
}
try {
doCreate(user, dn, attrs, con.getConnection(), request);
} finally {
con.returnCon();
}
}
Aggregations