use of com.tremolosecurity.saml.Attribute in project OpenUnison by TremoloSecurity.
the class Attribute2Groups method doTask.
@Override
public boolean doTask(User user, Map<String, Object> request) throws ProvisioningException {
Attribute groups = user.getAttribs().get(this.attributeName);
if (groups == null) {
StringBuffer b = new StringBuffer();
b.append("Attribute '").append(this.attributeName).append("' not found");
logger.warn(b.toString());
} else {
user.getGroups().addAll(groups.getValues());
user.getAttribs().remove(this.attributeName);
}
return true;
}
use of com.tremolosecurity.saml.Attribute in project OpenUnison by TremoloSecurity.
the class CallRemoteWorkflow method init.
@Override
public void init(WorkflowTask task, Map<String, Attribute> params) throws ProvisioningException {
this.workflowName = params.get("workflowName").getValues().get(0);
this.lastmileKeyName = params.get("lastMileKeyName").getValues().get(0);
this.url = params.get("url").getValues().get(0);
this.fromRequest = new HashSet<String>();
this.staticRequest = new HashMap<String, String>();
this.lastMileUid = params.get("lastMileUid").getValues().get(0);
this.uidAttributeName = params.get("uidAttributeName").getValues().get(0);
Attribute attr = params.get("attributeFromRequest");
if (attr != null) {
this.fromRequest.addAll(attr.getValues());
}
attr = params.get("staticRequestValues");
if (attr != null) {
for (String p : attr.getValues()) {
String name = p.substring(0, p.indexOf('='));
String val = p.substring(p.indexOf('=') + 1);
this.staticRequest.put(name, val);
}
}
this.lastMileUser = params.get("lastMileUser").getValues().get(0);
this.timeSkew = Integer.parseInt(params.get("timeSkew").getValues().get(0));
this.task = task;
try {
URL uurl = new URL(this.url);
this.uri = uurl.getPath();
} catch (MalformedURLException e) {
throw new ProvisioningException("Could not initialize", e);
}
}
use of com.tremolosecurity.saml.Attribute in project OpenUnison by TremoloSecurity.
the class BasicDB method createUser.
/* (non-Javadoc)
* @see com.tremolosecurity.provisioning.core.providers.BasicDB#createUser(com.tremolosecurity.provisioning.core.User, java.util.Set, java.util.Map)
*/
@Override
public void createUser(User user, Set<String> attributes, Map<String, Object> request) throws ProvisioningException {
int userID = 0;
int approvalID = 0;
int workflow = 0;
if (request.containsKey("TREMOLO_USER_ID")) {
userID = (Integer) request.get("TREMOLO_USER_ID");
}
if (request.containsKey("APPROVAL_ID")) {
approvalID = (Integer) request.get("APPROVAL_ID");
}
if (request.containsKey("WORKFLOW_ID")) {
workflow = (Integer) request.get("WORKFLOW_ID");
}
Map<String, Attribute> attrs = new HashMap<String, Attribute>();
attrs.putAll(user.getAttribs());
if (!attrs.containsKey(this.userName)) {
attrs.remove("userid");
attrs.put(this.userName, new Attribute(this.userName, user.getUserID()));
}
Connection con = null;
try {
con = this.ds.getConnection();
con.setAutoCommit(false);
int userid = -1;
if (this.customDBProvider != null) {
Map<String, Attribute> toadd = new HashMap<String, Attribute>();
for (String attr : attributes) {
if (attrs.get(attr) != null) {
toadd.put(attr, user.getAttribs().get(attr));
}
}
userid = this.customDBProvider.createUser(con, user, toadd, request);
for (String groupName : user.getGroups()) {
this.customDBProvider.addGroup(con, userid, groupName, request);
}
} else {
insertCreate(user, attributes, attrs, con, request);
}
con.commit();
} catch (Exception e) {
try {
if (con != null)
con.rollback();
} catch (SQLException e1) {
}
throw new ProvisioningException("Could not create user", e);
} finally {
if (con != null) {
try {
con.close();
} catch (SQLException e) {
}
}
}
}
use of com.tremolosecurity.saml.Attribute in project OpenUnison by TremoloSecurity.
the class LDAPProvider method doCreate.
private void doCreate(User user, Set<String> attributes, LDAPConnection con, 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");
String dn = this.getDN(user, request);
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;
}
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);
}
try {
con.add(new LDAPEntry(dn, attrs));
} catch (LDAPException e) {
throw new ProvisioningException("Could not add user " + user.getUserID(), e);
}
cfgMgr.getProvisioningEngine().logAction(this.name, true, ActionType.Add, approvalID, workflow, "dn", dn);
for (String attrName : user.getAttribs().keySet()) {
if (!attributes.contains(attrName)) {
continue;
}
for (String val : user.getAttribs().get(attrName).getValues()) {
this.cfgMgr.getProvisioningEngine().logAction(this.name, false, ActionType.Add, approvalID, workflow, attrName, val);
}
}
try {
Iterator<String> groupNames = user.getGroups().iterator();
while (groupNames.hasNext()) {
String groupName = groupNames.next();
StringBuffer b = new StringBuffer();
b.append("(cn=").append(groupName).append(")");
LDAPSearchResults res = con.search(searchBase, 2, b.toString(), new String[] { "1.1" }, false);
if (!res.hasMore()) {
throw new ProvisioningException("Group " + groupName + " does not exist");
}
String groupDN = res.next().getDN();
while (res.hasMore()) res.next();
LDAPAttribute attr = new LDAPAttribute(GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getGroupMemberAttribute(), dn);
LDAPModification mod = new LDAPModification(LDAPModification.ADD, attr);
con.modify(groupDN, mod);
this.cfgMgr.getProvisioningEngine().logAction(this.name, false, ActionType.Add, approvalID, workflow, "group", groupName);
}
} catch (LDAPException e) {
throw new ProvisioningException("Could not provision groups for user " + user.getUserID(), e);
}
}
use of com.tremolosecurity.saml.Attribute in project OpenUnison by TremoloSecurity.
the class LDAPProvider method doFindUser.
private User doFindUser(String userID, Set<String> attributes, StringBuffer filter, LDAPConnection con) throws LDAPException {
LDAPEntry ldapUser = null;
boolean isExternal = false;
LDAPSearchResults res = con.search(searchBase, 2, filter.toString(), this.toStringArray(attributes), false);
if (!res.hasMore()) {
if (this.allowExternalUsers) {
res = searchExternalUser(userID);
if (!res.hasMore()) {
return null;
}
isExternal = true;
} else {
return null;
}
}
try {
ldapUser = res.next();
while (res.hasMore()) res.next();
} catch (LDAPReferralException e) {
}
if (ldapUser == null) {
return null;
}
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);
}
StringBuffer b = new StringBuffer();
// b.append("(uniqueMember=").append(ldapUser.getDN()).append(")");
String userDN = ldapUser.getDN();
if (isExternal) {
userDN = this.mapUnison2Dir(userDN);
}
res = con.search(searchBase, 2, equal(GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getGroupMemberAttribute(), userDN).toString(), new String[] { "cn" }, false);
while (res.hasMore()) {
LDAPEntry group = res.next();
user.getGroups().add(group.getAttribute("cn").getStringValue());
}
return user;
}
Aggregations