I am trying to build an application with AngularJS 1.x, Spring Boot REST with Spring Security. Though I have intermediate knowledge on Spring REST itself, I am quite new to AngularJS and Spring Security. I have given the github link of the application I have developed so far. Its in skeletal form still, and nothing is working:

https://github.com/imrnk/touchinghand

I will list down the problems and confusion I am having below:

1) I am using ui-router states to navigate from one state to another. So far I have identified two states: the "login" page and a link from there to "registration" page. Once the user will logged in, she will land to a dashboard. But this dashboard is yet to be created. Now this login.html could be said as the entry point to the application. And when I type localhost:8080/ it should redirect to localhost:8080/login. Now I can see the page is redirecting correctly to the login.html but the templates I am using (login.template.html or register.template.html) inside login.html is not loading... However, when I am running through node js using browsersync, I see the page is loading with all the contents in it.

2) I tried disabling the spring security and then I see the login page is loaded correctly. So I guessed it could be a spring security issue, but what exactly is the issue I couldn't figure out. My HttpSecurity configuration inside the implementation of WebSecurityConfigurerAdapter looks like this:

@Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/", "/login", "/register", "/**/*.css", 
                        "/**/*.js", "/**/**/*.css", "/**/**/*.js",
                        "/**/**/**/*.css", "/**/**/**/*.js", 
                        "/**/**/**/**/*.css", "/**/**/**/**/*.js", "/**/home.html", "**/login.html",
                        "**/**/login.template.html", "**/**/registration.template.html")
                .permitAll().
                regexMatchers("/registration*")
                .permitAll()
                .anyRequest().authenticated()
                .and()
                .formLogin().loginPage("/login").permitAll()
                .and()
                .logout().permitAll();
    }

And my MvcConfig looks like this:

@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {

    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        super.addResourceHandlers(registry);
        registry.addResourceHandler("classpath:/resources/static/css/**")
                .addResourceLocations("classpath:/resources/static/css/");
        registry.addResourceHandler("classpath:/resources/js/**").addResourceLocations("classpath:/resources/js/");
        registry.addResourceHandler("classpath:/resources/static/**")
                .addResourceLocations("classpath:/resources/static/");
        registry.addResourceHandler("classpath:/resources/static/templates/**")
                .addResourceLocations("classpath:/resources/static/templates/");
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        super.addViewControllers(registry);
        registry.addViewController("/").setViewName("forward:/login");
        //registry.addViewController("/login").setViewName("forward:/login");
        registry.addViewController("login.html");
        //registry.addViewController("register").setViewName("registration");
        // registry.addViewController("/registration.html");
        //registry.addViewController("/dashboard").setViewName("dashboard");
        //registry.addViewController("/dashboard.html");
    }

    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("static/");
        resolver.setSuffix(".html");
        registry.viewResolver(resolver);
    }
}

My LoginController class which anotated as @Controller has this:

 @RequestMapping(value={"/"}, method = RequestMethod.GET)
  public String showLogin(Model model){
    model.addAttribute("user", new UserDTO());
    return "/login";
  }

3) I am quite confused between what should be the name of the resolved views and how that could map with the angular templates html.

I suspect, probably I am following a pure REST approach, and hanging in the middle with some aspect of Spring MVC and Spring REST. Introducing Spring Security also increased the problem for now.

I am also attaching the firefox developer network screenshot if that could help

enter image description here

Kindly help me out. Thanks.

share|improve this question
    
Your code looks like a product of random attempts to fix things. Either your ant matchers or file structure is crazy; should be able to achieve that with something similar to antMatchers("/", "/webjars/**", "/img/**", "/css/**", "/js/**", "/index").permitAll(). I would suggest you get the angular side working the way you want and add spring security on to it by starting with the most basic config and build upon it as needed. – ChiefTwoPencils Jan 28 at 18:57
    
Thanks but not much of help. I asked specifically, what should be the relation between the views declared mvc config and the ui states at the angularjs. My file structure is simple for the ui part, all are under main/resources/, the htmls are under static and static/templates – Imran K Jan 29 at 4:50
    
Sorry, I wasn't able to look at your code then so I was making a suggestion not trying to answer your questions. Now that I have I would like to make another suggestion. Make a push to that repo that makes your project able to compile. – ChiefTwoPencils Jan 29 at 17:58

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.