Commit 9fe0052a authored by benjamin.ertl's avatar benjamin.ertl
Browse files

init harmonize algo

parent b8e4d0c7
...@@ -31,6 +31,10 @@ ...@@ -31,6 +31,10 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId> <artifactId>spring-boot-starter-thymeleaf</artifactId>
...@@ -93,9 +97,11 @@ ...@@ -93,9 +97,11 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.apache.hadoop</groupId>
<artifactId>spring-boot-starter-jersey</artifactId> <artifactId>hadoop-core</artifactId>
<version>1.0.0</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file
...@@ -10,7 +10,6 @@ package edu.kit.scc; ...@@ -10,7 +10,6 @@ package edu.kit.scc;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.FormParam; import javax.ws.rs.FormParam;
import javax.ws.rs.HeaderParam;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -61,17 +60,21 @@ public class RestServiceController { ...@@ -61,17 +60,21 @@ public class RestServiceController {
@RequestMapping(path = "/scim/Users", method = RequestMethod.POST, produces = "application/scim+json") @RequestMapping(path = "/scim/Users", method = RequestMethod.POST, produces = "application/scim+json")
@ResponseStatus(value = HttpStatus.CREATED) @ResponseStatus(value = HttpStatus.CREATED)
public ScimUser scimAddUser(@RequestHeader("Authorization") String basicAuthorization, @RequestBody String body, public ScimUser scimAddUser(@RequestHeader("Authorization") String basicAuthorization,
HttpServletResponse response) { @RequestBody ScimUser scimUser, HttpServletResponse response) {
ScimUser scimUser = new ScimUser();
verifyAuthorization(basicAuthorization); verifyAuthorization(basicAuthorization);
log.debug("Request body {}", body); log.debug("Request body {}", scimUser);
ScimUser createdScimUser = scimService.createLdapIndigoUser(scimUser);
response.addHeader("Location", ""); if (createdScimUser != null) {
response.addHeader("Location", "");
return createdScimUser;
}
return scimUser; throw new ConflictException();
} }
@RequestMapping(path = "/ecp/regid/{regId}", method = RequestMethod.POST) @RequestMapping(path = "/ecp/regid/{regId}", method = RequestMethod.POST)
......
...@@ -17,9 +17,9 @@ public interface IndigoUserDAO { ...@@ -17,9 +17,9 @@ public interface IndigoUserDAO {
public List<IndigoUser> getUserDetails(String uid); public List<IndigoUser> getUserDetails(String uid);
public void insertUser(IndigoUser userDTO); public void insertUser(IndigoUser user);
public void updateUser(IndigoUser userDTO); public void updateUser(IndigoUser user);
public void deleteUser(IndigoUser userDTO); public void deleteUser(IndigoUser user);
} }
...@@ -17,11 +17,9 @@ public interface PosixGroupDAO { ...@@ -17,11 +17,9 @@ public interface PosixGroupDAO {
public List<PosixGroup> getGroupDetails(String commonName); public List<PosixGroup> getGroupDetails(String commonName);
public void insertGroup(PosixGroup groupDTO); public void insertGroup(PosixGroup group);
public void updateGroup(PosixGroup groupDTO); public void updateGroup(PosixGroup group);
public void deleteGroup(PosixGroup groupDTO); public void deleteGroup(PosixGroup group);
public void addMember(PosixGroup groupDTO, String memberUid);
} }
/* Copyright 2016 Karlsruhe Institute of Technology (KIT)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
*/
package edu.kit.scc.dao;
import java.util.List;
import edu.kit.scc.dto.PosixUser;
public interface PosixUserDAO {
public List<PosixUser> getAllUsers();
public List<PosixUser> getUserDetails(String uid);
public void insertUser(PosixUser user);
public void updateUser(PosixUser user);
public void deleteUser(PosixUser user);
}
\ No newline at end of file
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
*/ */
package edu.kit.scc.dto; package edu.kit.scc.dto;
import java.util.Arrays;
public class IndigoUser extends PosixUser { public class IndigoUser extends PosixUser {
String indigoId; String indigoId;
...@@ -30,7 +32,7 @@ public class IndigoUser extends PosixUser { ...@@ -30,7 +32,7 @@ public class IndigoUser extends PosixUser {
+ (description != null ? "description=" + description + ", " : "") + (description != null ? "description=" + description + ", " : "")
+ (gecos != null ? "gecos=" + gecos + ", " : "") + (gecos != null ? "gecos=" + gecos + ", " : "")
+ (loginShell != null ? "loginShell=" + loginShell + ", " : "") + (loginShell != null ? "loginShell=" + loginShell + ", " : "")
+ (userPassword != null ? "userPassword=" + userPassword + ", " : "") + "uidNumber=" + uidNumber + (userPassword != null ? "userPassword=" + Arrays.toString(userPassword) + ", " : "") + "uidNumber="
+ ", gidNumber=" + gidNumber + "]"; + uidNumber + ", gidNumber=" + gidNumber + "]";
} }
} }
\ No newline at end of file
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
*/ */
package edu.kit.scc.dto; package edu.kit.scc.dto;
import java.util.Arrays;
import java.util.List; import java.util.List;
public class PosixGroup { public class PosixGroup {
...@@ -16,7 +17,7 @@ public class PosixGroup { ...@@ -16,7 +17,7 @@ public class PosixGroup {
int gidNumber; int gidNumber;
List<String> memberUids; List<String> memberUids;
String description; String description;
String userPassword; byte[] userPassword;
public String getCommonName() { public String getCommonName() {
return commonName; return commonName;
...@@ -50,11 +51,11 @@ public class PosixGroup { ...@@ -50,11 +51,11 @@ public class PosixGroup {
this.description = description; this.description = description;
} }
public String getUserPassword() { public byte[] getUserPassword() {
return userPassword; return userPassword;
} }
public void setUserPassword(String userPassword) { public void setUserPassword(byte[] userPassword) {
this.userPassword = userPassword; this.userPassword = userPassword;
} }
...@@ -63,6 +64,6 @@ public class PosixGroup { ...@@ -63,6 +64,6 @@ public class PosixGroup {
return "PosixGroup [" + (commonName != null ? "commonName=" + commonName + ", " : "") + "gidNumber=" + gidNumber return "PosixGroup [" + (commonName != null ? "commonName=" + commonName + ", " : "") + "gidNumber=" + gidNumber
+ ", " + (memberUids != null ? "memberUids=" + memberUids + ", " : "") + ", " + (memberUids != null ? "memberUids=" + memberUids + ", " : "")
+ (description != null ? "description=" + description + ", " : "") + (description != null ? "description=" + description + ", " : "")
+ (userPassword != null ? "userPassword=" + userPassword : "") + "]"; + (userPassword != null ? "userPassword=" + Arrays.toString(userPassword) : "") + "]";
} }
} }
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
*/ */
package edu.kit.scc.dto; package edu.kit.scc.dto;
import java.util.Arrays;
public class PosixUser { public class PosixUser {
String uid; String uid;
...@@ -17,7 +19,7 @@ public class PosixUser { ...@@ -17,7 +19,7 @@ public class PosixUser {
String description; String description;
String gecos; String gecos;
String loginShell; String loginShell;
String userPassword; byte[] userPassword;
int uidNumber; int uidNumber;
int gidNumber; int gidNumber;
...@@ -38,11 +40,11 @@ public class PosixUser { ...@@ -38,11 +40,11 @@ public class PosixUser {
this.loginShell = loginShell; this.loginShell = loginShell;
} }
public String getUserPassword() { public byte[] getUserPassword() {
return userPassword; return userPassword;
} }
public void setUserPassword(String userPassword) { public void setUserPassword(byte[] userPassword) {
this.userPassword = userPassword; this.userPassword = userPassword;
} }
...@@ -111,7 +113,7 @@ public class PosixUser { ...@@ -111,7 +113,7 @@ public class PosixUser {
+ (description != null ? "description=" + description + ", " : "") + (description != null ? "description=" + description + ", " : "")
+ (gecos != null ? "gecos=" + gecos + ", " : "") + (gecos != null ? "gecos=" + gecos + ", " : "")
+ (loginShell != null ? "loginShell=" + loginShell + ", " : "") + (loginShell != null ? "loginShell=" + loginShell + ", " : "")
+ (userPassword != null ? "userPassword=" + userPassword + ", " : "") + "uidNumber=" + uidNumber + (userPassword != null ? "userPassword=" + Arrays.toString(userPassword) + ", " : "") + "uidNumber="
+ ", gidNumber=" + gidNumber + "]"; + uidNumber + ", gidNumber=" + gidNumber + "]";
} }
} }
...@@ -22,6 +22,7 @@ import org.springframework.ldap.core.support.LdapContextSource; ...@@ -22,6 +22,7 @@ import org.springframework.ldap.core.support.LdapContextSource;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import edu.kit.scc.dto.PosixGroup; import edu.kit.scc.dto.PosixGroup;
import edu.kit.scc.dto.PosixUser;
import edu.kit.scc.dto.IndigoUser; import edu.kit.scc.dto.IndigoUser;
/** /**
...@@ -69,7 +70,7 @@ public class LdapClient { ...@@ -69,7 +70,7 @@ public class LdapClient {
} }
@Bean @Bean
LdapIndigoUserDAO ldapUser(LdapTemplate ldapTemplate) { LdapIndigoUserDAO ldapIndigoUser(LdapTemplate ldapTemplate) {
LdapIndigoUserDAO ldapUserDAO = new LdapIndigoUserDAO(); LdapIndigoUserDAO ldapUserDAO = new LdapIndigoUserDAO();
ldapUserDAO.setLdapTemplate(ldapTemplate); ldapUserDAO.setLdapTemplate(ldapTemplate);
ldapUserDAO.setUserBase(userBase); ldapUserDAO.setUserBase(userBase);
...@@ -77,7 +78,15 @@ public class LdapClient { ...@@ -77,7 +78,15 @@ public class LdapClient {
} }
@Bean @Bean
LdapPosixGroupDAO ldapGroup(LdapTemplate ldapTemplate) { LdapPosixUserDAO ldapPosixUser(LdapTemplate ldapTemplate) {
LdapPosixUserDAO ldapUserDAO = new LdapPosixUserDAO();
ldapUserDAO.setLdapTemplate(ldapTemplate);
ldapUserDAO.setUserBase("");
return ldapUserDAO;
}
@Bean
LdapPosixGroupDAO ldapPosixGroup(LdapTemplate ldapTemplate) {
LdapPosixGroupDAO ldapGroupDAO = new LdapPosixGroupDAO(); LdapPosixGroupDAO ldapGroupDAO = new LdapPosixGroupDAO();
ldapGroupDAO.setLdapTemplate(ldapTemplate); ldapGroupDAO.setLdapTemplate(ldapTemplate);
ldapGroupDAO.setGroupBase(groupBase); ldapGroupDAO.setGroupBase(groupBase);
...@@ -85,20 +94,23 @@ public class LdapClient { ...@@ -85,20 +94,23 @@ public class LdapClient {
} }
@Autowired @Autowired
private LdapIndigoUserDAO ldapUser; private LdapIndigoUserDAO ldapIndigoUser;
@Autowired @Autowired
private LdapPosixGroupDAO ldapGroup; private LdapPosixUserDAO ldapPosixUser;
@Autowired
private LdapPosixGroupDAO ldapPosixGroup;
/** /**
* Gets the user specified from the LDAP server. * Gets the INDIGO user specified from the LDAP server.
* *
* @param uid * @param uid
* the user's uid * the user's uid
* @return a {@link IndigoUser} with the LDAP user information * @return a {@link IndigoUser} with the LDAP user information
*/ */
public IndigoUser getIndigoUser(String uid) { public IndigoUser getIndigoUser(String uid) {
List<IndigoUser> userList = ldapUser.getUserDetails(uid); List<IndigoUser> userList = ldapIndigoUser.getUserDetails(uid);
IndigoUser user = null; IndigoUser user = null;
if (userList != null && !userList.isEmpty()) { if (userList != null && !userList.isEmpty()) {
...@@ -109,14 +121,14 @@ public class LdapClient { ...@@ -109,14 +121,14 @@ public class LdapClient {
} }
/** /**
* Gets the group specified from the LDAP server. * Gets the POSIX group specified from the LDAP server.
* *
* @param cn * @param cn
* the group's common name * the group's common name
* @return a {@link PosixGroup} with the LDAP group information * @return a {@link PosixGroup} with the LDAP group information
*/ */
public PosixGroup getPosixGroup(String cn) { public PosixGroup getPosixGroup(String cn) {
List<PosixGroup> groupList = ldapGroup.getGroupDetails(cn); List<PosixGroup> groupList = ldapPosixGroup.getGroupDetails(cn);
PosixGroup group = null; PosixGroup group = null;
if (groupList != null && !groupList.isEmpty()) { if (groupList != null && !groupList.isEmpty()) {
...@@ -127,12 +139,30 @@ public class LdapClient { ...@@ -127,12 +139,30 @@ public class LdapClient {
} }
/** /**
* Gets all users from the LDAP server. * Gets the POSIX group specified from the LDAP server.
* *
* @return a {@link List<UserDTO>} with the LDAP user information * @param gidNumber
* the group's gidNumber
* @return a {@link PosixGroup} with the LDAP group information
*/
public PosixGroup getPosixGroup(int gidNumber) {
List<PosixGroup> groupList = ldapPosixGroup.getGroupDetails(gidNumber);
PosixGroup group = null;
if (groupList != null && !groupList.isEmpty()) {
group = groupList.get(0);
log.debug(group.toString());
}
return group;
}
/**
* Gets all INDIGO users from the LDAP server.
*
* @return a {@link List<IndigoUser>} with the LDAP user information
*/ */
public List<IndigoUser> getIndigoUsers() { public List<IndigoUser> getIndigoUsers() {
List<IndigoUser> userList = ldapUser.getAllUsers(); List<IndigoUser> userList = ldapIndigoUser.getAllUsers();
for (int i = 0; i < userList.size(); i++) for (int i = 0; i < userList.size(); i++)
log.debug("User {}", ((IndigoUser) userList.get(i)).toString()); log.debug("User {}", ((IndigoUser) userList.get(i)).toString());
...@@ -140,12 +170,25 @@ public class LdapClient { ...@@ -140,12 +170,25 @@ public class LdapClient {
} }
/** /**
* Gets all groups from the LDAP server. * Gets all POSIX users from the LDAP server.
*
* @return a {@link List<PosixUser>} with the LDAP user information
*/
public List<PosixUser> getPosixUsers() {
List<PosixUser> userList = ldapPosixUser.getAllUsers();
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.
* *
* @return a {@link List<GroupDTO>} with the LDAP group information * @return a {@link List<PosixGroup>} with the LDAP group information
*/ */
public List<PosixGroup> getPosixGroups() { public List<PosixGroup> getPosixGroups() {
List<PosixGroup> groupList = ldapGroup.getAllGroups(); List<PosixGroup> groupList = ldapPosixGroup.getAllGroups();
for (int i = 0; i < groupList.size(); i++) for (int i = 0; i < groupList.size(); i++)
log.debug("Group {}", ((PosixGroup) groupList.get(i)).toString()); log.debug("Group {}", ((PosixGroup) groupList.get(i)).toString());
...@@ -153,7 +196,7 @@ public class LdapClient { ...@@ -153,7 +196,7 @@ public class LdapClient {
} }
/** /**
* Creates a new LDAP INDIGO POSIX user. * Creates a new LDAP INDIGO user.
* *
* @param uid * @param uid
* the user's uid * the user's uid
...@@ -175,8 +218,9 @@ public class LdapClient { ...@@ -175,8 +218,9 @@ public class LdapClient {
* the user's login shell * the user's login shell
* @param userPassword * @param userPassword
* the user's password * the user's password
* @return the created {@link IndigoUser}
*/ */
public void createIndigoUser(String uid, String cn, String sn, String indigoId, int uidNumber, int gidNumber, public IndigoUser createIndigoUser(String uid, String cn, String sn, String indigoId, int uidNumber, int gidNumber,
String homeDirectory, String description, String gecos, String loginShell, String userPassword) { String homeDirectory, String description, String gecos, String loginShell, String userPassword) {
IndigoUser user = new IndigoUser(); IndigoUser user = new IndigoUser();
user.setCommonName(cn); user.setCommonName(cn);
...@@ -189,12 +233,15 @@ public class LdapClient { ...@@ -189,12 +233,15 @@ public class LdapClient {
user.setUidNumber(uidNumber); user.setUidNumber(uidNumber);
user.setHomeDirectory(homeDirectory); user.setHomeDirectory(homeDirectory);
user.setLoginShell(loginShell); user.setLoginShell(loginShell);
user.setUserPassword(userPassword); if (userPassword != null)
ldapUser.insertUser(user); user.setUserPassword(userPassword.getBytes());
ldapIndigoUser.insertUser(user);
return user;
} }
/** /**
* Updates a specific LDAP POSIX user. * Updates a specific LDAP INDIGO user.
* *
* @param uid * @param uid
* the user's uid * the user's uid
...@@ -216,8 +263,9 @@ public class LdapClient { ...@@ -216,8 +263,9 @@ public class LdapClient {
* the user's login shell * the user's login shell
* @param userPassword * @param userPassword
* the user's password * the user's password
* @return the updated {@link IndigoUser}
*/ */
public void updateIndigoUser(String uid, String cn, String sn, String indigoId, int uidNumber, int gidNumber, public IndigoUser updateIndigoUser(String uid, String cn, String sn, String indigoId, int uidNumber, int gidNumber,
String homeDirectory, String description, String gecos, String loginShell, String userPassword) { String homeDirectory, String description, String gecos, String loginShell, String userPassword) {
IndigoUser user = new IndigoUser(); IndigoUser user = new IndigoUser();
user.setCommonName(cn); user.setCommonName(cn);
...@@ -230,8 +278,11 @@ public class LdapClient { ...@@ -230,8 +278,11 @@ public class LdapClient {
user.setUidNumber(uidNumber); user.setUidNumber(uidNumber);
user.setHomeDirectory(homeDirectory); user.setHomeDirectory(homeDirectory);
user.setLoginShell(loginShell); user.setLoginShell(loginShell);
user.setUserPassword(userPassword); if (userPassword != null)
ldapUser.updateUser(user); user.setUserPassword(userPassword.getBytes());
ldapIndigoUser.updateUser(user);
return user;
} }
/** /**
...@@ -243,7 +294,19 @@ public class LdapClient { ...@@ -243,7 +294,19 @@ public class LdapClient {
public void deleteUser(String uid) { public void deleteUser(String uid) {
IndigoUser user = new IndigoUser(); IndigoUser user = new IndigoUser();
user.setUid(uid); user.setUid(uid);
ldapUser.deleteUser(user); ldapPosixUser.deleteUser(user);
}
/**
* Deletes a specific INDIGO LDAP user.
*
* @param uid
* the user's uid
*/
public void deleteIndigoUser(String uid) {
IndigoUser user = new IndigoUser();
user.setUid(uid);
ldapIndigoUser.deleteUser(user);
} }
/** /**
...@@ -257,15 +320,19 @@ public class LdapClient { ...@@ -257,15 +320,19 @@ public class LdapClient {
* group's description * group's description
* @param the * @param the