Search in sources :

Example 1 with GroupList

use of com.okta.sdk.resource.group.GroupList in project OpenUnison by TremoloSecurity.

the class OktaTarget method createUser.

@Override
public void createUser(User user, Set<String> attributes, Map<String, Object> request) throws ProvisioningException {
    int approvalID = 0;
    if (request.containsKey("APPROVAL_ID")) {
        approvalID = (Integer) request.get("APPROVAL_ID");
    }
    Workflow workflow = (Workflow) request.get("WORKFLOW");
    com.okta.sdk.resource.user.User forOkta = null;
    UserBuilder ub = UserBuilder.instance();
    HashMap<String, Object> profile = new HashMap<String, Object>();
    for (String attrName : user.getAttribs().keySet()) {
        if (attributes.contains(attrName)) {
            profile.put(attrName, user.getAttribs().get(attrName).getValues().get(0));
        }
    }
    ub.setProfileProperties(profile);
    for (String group : user.getGroups()) {
        GroupList gl = okta.listGroups(group, null, null);
        ub.addGroup(gl.iterator().next().getId());
    }
    ub.buildAndCreate(this.okta);
    this.cfgMgr.getProvisioningEngine().logAction(name, true, ActionType.Add, approvalID, workflow, "login", user.getUserID());
    for (String attrName : user.getAttribs().keySet()) {
        if (attributes.contains(attrName)) {
            profile.put(attrName, user.getAttribs().get(attrName).getValues().get(0));
            this.cfgMgr.getProvisioningEngine().logAction(name, false, ActionType.Add, approvalID, workflow, attrName, user.getAttribs().get(attrName).getValues().get(0));
        }
    }
    for (String group : user.getGroups()) {
        this.cfgMgr.getProvisioningEngine().logAction(name, false, ActionType.Add, approvalID, workflow, "group", group);
    }
}
Also used : GroupList(com.okta.sdk.resource.group.GroupList) HashMap(java.util.HashMap) Workflow(com.tremolosecurity.provisioning.core.Workflow) JSONObject(org.json.simple.JSONObject) UserBuilder(com.okta.sdk.resource.user.UserBuilder)

Example 2 with GroupList

use of com.okta.sdk.resource.group.GroupList in project OpenUnison by TremoloSecurity.

the class OktaTarget method findUser.

@Override
public User findUser(String userID, Set<String> attributes, Map<String, Object> request) throws ProvisioningException {
    try {
        com.okta.sdk.resource.user.User fromOkta = null;
        try {
            fromOkta = okta.getUser(userID);
        } catch (ResourceException e) {
            if (e.getStatus() == 404) {
                return null;
            } else {
                throw new ProvisioningException("Could not lookup user", e);
            }
        }
        User user = new User(userID);
        UserProfile profile = fromOkta.getProfile();
        for (Object attrKey : profile.keySet()) {
            String attrName = (String) attrKey;
            String value = (String) profile.get(attrKey);
            if (attributes.contains(attrName)) {
                user.getAttribs().put(attrName, new Attribute(attrName, value));
            }
        }
        GroupList groups = fromOkta.listGroups();
        for (Group group : groups) {
            user.getGroups().add(group.getProfile().getName());
        }
        return user;
    } catch (Exception e) {
        throw new ProvisioningException("Could not retrieve user", e);
    }
}
Also used : Group(com.okta.sdk.resource.group.Group) User(com.tremolosecurity.provisioning.core.User) UserProfile(com.okta.sdk.resource.user.UserProfile) Attribute(com.tremolosecurity.saml.Attribute) ResourceException(com.okta.sdk.resource.ResourceException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) IOException(java.io.IOException) GroupList(com.okta.sdk.resource.group.GroupList) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) ResourceException(com.okta.sdk.resource.ResourceException) JSONObject(org.json.simple.JSONObject)

Example 3 with GroupList

use of com.okta.sdk.resource.group.GroupList in project OpenUnison by TremoloSecurity.

the class LoadGroupsFromOkta method validate.

@Override
public String validate(String value, HttpFilterRequest request) throws Exception {
    if (targetName == null) {
        throw new Exception("targetName not configured");
    }
    OktaTarget okta = (OktaTarget) GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getTarget(this.targetName).getProvider();
    if (okta == null) {
        throw new Exception("The target " + targetName + " does not exist");
    }
    Client client = okta.getOkta();
    GroupList groupList = client.listGroups(value, null, null);
    Group group = groupList.single();
    if (group == null || !group.getProfile().getName().equals(value)) {
        return this.errorMessage;
    } else {
        return null;
    }
}
Also used : Group(com.okta.sdk.resource.group.Group) GroupList(com.okta.sdk.resource.group.GroupList) OktaTarget(com.tremolosecurity.unison.okta.provisioning.OktaTarget) Client(com.okta.sdk.client.Client)

Example 4 with GroupList

use of com.okta.sdk.resource.group.GroupList in project OpenUnison by TremoloSecurity.

the class LoadGroupsFromOkta method getSourceList.

@Override
public List<NVP> getSourceList(HttpFilterRequest request) throws Exception {
    if (targetName == null) {
        throw new Exception("targetName not configured");
    }
    OktaTarget okta = (OktaTarget) GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getTarget(this.targetName).getProvider();
    if (okta == null) {
        throw new Exception("The target " + targetName + " does not exist");
    }
    Client client = okta.getOkta();
    if (request.getParameter("search") == null) {
        ArrayList<NVP> toReturn = new ArrayList<NVP>();
        GroupList groupList = client.listGroups();
        int i = 0;
        for (Group group : groupList) {
            toReturn.add(new NVP(group.getProfile().getName(), group.getProfile().getName()));
            if (this.dynSearch && i >= this.maxEntries) {
                break;
            }
        }
        Collections.sort(toReturn, new Comparator<NVP>() {

            @Override
            public int compare(NVP arg0, NVP arg1) {
                return arg0.getName().compareTo(arg1.getName());
            }
        });
        return toReturn;
    } else {
        int i = 0;
        ArrayList<NVP> toReturn = new ArrayList<NVP>();
        GroupList groupList = client.listGroups(request.getParameter("search").getValues().get(0), null, null);
        for (Group group : groupList) {
            toReturn.add(new NVP(group.getProfile().getName(), group.getProfile().getName()));
            i++;
            if (i >= this.maxEntries) {
                break;
            }
        }
        Collections.sort(toReturn, new Comparator<NVP>() {

            @Override
            public int compare(NVP arg0, NVP arg1) {
                return arg0.getName().compareTo(arg1.getName());
            }
        });
        return toReturn;
    }
}
Also used : Group(com.okta.sdk.resource.group.Group) GroupList(com.okta.sdk.resource.group.GroupList) OktaTarget(com.tremolosecurity.unison.okta.provisioning.OktaTarget) ArrayList(java.util.ArrayList) NVP(com.tremolosecurity.util.NVP) Client(com.okta.sdk.client.Client)

Example 5 with GroupList

use of com.okta.sdk.resource.group.GroupList in project OpenUnison by TremoloSecurity.

the class OktaInsert method loadGroupFromOkta.

private void loadGroupFromOkta(DistinguishedName base, Filter filter, String name, Client okta, ArrayList<Entry> ret) throws UnsupportedEncodingException {
    GroupList groupList;
    Group fromOkta;
    groupList = okta.listGroups(name, null, null);
    fromOkta = groupList.single();
    LDAPEntry entry = new LDAPEntry(base.getDN().toString());
    oktaGroup2Ldap(filter, ret, fromOkta, entry);
}
Also used : Group(com.okta.sdk.resource.group.Group) LDAPEntry(com.novell.ldap.LDAPEntry) GroupList(com.okta.sdk.resource.group.GroupList)

Aggregations

GroupList (com.okta.sdk.resource.group.GroupList)8 Group (com.okta.sdk.resource.group.Group)6 Client (com.okta.sdk.client.Client)3 ResourceException (com.okta.sdk.resource.ResourceException)3 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)3 OktaTarget (com.tremolosecurity.unison.okta.provisioning.OktaTarget)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 LDAPEntry (com.novell.ldap.LDAPEntry)2 User (com.okta.sdk.resource.user.User)2 Workflow (com.tremolosecurity.provisioning.core.Workflow)2 HashMap (java.util.HashMap)2 JSONObject (org.json.simple.JSONObject)2 LDAPException (com.novell.ldap.LDAPException)1 RDN (com.novell.ldap.util.RDN)1 AuthenticationClient (com.okta.authn.sdk.client.AuthenticationClient)1 UserBuilder (com.okta.sdk.resource.user.UserBuilder)1 UserList (com.okta.sdk.resource.user.UserList)1 UserProfile (com.okta.sdk.resource.user.UserProfile)1 User (com.tremolosecurity.provisioning.core.User)1