Commit a887be1d authored by benjamin.ertl's avatar benjamin.ertl

fix ssl

parent c0c2dcd4
......@@ -22,6 +22,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
......@@ -62,6 +64,13 @@ public class RestServiceController {
@Autowired
private LdapClient ldapClient;
@RequestMapping(path = "/oauth2")
@ResponseBody
public String oauth2Authentication(@RequestParam(value = "code") String code) {
log.debug(code);
return code;
}
// expected body e.g.
// password=password
// password=https%3A%2F%2F512eebd9%3Fk%3D49806e48a5cd2941604eb9dfe321c3bc
......
......@@ -113,4 +113,25 @@ public class LdapClient {
return groupList;
}
/**
* Creates a new LDAP user.
*
* @param uid
* the user's uid
* @param cn
* the user's common name
* @param sn
* the user's sure name
* @param description
* the user's description
*/
public void createUser(String uid, String cn, String sn, String description) {
UserDTO user = new UserDTO();
user.setCommonName(cn);
user.setDescription(description);
user.setLastName(sn);
user.setUid(uid);
ldapUser.insertUser(user);
}
}
......@@ -71,7 +71,7 @@ public class LdapGroupDAO implements GroupDAO {
newGroupDN = new LdapName(groupBase);
newGroupDN.add("cn=" + groupDTO.getCommonName());
log.debug(newGroupDN.toString());
// ldapTemplate.bind(newUserDN, null, personAttributes);
ldapTemplate.bind(newGroupDN, null, posixGroupAttributes);
} catch (InvalidNameException e) {
e.printStackTrace();
}
......@@ -92,7 +92,7 @@ public class LdapGroupDAO implements GroupDAO {
newGroupDN = new LdapName(groupBase);
newGroupDN.add("cn=" + groupDTO.getCommonName());
log.debug(newGroupDN.toString());
// ldapTemplate.bind(newUserDN, null, personAttributes);
ldapTemplate.bind(newGroupDN, null, posixGroupAttributes);
} catch (InvalidNameException e) {
e.printStackTrace();
}
......@@ -105,7 +105,7 @@ public class LdapGroupDAO implements GroupDAO {
newGroupDN = new LdapName(groupBase);
newGroupDN.add("cn=" + groupDTO.getCommonName());
log.debug(newGroupDN.toString());
// ldapTemplate.unbind(newUserDN);
ldapTemplate.unbind(newGroupDN);
} catch (InvalidNameException e) {
e.printStackTrace();
}
......
......@@ -44,13 +44,13 @@ public class LdapUserDAO implements UserDAO {
@Override
public List<UserDTO> getAllUsers() {
return ldapTemplate.search(userBase, "(objectclass=person)", new UserAttributeMapper());
return ldapTemplate.search(userBase, "(objectclass=inetOrgPerson)", new UserAttributeMapper());
}
@Override
public List<UserDTO> getUserDetails(String uid) {
AndFilter andFilter = new AndFilter();
andFilter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", uid));
andFilter.and(new EqualsFilter("objectclass", "inetOrgPerson")).and(new EqualsFilter("uid", uid));
log.debug("LDAP query {}", andFilter.encode());
return ldapTemplate.search("", andFilter.encode(), new UserAttributeMapper());
......@@ -59,7 +59,7 @@ public class LdapUserDAO implements UserDAO {
@Override
public void insertUser(UserDTO userDTO) {
BasicAttribute personBasicAttribute = new BasicAttribute("objectclass");
personBasicAttribute.add("person");
personBasicAttribute.add("inetOrgPerson");
Attributes personAttributes = new BasicAttributes();
personAttributes.put(personBasicAttribute);
......@@ -73,7 +73,7 @@ public class LdapUserDAO implements UserDAO {
newUserDN = new LdapName(userBase);
newUserDN.add("uid=" + userDTO.getUid());
log.debug(newUserDN.toString());
// ldapTemplate.bind(newUserDN, null, personAttributes);
ldapTemplate.bind(newUserDN, null, personAttributes);
} catch (InvalidNameException e) {
// TODO Auto-generated catch block
e.printStackTrace();
......@@ -83,20 +83,21 @@ public class LdapUserDAO implements UserDAO {
@Override
public void updateUser(UserDTO userDTO) {
BasicAttribute personBasicAttribute = new BasicAttribute("objectclass");
personBasicAttribute.add("person");
personBasicAttribute.add("inetOrgPerson");
Attributes personAttributes = new BasicAttributes();
personAttributes.put(personBasicAttribute);
personAttributes.put("cn", userDTO.getCommonName());
personAttributes.put("sn", userDTO.getLastName());
personAttributes.put("description", userDTO.getDescription());
personAttributes.put("uid", userDTO.getUid());
LdapName newUserDN = LdapUtils.emptyLdapName();
try {
newUserDN = new LdapName(userBase);
newUserDN.add("uid=" + userDTO.getCommonName());
newUserDN.add("uid=" + userDTO.getUid());
log.debug(newUserDN.toString());
// ldapTemplate.rebind(newUserDN, null, personAttributes);
ldapTemplate.rebind(newUserDN, null, personAttributes);
} catch (InvalidNameException e) {
// TODO Auto-generated catch block
e.printStackTrace();
......@@ -108,9 +109,9 @@ public class LdapUserDAO implements UserDAO {
LdapName newUserDN = LdapUtils.emptyLdapName();
try {
newUserDN = new LdapName(userBase);
newUserDN.add("uid=" + userDTO.getCommonName());
newUserDN.add("uid=" + userDTO.getUid());
log.debug(newUserDN.toString());
// ldapTemplate.unbind(newUserDN);
ldapTemplate.unbind(newUserDN);
} catch (InvalidNameException e) {
// TODO Auto-generated catch block
e.printStackTrace();
......
......@@ -33,4 +33,9 @@ public class LdapClientTest {
public void getLdapUsersTest() {
ldapClient.getLdapUsers();
}
@Test
public void createLdapUserTest() {
ldapClient.createUser("newUser", "newUser", "newUser", "newUser");
}
}
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