简体   繁体   English

用spring安全性保护移动REST Api是否足够?

[英]Securing mobile REST Api with spring Security enough?

I'm planing to make a little mobile app that will rely on a java (spring-spring mvc) rest API. 我打算制作一个小型移动应用程序,该应用程序将依赖于Java(spring-spring mvc)rest API。 The API will have paths that look like this for example: API将具有如下所示的路径:

/rest/account POST (will create a new account (account is composed of a username+pass+email) / rest / account POST(将创建一个新帐户(帐户由用户名+密码+电子邮件组成)

/rest/photo/like for example that modify behaviour and add things to the DB... / rest / photo /例如,例如修改行为并将其添加到数据库中...

I'm also planing to use Spring Security to handle the authentication/authorisation. 我还计划使用Spring Security来处理身份验证/授权。 So the mobile app before to make any authorise call (for example to /rest/photo/like) it will have to login (so the basically to /security_check?j_username=username&password 因此,移动应用程序在进行任何授权调用(例如/ rest / photo / like)之前,必须先登录(因此基本上是/ security_check?j_username = username&password

And from now on every request will have to include the JSESSIONID in the cookie. 从现在开始,每个请求都必须在cookie中包含JSESSIONID。

My question is, is this secure enough? 我的问题是,这足够安全吗? Do I have to use OAUTH2? 我必须使用OAUTH2吗? Or is it overkill? 还是过度杀伤力?

Bonus question: As you don't need to be authenticated to make the /rest/account call to create an account, what is the best way to avoid that a user create 1000000 accounts ?? 奖励问题:由于不需要通过身份验证就可以创建帐户来进行/ rest / account调用,因此避免用户创建1000000个帐户的最佳方法是什么? Apache/ip-filter? 阿帕奇/ IP过滤器? Or should I handle this in some interceptor in spring-mvc ? 还是应该在spring-mvc中的某些拦截器中处理此问题?

1) Yes, from your requirements description I will say Spring Security will do fine. 1)是的,从您的需求描述中,我会说Spring Security会很好。 (REST services are usually stateless instead of using sessions, but Spring Security can handle both.) (REST服务通常是无状态的,而不是使用会话,但是Spring Security可以处理这两种情况。)

2) You don't need to use OAuth2 unless you want to pull information from user's Google or Facebook account or something like that. 2)除非您要从用户的Google或Facebook帐户等中提取信息,否则无需使用OAuth2。

3) The bonus question is not trivial. 3)奖金问题并非无关紧要。 A common way is to use a CAPTCHA . 一种常见的方法是使用CAPTCHA You could use OAuth to for example limit the user to one account for every Google/Facebook/X account they have. 例如,您可以使用OAuth将用户拥有的每个Google / Facebook / X帐户限制为一个帐户。

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

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