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

fix ssl

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