简体   繁体   English

REST无法在Spring Boot中控制URL吗? 排除网址?

[英]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. 我在某些地方使用了一些Angular ui路由,并且希望Java服务器不控制某些url。

Perhaps it makes more sense to run the java app elsewhere? 也许在其他地方运行Java应用程序更有意义? The reason I have the angularJS in the same url is because there are some authentication checks for my springboot app. 我在相同的URL中有angularJS的原因是因为对springboot应用程序进行了一些身份验证检查。 So I want most URLs controlled. 因此,我希望控制大多数URL。

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. 我认为我的问题是我的Spring Boot代码正在尝试使用Velocity,而其中某些URL应该只转发到AngularJS路由。

So a URL=/myreport/ 因此,URL = / myreport /

--> goes to Java 404 error, instead of just forwarding to Angular UI Routing ->转到Java 404错误,而不仅仅是转发到Angular UI Routing

--> But in some cases, Java should return 404/500/403 et al ->但在某些情况下,Java应该返回404/500/403等

Is there a way to do like a RestController that just forwards to AngularJS after authenticating? 有没有办法像RestController一样在身份验证后转发到AngularJS? 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. 如果将Spring Boot代码限制为仅进行身份验证和提供API,并在Angular应用中实现所有UI,则可能会更直接。

You can then still use Spring Security to control access to the API. 然后,您仍然可以使用Spring Security来控制对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. 在Angular端,您可以在路由中使用AuthGuard,以根据用户角色控制对部分UI的访问。

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. 这样,Angular应用程序可以呈现登录UI,并向Spring Boot应用程序进行REST调用以登录并获取令牌,该令牌将在后续调用中使用。

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. 如果使用JWT,则可以让后端产生一个包含用户角色的令牌,然后在Angular应用程序中读取该令牌。

I recently wrote a 2-part blog post showing how to create an Angular 2 app with a Spring Boot back-end using JWT. 我最近写了一个由两部分组成的博客文章,展示了如何使用JWT使用Spring Boot后端创建Angular 2应用。 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 参见http://chariotsolutions.com/blog/post/angular-2-spring-boot-jwt-cors_part1http://chariotsolutions.com/blog/post/angular-2-spring-boot-jwt-cors_part2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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