diff --git a/dashboard-web-app/src/main/java/org/inventory/hub/controller/SecurityController.java b/dashboard-web-app/src/main/java/org/inventory/hub/controller/SecurityController.java new file mode 100644 index 0000000..370b052 --- /dev/null +++ b/dashboard-web-app/src/main/java/org/inventory/hub/controller/SecurityController.java @@ -0,0 +1,37 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See LICENSE in the project root for + * license information. + */ + +package org.inventory.hub.controller; + +import java.security.Principal; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +@ResponseBody +public class SecurityController { + + public SecurityController() { + } + + @RequestMapping(value = "/api/username", method = RequestMethod.GET) + public String currentUsername(final Principal principal) { + + System.out.println("======= /api/username ===== "); + String username = new String(); + if (principal != null) + username = principal.getName(); + + System.out.println("username=" + username); + System.out.println("====== success"); + + return username; + } + +} \ No newline at end of file diff --git a/dashboard-web-app/src/main/resources/static/Scripts/usernameCtrl.js b/dashboard-web-app/src/main/resources/static/Scripts/usernameCtrl.js new file mode 100644 index 0000000..8e1181a --- /dev/null +++ b/dashboard-web-app/src/main/resources/static/Scripts/usernameCtrl.js @@ -0,0 +1,24 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See LICENSE in the project root for + * license information. + */ + +'use strict'; +angular.module('inventoryHubApp') + .controller('usernameCtrl', ['$scope', '$location', 'usernameSvc', + function ($scope, $location, usernameSvc) { + $scope.error = ''; + $scope.loadingMessage = ''; + $scope.username = null; + + $scope.fetchUsername = function () { + usernameSvc.getUsername().success(function(results) { + $scope.username = results; + }).error(function (err){ + $scope.error = err; + $scope.loadingMessage = ''; + + }); + }; + }]); diff --git a/dashboard-web-app/src/main/resources/static/Scripts/usernameSvc.js b/dashboard-web-app/src/main/resources/static/Scripts/usernameSvc.js new file mode 100644 index 0000000..68acbd4 --- /dev/null +++ b/dashboard-web-app/src/main/resources/static/Scripts/usernameSvc.js @@ -0,0 +1,15 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See LICENSE in the project root for + * license information. + */ + +'use strict'; +angular.module('inventoryHubApp') + .factory('usernameSvc', ['$http', function ($http) { + return { + getUsername: function(){ + return $http.get('api/username'); + } + }; + }]); diff --git a/dashboard-web-app/src/main/resources/static/index.html b/dashboard-web-app/src/main/resources/static/index.html index 9af1e0a..a62bf6e 100644 --- a/dashboard-web-app/src/main/resources/static/index.html +++ b/dashboard-web-app/src/main/resources/static/index.html @@ -25,6 +25,14 @@ @@ -45,6 +53,8 @@ + +