use of com.novell.ldap.LDAPReferralException 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;
}
use of com.novell.ldap.LDAPReferralException in project OpenUnison by TremoloSecurity.
the class ADProvider method doSync.
private void doSync(User user, boolean fromUserOnly, Set<String> attributes, StringBuffer filter, LDAPConnection con, Map<String, Object> request) throws LDAPException, ProvisioningException {
LDAPSearchResults res = con.search(searchBase, 2, filter.toString(), this.toStringArray(attributes), false);
int approvalID = 0;
boolean isExternal = false;
LDAPEntry ldapUser = null;
if (request.containsKey("APPROVAL_ID")) {
approvalID = (Integer) request.get("APPROVAL_ID");
}
Workflow workflow = (Workflow) request.get("WORKFLOW");
if (!res.hasMore()) {
if (this.supportExternalUsers) {
ldapUser = this.getMyVDUser(filter);
if (ldapUser == null) {
this.createUser(user, attributes, request);
} else {
isExternal = true;
ArrayList<LDAPModification> mods = new ArrayList<LDAPModification>();
HashSet<String> done = new HashSet<String>();
syncUser(user, fromUserOnly, attributes, con, approvalID, workflow, mods, done, ldapUser, isExternal, request);
}
} else {
this.createUser(user, attributes, request);
}
} else {
ArrayList<LDAPModification> mods = new ArrayList<LDAPModification>();
HashSet<String> done = new HashSet<String>();
try {
ldapUser = res.next();
try {
while (res.hasMore()) res.next();
} catch (LDAPReferralException e) {
}
} catch (LDAPReferralException e) {
if (this.supportExternalUsers) {
ldapUser = this.getMyVDUser(filter);
if (ldapUser == null) {
this.createUser(user, attributes, request);
return;
} else {
isExternal = true;
}
} else {
this.createUser(user, attributes, request);
return;
}
}
syncUser(user, fromUserOnly, attributes, con, approvalID, workflow, mods, done, ldapUser, isExternal, request);
}
}
use of com.novell.ldap.LDAPReferralException in project OpenUnison by TremoloSecurity.
the class ADProvider method syncGroups.
private void syncGroups(User user, boolean fromUserOnly, LDAPConnection con, int approvalID, Workflow workflow, HashSet<String> done, LDAPEntry ldapUser, boolean isExternal) throws LDAPException, ProvisioningException {
LDAPSearchResults res;
if (isExternal) {
String fdn = ldapUser.getDN();
/*if (fdn.contains("\\\\\\\\,")) {
fdn = fdn.replaceAll("\\\\\\\\,","\\5C,");
}
if (fdn.contains("\\,")) {
fdn = fdn.replaceAll("\\\\,","\\\\5C,");
}*/
// fdn = this.adEscape(fdn);
res = con.search(searchBase, 2, equal(this.externalGroupAttr, fdn).toString(), new String[] { "cn" }, false);
} else {
String fdn = ldapUser.getDN();
/*if (fdn.contains("\\,")) {
fdn = fdn.replaceAll("[\\\\][,]","\\\\5C,");
} */
// fdn = this.adEscape(fdn);
StringBuffer f = new StringBuffer();
res = con.search(searchBase, 2, equal("member", fdn).toString(), new String[] { "cn" }, false);
}
done.clear();
while (res.hasMore()) {
LDAPEntry groupEntry = null;
try {
groupEntry = res.next();
} catch (LDAPReferralException e) {
break;
}
String memberDN = ldapUser.getDN();
if (memberDN.contains("\\\\\\,")) {
memberDN = memberDN.replaceAll("\\\\\\\\,", "\\,");
}
if (!user.getGroups().contains(groupEntry.getAttribute("cn").getStringValue())) {
if (!fromUserOnly) {
if (isExternal) {
if (logger.isDebugEnabled()) {
logger.debug("Deleting external '" + memberDN + "' from '" + groupEntry.getDN() + "'");
}
con.modify(groupEntry.getDN(), new LDAPModification(LDAPModification.DELETE, new LDAPAttribute(this.externalGroupAttr, memberDN)));
} else {
if (logger.isDebugEnabled()) {
logger.debug("Deleting internal '" + memberDN + "' from '" + groupEntry.getDN() + "'");
}
con.modify(groupEntry.getDN(), new LDAPModification(LDAPModification.DELETE, new LDAPAttribute("member", memberDN)));
}
this.cfgMgr.getProvisioningEngine().logAction(name, false, ActionType.Delete, approvalID, workflow, "group", groupEntry.getAttribute("cn").getStringValue());
}
}
done.add(groupEntry.getAttribute("cn").getStringValue());
}
Iterator<String> itgroups = user.getGroups().iterator();
while (itgroups.hasNext()) {
String groupName = itgroups.next();
if (done.contains(groupName)) {
continue;
}
StringBuffer b = new StringBuffer();
b.append("(cn=").append(groupName).append(")");
res = con.search(searchBase, 2, b.toString(), new String[] { "1.1" }, false);
if (!res.hasMore()) {
if (!isExternal) {
b.setLength(0);
b.append("Group ").append(groupName).append(" does not exist");
logger.warn(b.toString());
}
continue;
}
String groupDN = res.next().getDN();
while (res.hasMore()) {
try {
res.next();
} catch (LDAPException e) {
// do nothing
}
}
String memberDN = ldapUser.getDN();
if (memberDN.contains("\\\\\\,")) {
memberDN = memberDN.replaceAll("\\\\\\\\,", "\\,");
}
if (isExternal) {
if (logger.isDebugEnabled()) {
logger.debug("Adding external '" + memberDN + "' to '" + groupDN + "'");
}
con.modify(groupDN, new LDAPModification(LDAPModification.ADD, new LDAPAttribute(this.externalGroupAttr, memberDN)));
} else {
if (logger.isDebugEnabled()) {
logger.debug("Adding internal '" + memberDN + "' to '" + groupDN + "'");
}
con.modify(groupDN, new LDAPModification(LDAPModification.ADD, new LDAPAttribute("member", memberDN)));
}
this.cfgMgr.getProvisioningEngine().logAction(name, false, ActionType.Add, approvalID, workflow, "group", groupName);
}
}
use of com.novell.ldap.LDAPReferralException 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;
}
use of com.novell.ldap.LDAPReferralException in project OpenUnison by TremoloSecurity.
the class UpdateApprovalAZListener method sendNotification.
private void sendNotification(String emailTemplate, ConfigManager cfg, Session session, String userKey) throws ProvisioningException {
try {
ArrayList<String> attrs = new ArrayList<String>();
// attrs.add("mail");
// attrs.add(cfg.getProvisioningEngine().getUserIDAttribute());
LDAPSearchResults res = cfg.getMyVD().search(GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getLdapRoot(), 2, equal(cfg.getProvisioningEngine().getUserIDAttribute(), userKey).toString(), attrs);
if (!res.hasMore()) {
if (logger.isDebugEnabled()) {
logger.debug("Can not find '" + userKey + "'");
}
return;
}
LDAPEntry entry = res.next();
if (logger.isDebugEnabled()) {
logger.debug("Approver DN - " + entry.getDN());
LDAPAttributeSet attrsx = entry.getAttributeSet();
for (Object o : attrsx) {
LDAPAttribute attrx = (LDAPAttribute) o;
for (String val : attrx.getStringValueArray()) {
logger.debug("Approver Attribute '" + attrx.getName() + "'='" + val + "'");
}
}
}
String userID = entry.getAttribute(cfg.getProvisioningEngine().getUserIDAttribute()).getStringValue();
if (entry.getAttribute("mail") == null) {
StringBuffer b = new StringBuffer();
b.append("No email address for ").append(userKey);
logger.warn(b.toString());
} else {
String mail = entry.getAttribute("mail").getStringValue();
logger.debug("Sedning notification to '" + mail + "'");
cfg.getProvisioningEngine().sendNotification(mail, emailTemplate, new User(entry));
}
} catch (LDAPReferralException le) {
StringBuffer b = new StringBuffer();
b.append("User : '").append(userKey).append("' not found");
logger.warn(b.toString());
} catch (LDAPException le) {
if (le.getResultCode() == 32) {
StringBuffer b = new StringBuffer();
b.append("User : '").append(userKey).append("' not found");
logger.warn(b.toString());
} else {
throw new ProvisioningException("could not create approver", le);
}
} catch (Exception e) {
throw new ProvisioningException("Could not create approver", e);
}
}
Aggregations