Advertisement
Guest User

Untitled

a guest
May 9th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.59 KB | None | 0 0
  1. protected void configure(HttpSecurity http) throws Exception {
  2. http
  3. .httpBasic()
  4. .and()
  5. .addFilterBefore(new CORSFilter(), ChannelProcessingFilter.class)
  6. .csrf().disable()
  7. .exceptionHandling()
  8. .authenticationEntryPoint(restAuthenticationEntryPoint)
  9. .and()
  10. .authorizeRequests()
  11. .antMatchers("/login").permitAll()
  12. .antMatchers("/ristore/**").authenticated()
  13. .anyRequest().authenticated()
  14. .and()
  15. .formLogin()
  16. .successHandler(authenticationSuccessHandler)
  17. .failureHandler(new SimpleUrlAuthenticationFailureHandler());
  18. }
  19.  
  20. <div class="container" ng-controller="loginCtrl">
  21. <div class="card card-container">
  22. <img id="profile-img" class="profile-img-card" src="//ssl.gstatic.com/accounts/ui/avatar_2x.png" />
  23. <p id="profile-name" class="profile-name-card"></p>
  24. <form class="form-signin" ng-submit="authenticate()">
  25. <input type="text" id="username" class="form-control" ng-model="username" placeholder="username" required autofocus>
  26. <input type="password" id="password" autocomplete="new-password" class="form-control" ng-model="password" placeholder="password" required>
  27. <button class="btn btn-lg btn-primary btn-block btn-signin" type="submit">Sign in</button>
  28. <div ng-show="!authenticated" class="bad-credentials">
  29. <p>Invalid username and/or password!</p>
  30. </div>
  31. </form>
  32. </div>
  33. </div>
  34.  
  35. ristoreApp.controller("loginCtrl",
  36. ['$rootScope', '$scope', '$location', 'loginFactory',
  37. function($rootScope, $scope, $location, loginFactory){
  38. (function initController() {
  39. // reset login status
  40. loginFactory.clearCredentials();
  41. })();
  42. $rootScope.authenticated = true;
  43. $scope.authenticate = function() {
  44. loginFactory.login($scope.username, $scope.password, function(response) {
  45. if (response.status == 200) {
  46. loginFactory.setCredentials($scope.username, $scope.password);
  47. $rootScope.authenticated = true;
  48. $location.path('/home');
  49. } else {
  50. $rootScope.authenticated = false;
  51. $location.path('/login');
  52. }
  53. });
  54. }
  55. }]);
  56.  
  57. .factory("loginFactory", ['Base64', '$http', '$cookieStore', '$rootScope',
  58. function (Base64, $http, $cookieStore, $rootScope) {
  59. var service = {};
  60.  
  61. service.login = function(username, password, callback) {
  62. var credentials = "username="+username+"&password="+password;
  63. var config = {
  64. headers: {'Content-Type': 'application/x-www-form-urlencoded'}
  65. }
  66.  
  67. $http.post(LOGIN_URL, credentials, config)
  68. .then(function(response) {
  69. callback(response);
  70. });
  71. };
  72.  
  73. service.setCredentials = function (username, password) {
  74. var authdata = Base64.encode(username + ':' + password);
  75. $rootScope.globals = {
  76. currentUser: {
  77. username: username,
  78. authdata: authdata,
  79. }
  80. };
  81.  
  82. $cookieStore.put('globals', $rootScope.globals);
  83. };
  84.  
  85. service.clearCredentials = function () {
  86. $rootScope.globals = {};
  87. $cookieStore.remove('globals');
  88. };
  89.  
  90. return service;
  91. }])
  92.  
  93. .factory('Base64', function () {
  94. //omiting code
  95. });
  96.  
  97. .run(['$rootScope', '$location', '$cookieStore', '$http',
  98. function ($rootScope, $location, $cookieStore, $http) {
  99. $rootScope.globals = $cookieStore.get('globals') || {};
  100.  
  101. $rootScope.$on('$locationChangeStart', function (event, next, current) {
  102. if ($location.path() !== '/login' && !$rootScope.globals.currentUser) {
  103. $location.path('/login');
  104. }
  105. });
  106. }
  107.  
  108. .controller("fmCtrl",
  109. ['$scope', 'fmFactory', function($scope, fmFactory) {
  110. $scope.reports = [];
  111. $scope.fmSearch = function() {
  112. fmFactory.getAll().success(function(data){
  113. $scope.reports=data;
  114. });
  115. }]
  116. )
  117.  
  118. .factory("fmFactory", ['$http',
  119. function ($http) {
  120. var service = {};
  121. service.getAll = function () {
  122. var url = SERVER + "/ristore/foundtion/";
  123. return $http({
  124. url: url,
  125. method: 'GET'
  126. })
  127. }
  128. return service;
  129. }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement