Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I have a web application with separate front and back:

/project  
+--- /back
+--- /front

The back is developped using Spring boot + Spring MVC, while the front is using AngularJS.

I am trying to set up the security for the communication between the back/front. What I did:

- create a ConfigSecurity class which extends from WebSecurityConfigurerAdapter
- create a SpringWebMvcInitializer which extends from AbstractAnnotationConfigDispatcherServletInitializer and call ConfigSecurity
- create a SecurityWebInitializer class which extends AbstractSecurityWebApplicationInitializer

My ConfigSecurity looks like this:

@Configuration
@EnableWebMvcSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class ConfigSecurity extends WebSecurityConfigurerAdapter {

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {

    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/demo/**","/home").permitAll()
                .anyRequest().fullyAuthenticated()
                .and()
                .formLogin().loginPage("...")
                .and()
                .httpBasic();
    }
}

My problems:

  1. In configureGlobal(), I can set the username and password to access my protected urls, but how can I do when there is not only one single user? I mean, I want to grant access to all the users that are registered in my database.

  2. Since the back and the front are only communicating with REST (through JSON files), what should be done with formLogin() in ConfigSecurity? By default, Spring Security generates a default login form. I don't need a it in the back of the application since it is the front which is responsible for displaying the loginPage. How can I skip the login page in the back? Maybe by putting the username and password in JSON file the front is sending to the back? Does someone know how it can be done?

I am using Java Configuration for Spring (not XML configuration).
Thank you, I do appreciate your time.

share|improve this question
1  
Please check this tutorial spring.io/blog/2015/01/12/… it should explain how to login from AngularJS application. – kTT Jun 16 '15 at 9:34

You have many options, all of them require quite a lot of code, but most of it is already well implemented around the internet so you just would have to make it fit your needs. You can either go with simplest way which would be http sessions, JSON token or JWT (JSON web token) or anything else.

HTTP Sessions would definitely be the easiest to set up and is well supported by Spring Security out of the box already.

share|improve this answer

Found great help on this baeldung website (even though it is using XML configuration) and this website (using Java configuration).

For global explanation of how Spring security works, this link helps me a lot.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.