fix: checking token for service in findById
@@ -27,13 +27,25 @@ import javax.crypto.NoSuchPaddingException;
import javax.validation.Valid;
import org.openbaton.catalogue.nfvo.NFVImage;
import org.openbaton.catalogue.nfvo.VimInstance;
-import org.openbaton.exceptions.*;
+import org.openbaton.exceptions.AlreadyExistingException;
+import org.openbaton.exceptions.BadFormatException;
+import org.openbaton.exceptions.BadRequestException;
+import org.openbaton.exceptions.EntityUnreachableException;
+import org.openbaton.exceptions.NotFoundException;
+import org.openbaton.exceptions.PluginException;
+import org.openbaton.exceptions.VimException;
import org.openbaton.nfvo.core.interfaces.VimManagement;
import org.openbaton.nfvo.security.interfaces.ComponentManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.PathVariable;
+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.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/v1/datacenters")
@@ -130,11 +142,16 @@ public class RestVimInstances {
@RequestHeader(value = "project-id") String projectId,
@RequestHeader(value = "authorization") String token)
throws IllegalBlockSizeException, NoSuchPaddingException, BadPaddingException,
- NoSuchAlgorithmException, InvalidKeyException, NotFoundException {
+ NoSuchAlgorithmException, InvalidKeyException, NotFoundException, BadFormatException {
VimInstance vimInstance = vimManagement.query(id, projectId);
if (vimInstance == null)
throw new NotFoundException("VIM Instance with ID " + id + " not found.");
- if (!componentManager.isService(token)) vimInstance.setPassword("**********");
+ String[] tokenArray = token.split(" ");
+ if (tokenArray.length < 2) throw new BadFormatException("The passed token has a wrong format.");
+ token = tokenArray[1];
+ if (!componentManager.isService(token)) {
+ vimInstance.setPassword("**********");
+ }
return vimInstance;
}
