use of org.springframework.ldap.NameNotFoundException in project perun by CESNET.
the class LdapConnectorImpl method createUser.
//-----------------------USER MODIFICATION METHODS----------------------------
public void createUser(User user) throws InternalErrorException {
// Create a set of attributes
Attributes attributes = new BasicAttributes();
// Create the objectclass to add
Attribute objClasses = new BasicAttribute("objectClass");
objClasses.add("top");
objClasses.add("person");
objClasses.add("organizationalPerson");
objClasses.add("inetOrgPerson");
objClasses.add("perunUser");
objClasses.add("tenOperEntry");
objClasses.add("inetUser");
String firstName = user.getFirstName();
String lastName = user.getLastName();
if (firstName == null)
firstName = "";
if (lastName == null || lastName.isEmpty())
lastName = "N/A";
// Add attributes
attributes.put(objClasses);
attributes.put("entryStatus", "active");
attributes.put("sn", lastName);
attributes.put("cn", firstName + " " + lastName);
if (!firstName.isEmpty())
attributes.put("givenName", firstName);
attributes.put("perunUserId", String.valueOf(user.getId()));
if (user.isServiceUser())
attributes.put("isServiceUser", "1");
else
attributes.put("isServiceUser", "0");
if (user.isSponsoredUser())
attributes.put("isSponsoredUser", "1");
else
attributes.put("isSponsoredUser", "0");
// Create the entry
try {
ldapTemplate.bind(getUserDN(String.valueOf(user.getId())), null, attributes);
log.debug("New entry created in LDAP: User {} in Group with Id=" + user.getId() + ".", user);
} catch (NameNotFoundException e) {
throw new InternalErrorException(e);
}
}
use of org.springframework.ldap.NameNotFoundException in project perun by CESNET.
the class LdapConnectorImpl method resourceAttributeExist.
public boolean resourceAttributeExist(Resource resource, String ldapAttributeName) throws InternalErrorException {
if (ldapAttributeName == null)
throw new InternalErrorException("ldapAttributeName can't be null.");
Object o = null;
try {
setLdapAttributeName(ldapAttributeName);
o = ldapTemplate.lookup(getResourceDN(String.valueOf(resource.getVoId()), String.valueOf(resource.getId())), new ResourcePerunResourceAttributeContextMapper());
} catch (NameNotFoundException ex) {
return false;
}
if (o == null)
return false;
return true;
}
use of org.springframework.ldap.NameNotFoundException in project perun by CESNET.
the class LdapConnectorImpl method deleteUser.
public void deleteUser(User user) throws InternalErrorException {
try {
ldapTemplate.unbind(getUserDN(String.valueOf(user.getId())));
log.debug("Entry deleted from LDAP: User {}.", user);
} catch (NameNotFoundException e) {
throw new InternalErrorException(e);
}
}
use of org.springframework.ldap.NameNotFoundException in project perun by CESNET.
the class LdapConnectorImpl method removeGroup.
public void removeGroup(Group group) throws InternalErrorException {
List<String> uniqueUsersIds = new ArrayList<String>();
uniqueUsersIds = this.getAllUniqueMembersInGroup(group.getId(), group.getVoId());
for (String s : uniqueUsersIds) {
Attribute memberOf = new BasicAttribute("memberOf", "perunGroupId=" + group.getId() + ",perunVoId=" + group.getVoId() + "," + ldapProperties.getLdapBase());
ModificationItem memberOfItem = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, memberOf);
this.updateUserWithUserId(s, new ModificationItem[] { memberOfItem });
}
try {
ldapTemplate.unbind(getGroupDN(String.valueOf(group.getVoId()), String.valueOf(group.getId())));
log.debug("Entry deleted from LDAP: Group {} from Vo with ID=" + group.getVoId() + ".", group);
} catch (NameNotFoundException e) {
throw new InternalErrorException(e);
}
}
use of org.springframework.ldap.NameNotFoundException in project perun by CESNET.
the class LdapConnectorImpl method userAttributeExist.
public boolean userAttributeExist(User user, String ldapAttributeName) throws InternalErrorException {
if (ldapAttributeName == null)
throw new InternalErrorException("ldapAttributeName can't be null.");
Object o = null;
try {
setLdapAttributeName(ldapAttributeName);
o = ldapTemplate.lookup(getUserDN(String.valueOf(user.getId())), new UserPerunUserAttributeContextMapper());
} catch (NameNotFoundException ex) {
return false;
}
if (o == null)
return false;
return true;
}
Aggregations