相关疑难解决方法(0)

Spring Boot:使用Spring Social和Spring Security保护RESTful API

我正在尝试使用Spring Boot定义和保护RESTful API.理想情况下,我想使用Spring Social并允许客户(网络和移动)通过Facebook登录.

什么工作

到目前为止,我设法使用一个有效的API @RestController并使用基本的Spring Security配置对其进行保护,如下所示:

@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .csrf().disable()
            .authorizeRequests()
                .antMatchers(HttpMethod.POST, "/api/**").authenticated()
                .antMatchers(HttpMethod.PUT, "/api/**").authenticated()
                .antMatchers(HttpMethod.DELETE, "/api/**").authenticated()
                .anyRequest().permitAll()
            .and().httpBasic()
            .and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
    }
}
Run Code Online (Sandbox Code Playgroud)

antMatchers很可能得到改善,但我做了这样的我自己清晰现在,它工作正常.允许执行GET请求,并且所有其他请求都需要user:password在运行时发送Spring Security提供的标准.使用示例httpie:

http POST user:a70fd629-1e29-475d-aa47-6861feb6900f@localhost:8080/api/ideas/ title="My first idea"
Run Code Online (Sandbox Code Playgroud)

哪个权利凭据,它发200 OK回一个,否则一个401 Unauthorized.

春天社交

现在,我陷入困境,无法使用我的头脑来使用Spring-Social-Facebook我当前的设置并保持完全RESTful控制器.使用标准表单和重定向似乎微不足道,但我找不到任何基于REST的方法的解决方案,例如可以轻松支持Web和移动客户端.

据我了解,客户端必须处理流程,因为后端不会向/connect/facebookURL 发送任何重定向.

  • 我按照教程访问Facebook数据,它自己工作.但是,我想避免必须拥有教程中的那些facebookConnect.htmlfacebookConnected.html模板.所以我不知道如何改变它.

  • OAuth的另一个 …

spring spring-security spring-social spring-boot spring-restcontroller

9
推荐指数
1
解决办法
2541
查看次数

Spring社交身份验证过滤器,用于使用Facebook令牌进行身份验证的无状态REST端点

我想Facebook Tokens用来验证我的REST后端Spring Security.能否详细说明如何将此安全性集成到我的Spring应用程序中.

我想使用与Spring Social Security相同的用户管理.UserConnection表和本地用户表.

rest spring facebook spring-security spring-social-facebook

6
推荐指数
1
解决办法
4633
查看次数