简体   繁体   中英

Don't REST control a URL in Spring Boot? Exclude url?

I am using some angular ui routing in some places, and I wanted the java server to not control some of the urls.

Perhaps it makes more sense to run the java app elsewhere? The reason I have the angularJS in the same url is because there are some authentication checks for my springboot app. So I want most URLs controlled.

But there's a few where I may want to control the authentication----but not the templating.

I think my problem is my Spring Boot code is trying to use velocity, when some of those URLs should just forward to AngularJS routing.

So a URL=/myreport/

--> goes to Java 404 error, instead of just forwarding to Angular UI Routing

--> But in some cases, Java should return 404/500/403 et al

Is there a way to do like a RestController that just forwards to AngularJS after authenticating? or to disable velocity??

This would probably be more straightforward if you limit your Spring Boot code to just doing authentication and providing an API, and implement all of your UI in the Angular app.

You can then still use Spring Security to control access to the API. On the Angular side, you can use AuthGuards in your routes to control access to parts of your UI based on the user's role.

To get a nice, clean separation, it is helpful to use token-based authentication instead of, say, Form-Based or Basic authentication. That way, the Angular app can present the login UI, and make a REST call to the Spring Boot app to log in, and get a token back, which is used on subsequent calls.

If you use JWT, you can have the back-end produce a token that includes the users' role, and then read that in the Angular app.

I recently wrote a 2-part blog post showing how to create an Angular 2 app with a Spring Boot back-end using JWT. See http://chariotsolutions.com/blog/post/angular-2-spring-boot-jwt-cors_part1 and http://chariotsolutions.com/blog/post/angular-2-spring-boot-jwt-cors_part2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM