Search in sources :

Example 6 with AzException

use of com.tremolosecurity.proxy.az.AzException in project OpenUnison by TremoloSecurity.

the class FreeIPAAz method listPossibleApprovers.

@Override
public List<String> listPossibleApprovers(String... params) throws AzException {
    ConfigManager cfg = GlobalEntries.getGlobalEntries().getConfigManager();
    try {
        FreeIPATarget ipa = (FreeIPATarget) cfg.getProvisioningEngine().getTarget(this.targetName).getProvider();
        IPACall showGroup = new IPACall();
        showGroup.setId(0);
        showGroup.setMethod("group_show");
        ArrayList<String> groupName = new ArrayList<String>();
        groupName.add(params[0]);
        showGroup.getParams().add(groupName);
        HashMap<String, String> additionalParams = new HashMap<String, String>();
        additionalParams.put("no_members", "true");
        showGroup.getParams().add(additionalParams);
        IPAResponse resp = ipa.executeIPACall(showGroup);
        ArrayList<FilterBuilder> checks = new ArrayList<FilterBuilder>();
        if (((Map) resp.getResult().getResult()).containsKey("ipaexternalmember")) {
            List<String> vals = (List<String>) ((Map) resp.getResult().getResult()).get("ipaexternalmember");
            for (String val : vals) {
                checks.add(equal(this.uidAttributeName, val));
            }
        }
        FilterBuilder[] filters = new FilterBuilder[checks.size()];
        checks.toArray(filters);
        String filter = or(filters).toString();
        ArrayList<String> attrsToGet = new ArrayList<String>();
        attrsToGet.add("1.1");
        LDAPSearchResults ldapSearch = cfg.getMyVD().search(cfg.getCfg().getLdapRoot(), 2, filter, attrsToGet);
        ArrayList<String> approvers = new ArrayList<String>();
        while (ldapSearch.hasMore()) {
            approvers.add(ldapSearch.next().getDN());
        }
        return approvers;
    } catch (Exception e) {
        throw new AzException("Could not process authorization", e);
    }
}
Also used : IPAResponse(com.tremolosecurity.unison.freeipa.json.IPAResponse) HashMap(java.util.HashMap) AzException(com.tremolosecurity.proxy.az.AzException) IPACall(com.tremolosecurity.unison.freeipa.json.IPACall) ArrayList(java.util.ArrayList) ConfigManager(com.tremolosecurity.config.util.ConfigManager) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) AzException(com.tremolosecurity.proxy.az.AzException) LDAPSearchResults(com.novell.ldap.LDAPSearchResults) FilterBuilder(org.apache.directory.ldap.client.api.search.FilterBuilder) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with AzException

use of com.tremolosecurity.proxy.az.AzException in project OpenUnison by TremoloSecurity.

the class GithubTeamRule method isAuthorized.

@Override
public boolean isAuthorized(AuthInfo subject, String... params) throws AzException {
    if (params.length == 0) {
        // No parameters, allways true
        return true;
    }
    List<FilterBuilder> comps = new ArrayList<FilterBuilder>();
    for (String param : params) {
        if (param.endsWith("/")) {
            comps.add(equal("githubOrgs", param.substring(0, param.indexOf("/"))));
        } else {
            comps.add(equal("githubTeams", param));
        }
    }
    FilterBuilder[] ands = new FilterBuilder[comps.size()];
    comps.toArray(ands);
    String filterString = or(ands).toString();
    net.sourceforge.myvd.types.Filter filter;
    try {
        filter = new net.sourceforge.myvd.types.Filter(filterString);
    } catch (LDAPException e) {
        throw new AzException("Could not build authorization rule", e);
    }
    return filter.getRoot().checkEntry(subject.createLDAPEntry());
}
Also used : LDAPException(com.novell.ldap.LDAPException) AzException(com.tremolosecurity.proxy.az.AzException) FilterBuilder(org.apache.directory.ldap.client.api.search.FilterBuilder) ArrayList(java.util.ArrayList)

Aggregations

AzException (com.tremolosecurity.proxy.az.AzException)7 ArrayList (java.util.ArrayList)4 User (com.tremolosecurity.provisioning.core.User)3 LDAPException (com.novell.ldap.LDAPException)2 LDAPSearchResults (com.novell.ldap.LDAPSearchResults)2 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)2 CustomAuthorization (com.tremolosecurity.proxy.az.CustomAuthorization)2 HashMap (java.util.HashMap)2 FilterBuilder (org.apache.directory.ldap.client.api.search.FilterBuilder)2 LDAPEntry (com.novell.ldap.LDAPEntry)1 LDAPUrl (com.novell.ldap.LDAPUrl)1 DN (com.novell.ldap.util.DN)1 ConfigManager (com.tremolosecurity.config.util.ConfigManager)1 IPACall (com.tremolosecurity.unison.freeipa.json.IPACall)1 IPAResponse (com.tremolosecurity.unison.freeipa.json.IPAResponse)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 DateTime (org.joda.time.DateTime)1 ST (org.stringtemplate.v4.ST)1