Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void configure(HttpSecurity http) throws Exception {
- http
- .httpBasic()
- .and()
- .addFilterBefore(new CORSFilter(), ChannelProcessingFilter.class)
- .csrf().disable()
- .exceptionHandling()
- .authenticationEntryPoint(restAuthenticationEntryPoint)
- .and()
- .authorizeRequests()
- .antMatchers("/login").permitAll()
- .antMatchers("/ristore/**").authenticated()
- .anyRequest().authenticated()
- .and()
- .formLogin()
- .successHandler(authenticationSuccessHandler)
- .failureHandler(new SimpleUrlAuthenticationFailureHandler());
- }
- <div class="container" ng-controller="loginCtrl">
- <div class="card card-container">
- <img id="profile-img" class="profile-img-card" src="//ssl.gstatic.com/accounts/ui/avatar_2x.png" />
- <p id="profile-name" class="profile-name-card"></p>
- <form class="form-signin" ng-submit="authenticate()">
- <input type="text" id="username" class="form-control" ng-model="username" placeholder="username" required autofocus>
- <input type="password" id="password" autocomplete="new-password" class="form-control" ng-model="password" placeholder="password" required>
- <button class="btn btn-lg btn-primary btn-block btn-signin" type="submit">Sign in</button>
- <div ng-show="!authenticated" class="bad-credentials">
- <p>Invalid username and/or password!</p>
- </div>
- </form>
- </div>
- </div>
- ristoreApp.controller("loginCtrl",
- ['$rootScope', '$scope', '$location', 'loginFactory',
- function($rootScope, $scope, $location, loginFactory){
- (function initController() {
- // reset login status
- loginFactory.clearCredentials();
- })();
- $rootScope.authenticated = true;
- $scope.authenticate = function() {
- loginFactory.login($scope.username, $scope.password, function(response) {
- if (response.status == 200) {
- loginFactory.setCredentials($scope.username, $scope.password);
- $rootScope.authenticated = true;
- $location.path('/home');
- } else {
- $rootScope.authenticated = false;
- $location.path('/login');
- }
- });
- }
- }]);
- .factory("loginFactory", ['Base64', '$http', '$cookieStore', '$rootScope',
- function (Base64, $http, $cookieStore, $rootScope) {
- var service = {};
- service.login = function(username, password, callback) {
- var credentials = "username="+username+"&password="+password;
- var config = {
- headers: {'Content-Type': 'application/x-www-form-urlencoded'}
- }
- $http.post(LOGIN_URL, credentials, config)
- .then(function(response) {
- callback(response);
- });
- };
- service.setCredentials = function (username, password) {
- var authdata = Base64.encode(username + ':' + password);
- $rootScope.globals = {
- currentUser: {
- username: username,
- authdata: authdata,
- }
- };
- $cookieStore.put('globals', $rootScope.globals);
- };
- service.clearCredentials = function () {
- $rootScope.globals = {};
- $cookieStore.remove('globals');
- };
- return service;
- }])
- .factory('Base64', function () {
- //omiting code
- });
- .run(['$rootScope', '$location', '$cookieStore', '$http',
- function ($rootScope, $location, $cookieStore, $http) {
- $rootScope.globals = $cookieStore.get('globals') || {};
- $rootScope.$on('$locationChangeStart', function (event, next, current) {
- if ($location.path() !== '/login' && !$rootScope.globals.currentUser) {
- $location.path('/login');
- }
- });
- }
- .controller("fmCtrl",
- ['$scope', 'fmFactory', function($scope, fmFactory) {
- $scope.reports = [];
- $scope.fmSearch = function() {
- fmFactory.getAll().success(function(data){
- $scope.reports=data;
- });
- }]
- )
- .factory("fmFactory", ['$http',
- function ($http) {
- var service = {};
- service.getAll = function () {
- var url = SERVER + "/ristore/foundtion/";
- return $http({
- url: url,
- method: 'GET'
- })
- }
- return service;
- }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement