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