Commit 765c98cb authored by Spiros Koulouzis's avatar Spiros Koulouzis

null check

parent 0c2670b1
......@@ -59,11 +59,11 @@ public class KeyPairService {
return k;
}
public KeyPair save(KeyPair upk) {
public KeyPair save(KeyPair keyPair) {
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String owner = user.getUsername();
upk.setOwner(owner);
return dao.save(upk);
keyPair.setOwner(owner);
return dao.save(keyPair);
}
@PostAuthorize("(hasRole('ROLE_ADMIN'))")
......
......@@ -108,7 +108,7 @@ public class KeyPairController {
@ResponseCode(code = 400, condition = "Key can't be empty")
})
public @ResponseBody
String postKey(@RequestBody KeyPair pair) {
String postKeyPair(@RequestBody KeyPair pair) {
if (pair.getPrivateKey() == null && pair.getPublicKey() == null) {
throw new NullKeyException();
}
......
......@@ -42,7 +42,7 @@ public class KeyPair extends OwnedObject {
* @throws nl.uva.sne.drip.api.exception.KeyException
*/
public void setPrivateKey(Key privateKey) throws KeyException {
if (privateKey.getType() != Key.KeyType.PRIVATE) {
if (privateKey != null && privateKey.getType() != Key.KeyType.PRIVATE) {
throw new KeyException("Trying to add public key to private");
}
this.privateKey = privateKey;
......@@ -60,7 +60,7 @@ public class KeyPair extends OwnedObject {
* @throws nl.uva.sne.drip.api.exception.KeyException
*/
public void setPublicKey(Key publicKey) throws KeyException {
if (privateKey.getType() != Key.KeyType.PUBLIC) {
if (publicKey != null && publicKey.getType() != Key.KeyType.PUBLIC) {
throw new KeyException("Trying to add private to public");
}
this.publicKey = publicKey;
......
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