Search in sources :

Example 16 with Attribute

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;
}
Also used : SecretKey(javax.crypto.SecretKey) HashMap(java.util.HashMap) Attribute(com.tremolosecurity.saml.Attribute) EncryptedMessage(com.tremolosecurity.provisioning.util.EncryptedMessage) Gson(com.google.gson.Gson) IvParameterSpec(javax.crypto.spec.IvParameterSpec) Cipher(javax.crypto.Cipher)

Example 17 with Attribute

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;
}
Also used : Attribute(com.tremolosecurity.saml.Attribute)

Example 18 with Attribute

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;
}
Also used : LDAPAttribute(com.novell.ldap.LDAPAttribute) LDAPEntry(com.novell.ldap.LDAPEntry) Attribute(com.tremolosecurity.saml.Attribute) LDAPAttribute(com.novell.ldap.LDAPAttribute) LDAPAttributeSet(com.novell.ldap.LDAPAttributeSet)

Example 19 with Attribute

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;
}
Also used : LDAPReferralException(com.novell.ldap.LDAPReferralException) LDAPAttribute(com.novell.ldap.LDAPAttribute) LDAPEntry(com.novell.ldap.LDAPEntry) LDAPSearchResults(com.novell.ldap.LDAPSearchResults) User(com.tremolosecurity.provisioning.core.User) LDAPAttribute(com.novell.ldap.LDAPAttribute) Attribute(com.tremolosecurity.saml.Attribute)

Example 20 with Attribute

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();
    }
}
Also used : LDAPAttribute(com.novell.ldap.LDAPAttribute) LDAPAttribute(com.novell.ldap.LDAPAttribute) Attribute(com.tremolosecurity.saml.Attribute) LDAPAttributeSet(com.novell.ldap.LDAPAttributeSet) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) LDAPException(com.novell.ldap.LDAPException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LDAPReferralException(com.novell.ldap.LDAPReferralException) LdapConnection(com.tremolosecurity.provisioning.util.ldap.pool.LdapConnection)

Aggregations

Attribute (com.tremolosecurity.saml.Attribute)268 LDAPAttribute (com.novell.ldap.LDAPAttribute)90 HashMap (java.util.HashMap)89 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)87 IOException (java.io.IOException)69 ArrayList (java.util.ArrayList)53 LDAPException (com.novell.ldap.LDAPException)51 ServletException (javax.servlet.ServletException)48 AuthInfo (com.tremolosecurity.proxy.auth.AuthInfo)46 AuthController (com.tremolosecurity.proxy.auth.AuthController)45 LDAPEntry (com.novell.ldap.LDAPEntry)43 LDAPSearchResults (com.novell.ldap.LDAPSearchResults)43 HttpSession (javax.servlet.http.HttpSession)40 Gson (com.google.gson.Gson)35 User (com.tremolosecurity.provisioning.core.User)33 HttpServletRequest (javax.servlet.http.HttpServletRequest)33 UrlHolder (com.tremolosecurity.config.util.UrlHolder)31 UnsupportedEncodingException (java.io.UnsupportedEncodingException)30 AuthChainType (com.tremolosecurity.config.xml.AuthChainType)28 HashSet (java.util.HashSet)26