Commit a479a9a5 authored by benjamin.ertl's avatar benjamin.ertl
Browse files

include local user mapping

parent 60662521
...@@ -186,6 +186,22 @@ public class LdapClient { ...@@ -186,6 +186,22 @@ public class LdapClient {
return userList; return userList;
} }
/**
* Gets all POSIX users from the LDAP server with the specified uidNumber.
*
* @param udiNumber
* the users' uidNumber
*
* @return a {@link List<PosixUser>} with the LDAP user information
*/
public List<PosixUser> getPosixUsers(int uidNumber) {
List<PosixUser> userList = ldapPosixUser.getAllUsers(uidNumber);
for (int i = 0; i < userList.size(); i++)
log.debug("User {}", ((PosixUser) userList.get(i)).toString());
return userList;
}
/** /**
* Gets all POSIX groups from the LDAP server. * Gets all POSIX groups from the LDAP server.
* *
......
...@@ -46,6 +46,14 @@ public class LdapPosixUserDAO implements PosixUserDAO { ...@@ -46,6 +46,14 @@ public class LdapPosixUserDAO implements PosixUserDAO {
return ldapTemplate.search(userBase, "(objectclass=posixAccount)", new LdapPosixUserAttributeMapper()); return ldapTemplate.search(userBase, "(objectclass=posixAccount)", new LdapPosixUserAttributeMapper());
} }
public List<PosixUser> getAllUsers(int uidNumber) {
AndFilter andFilter = new AndFilter();
andFilter.and(new EqualsFilter("objectclass", "posixAccount")).and(new EqualsFilter("uidNumber", uidNumber));
log.debug("LDAP query {}", andFilter.encode());
return ldapTemplate.search("", andFilter.encode(), new LdapPosixUserAttributeMapper());
}
@Override @Override
public List<PosixUser> getUserDetails(String uid) { public List<PosixUser> getUserDetails(String uid) {
AndFilter andFilter = new AndFilter(); AndFilter andFilter = new AndFilter();
......
...@@ -19,6 +19,7 @@ import org.springframework.stereotype.Component; ...@@ -19,6 +19,7 @@ import org.springframework.stereotype.Component;
import edu.kit.scc.dto.IndigoUser; import edu.kit.scc.dto.IndigoUser;
import edu.kit.scc.dto.PosixGroup; import edu.kit.scc.dto.PosixGroup;
import edu.kit.scc.dto.PosixUser;
import edu.kit.scc.ldap.LdapClient; import edu.kit.scc.ldap.LdapClient;
/** /**
...@@ -63,8 +64,26 @@ public class ScimService { ...@@ -63,8 +64,26 @@ public class ScimService {
// user claims to have local user id // user claims to have local user id
log.debug("User claimed local uidNumber {}", clamiedPrimaryUidNumber); log.debug("User claimed local uidNumber {}", clamiedPrimaryUidNumber);
createdUser = createOrGetDefaultUser(indigoUser); createdUser = createOrGetDefaultUser(indigoUser);
log.debug("Created user {}", createdUser.toString());
// - verify local user // - verify local user
// - modify created user's uidNumber // - modify created user's uidNumber
IndigoUser localUser = userMapper.mapToIndigoUser(createdUser);
log.debug("Map from {} to {}", createdUser.toString(), localUser.toString());
PosixUser verifiedLocalUser = getVerifiedLocalUser(clamiedPrimaryUidNumber);
log.debug("Found verified local user {}", verifiedLocalUser.toString());
int verifiedLocalUidNumber = verifiedLocalUser.getUidNumber();
String verifiedLocalHomeDirectory = verifiedLocalUser.getHomeDirectory();
IndigoUser updatedUser = ldapClient.updateIndigoUser(localUser.getUid(), localUser.getCommonName(),
localUser.getSurName(), localUser.getIndigoId(), verifiedLocalUidNumber, localUser.getGidNumber(),
verifiedLocalHomeDirectory, localUser.getDescription(), localUser.getGecos(),
localUser.getLoginShell(),
(localUser.getUserPassword() != null ? new String(localUser.getUserPassword()) : null));
log.debug("Updated user {}", updatedUser.toString());
createdUser = userMapper.mapFromIndigoUser(updatedUser);
} else { } else {
// user has no local user id, use default // user has no local user id, use default
log.debug("User has no local uidNumber"); log.debug("User has no local uidNumber");
...@@ -97,6 +116,20 @@ public class ScimService { ...@@ -97,6 +116,20 @@ public class ScimService {
return createdUser; return createdUser;
} }
private PosixUser getVerifiedLocalUser(int claimedPrimaryUidNumber) {
PosixUser user = null;
List<PosixUser> users = ldapClient.getPosixUsers(claimedPrimaryUidNumber);
if (users != null && !users.isEmpty()) {
if (users.size() == 1) {
user = users.get(0);
} else {
// multiple users with the same uidNumber
user = users.get(0);
}
}
return user;
}
private HashMap<String, Integer> getVerifiedLocalGroups(List<ScimGroup> groups) { private HashMap<String, Integer> getVerifiedLocalGroups(List<ScimGroup> groups) {
HashMap<String, Integer> localGroups = new HashMap<String, Integer>(); HashMap<String, Integer> localGroups = new HashMap<String, Integer>();
...@@ -140,13 +173,14 @@ public class ScimService { ...@@ -140,13 +173,14 @@ public class ScimService {
ldapClient.addGroupMember(indigoGroup.getDisplay(), ldapUser.getUid()); ldapClient.addGroupMember(indigoGroup.getDisplay(), ldapUser.getUid());
log.debug("Created LDAP INDIGO user {}", ldapUser.toString()); log.debug("Created/got LDAP INDIGO user {}", ldapUser.toString());
user = mapper.mapFromIndigoUser(ldapUser); user = mapper.mapFromIndigoUser(ldapUser);
} catch (Exception e) { } catch (Exception e) {
log.error("ERROR {}", e.getMessage()); log.error("ERROR {}", e.getMessage());
// e.printStackTrace(); // e.printStackTrace();
} }
log.debug("Created/got user {}", user.toString());
return user; return user;
} }
...@@ -161,7 +195,7 @@ public class ScimService { ...@@ -161,7 +195,7 @@ public class ScimService {
PosixGroup ldapGroup = ldapClient.createPosixGroup(DEFAULT_INDIGO_GROUP, gidNumber, DEFAULT_DESCRIPTION, PosixGroup ldapGroup = ldapClient.createPosixGroup(DEFAULT_INDIGO_GROUP, gidNumber, DEFAULT_DESCRIPTION,
null); null);
log.debug("Created LDAP group {}", ldapGroup.toString()); log.debug("Created/got LDAP group {}", ldapGroup.toString());
createdGroup = mapper.mapFromPosixGroup(ldapGroup); createdGroup = mapper.mapFromPosixGroup(ldapGroup);
} catch (Exception e) { } catch (Exception e) {
......
...@@ -60,7 +60,7 @@ public class ScimUserAttributeMapper { ...@@ -60,7 +60,7 @@ public class ScimUserAttributeMapper {
user.setGidNumber(Integer.valueOf(scimUser.getMeta().get("gidNumber"))); user.setGidNumber(Integer.valueOf(scimUser.getMeta().get("gidNumber")));
} }
if (scimUser.getMeta().get("uidNumber") != null) { if (scimUser.getMeta().get("uidNumber") != null) {
user.setUidNumber(Integer.valueOf(scimUser.getMeta().get("gidNumber"))); user.setUidNumber(Integer.valueOf(scimUser.getMeta().get("uidNumber")));
} }
} }
...@@ -95,11 +95,15 @@ public class ScimUserAttributeMapper { ...@@ -95,11 +95,15 @@ public class ScimUserAttributeMapper {
Meta meta = new Meta(); Meta meta = new Meta();
meta.put("homeDirectory", user.getHomeDirectory()); meta.put("homeDirectory", user.getHomeDirectory());
meta.put("gecos", user.getGecos()); if (user.getGecos() != null)
meta.put("loginShell", user.getLoginShell()); meta.put("gecos", user.getGecos());
meta.put("description", user.getDescription()); if (user.getLoginShell() != null)
meta.put("loginShell", user.getLoginShell());
if (user.getDescription() != null)
meta.put("description", user.getDescription());
meta.put("gidNumber", String.valueOf(user.getGidNumber())); meta.put("gidNumber", String.valueOf(user.getGidNumber()));
meta.put("uidNumber", String.valueOf(user.getUidNumber())); meta.put("uidNumber", String.valueOf(user.getUidNumber()));
scimUser.setMeta(meta);
if (user.getUserPassword() != null) if (user.getUserPassword() != null)
scimUser.setPassword(new String(user.getUserPassword())); scimUser.setPassword(new String(user.getUserPassword()));
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
"givenName":"Barbara" "givenName":"Barbara"
}, },
"meta":{ "meta":{
"gidNumber":"9999" "gidNumber":"9999",
"uidNumber":"5555"
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment