0

Well, I have a secured rest service just using the spring-security with static credentials 'user' and 'password'. When I consume the rest service shows the login dialog on the browser, that works fine.

The issue comes up when I want to consume my service using a web application using spring, I don't know how to proceed with that, I appreciate any solution, i'm kind of new in Spring, and I don't know if I have to add some method in my rest service or there is just a way to send the credentials from the webapp.

This is my security config for my rest service.

@Configuration
@Order(value = SecurityProperties.ACCESS_OVERRIDE_ORDER)
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    private AuthenticationProvider authenticationProvider;
    protected void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.authenticationProvider(authenticationProvider);
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests().anyRequest()
            .fullyAuthenticated().and().formLogin().permitAll();
    }
}

Im trying to consume the services using angular service:

restwebapp.controller('restController', function($scope, Servicio){
    Servicio.GetGreeting.get({}, function(response){
        $scope.hello = response;
    });
})

restwebapp.factory('Servicio', function($resource){
    return{
        GetGreeting: $resource( 'http://localhost:8080/greeting', {}, {
        get:{   

            method:'GET', 
        }
        })
    }
})

The service returns the fromlogin in a json format, is there another way to authenticate to my rest service, or what is better way.

Thanks in advance

Zayn Korai
  • 493
  • 1
  • 6
  • 24
Diego Bascans
  • 1,083
  • 1
  • 6
  • 14

1 Answers1

0

For a simple basic authentication without form, you can try this:

@Override
protected void configure(HttpSecurity http) throws Exception {
     http
         .authorizeRequests().anyRequest()
         .fullyAuthenticated().and().httpBasic();
}