Spring Security i Angular

0

Witam, używam Spring Security z Spring Boot i Angularem, możecie mi poradzić jak skonfigurować Spring Security aby dodać obsługę logowania dla żądań wysyłanych z Angular
moj kod w Angular to:

	$http({
    		  method: 'POST',
    		  url: '/authenticate',
    		  data: { username: $scope.username, password: $scope.password }
    		}).then(function successCallback(response) {
    			console.log("successCallback")
    		  }, function errorCallback(response) {
    			  console.log("errorCallback")
    		  });
    	 

Spring security:

@Override
	protected void configure(AuthenticationManagerBuilder builder) throws Exception {
		builder.inMemoryAuthentication().withUser("user").password("user").roles("USER").and().withUser("admin")
				.password("admin").roles("ADMIN");
	}

@Override
	protected void configure(HttpSecurity http) throws Exception {
          http.formLogin().loginPage("/login").loginProcessingUrl("/authenticate").usernameParameter("username")
				.passwordParameter("password");
       
	}

Póki co przy próbie POST dostaje taki błąd

timestamp: 1459027805130, status: 403, error: "Forbidden",…}
error:"Forbidden"
message:"Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'."
path:"/authenticate"
status:403
timestamp:1459027805130 

Jeśli wyłączę csrf to problem niby znika jednak dalej nie mogę się zalogować. Wygląda to dosyć słabo ale już kilka godzin nad tym siedzę, próbuje różnych konfiguracji i był bym wdzięczny gdyby ktoś mi dał rade jak to naprawić.

Dzięki

0

A co dostajesz po wyłączeniu CSRF? Ten błąd mówi sam za siebie :P

0

obczaj https://spring.io/blog/2015/01/12/the-login-page-angular-js-and-spring-security-part-ii

The other thing we have to do on the server is tell Spring Security to expect the CSRF token in the format that Angular wants to send it back (a header called “X-XRSF-TOKEN” instead of the default “X-CSRF-TOKEN”). We do this by customizing the CSRF filter:

ale ogolnie nie wysylasz tokena w ogole.

a to, ze sie nie da wylogowac po wylaczeniu csrf to juz zupelnie inny problem.

0
 <http>
  <!-- ... -->
  <csrf disabled="true"/>
</http>

1 użytkowników online, w tym zalogowanych: 0, gości: 1