Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何仅使用客户端';什么是身份和秘密?_Java_Spring_Spring Mvc_Spring Security_Spring Security Oauth2 - Fatal编程技术网

Java 如何仅使用客户端';什么是身份和秘密?

Java 如何仅使用客户端';什么是身份和秘密?,java,spring,spring-mvc,spring-security,spring-security-oauth2,Java,Spring,Spring Mvc,Spring Security,Spring Security Oauth2,我正在尝试用Spring配置RESTfulWeb服务,并且已经配置了OAuth。所以我得到了一些需要用户OAuth令牌的页面。然而,我有一些页面是匿名访问的,比如注册或忘记密码 像www.mywebsite.com/api/doStuff[GET/POST]这样的页面需要一个有效的OAuth令牌来保护,但是我如何保护像www.mywebsite.com/api/signup[POST]这样的页面,只使用客户端ID和secret标题授权:Basic[Base64EncodedString] 我不希

我正在尝试用Spring配置RESTfulWeb服务,并且已经配置了OAuth。所以我得到了一些需要用户OAuth令牌的页面。然而,我有一些页面是匿名访问的,比如注册或忘记密码

像www.mywebsite.com/api/doStuff[GET/POST]这样的页面需要一个有效的OAuth令牌来保护,但是我如何保护像www.mywebsite.com/api/signup[POST]这样的页面,只使用客户端IDsecret标题授权:Basic[Base64EncodedString]

我不希望那些“不安全的页面”被任何人访问,但像移动应用程序(iOS/Android)这样的客户端除外

这是我的ResourceServerConfigurerAdapter类中的configure(HttpSecurity)方法

public void configure(HttpSecurity http) throws Exception {
http
    .requestMatchers().antMatchers("/api/**")
.and()
    .authorizeRequests()
    .antMatchers("/api/doStuff", "/api/getOtherStuff").access("#oauth2.hasScope('read') and hasRole('ROLE_USER')")
    .antMatchers("/api/signup").access("#oauth2.isClient()") // Not working like I thought...
.and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}

谢谢你的帮助

如果您想对某些资源使用基本身份验证,最好创建一个单独的筛选链(即新的
websecurityConfigureAdapter
),并在那里设置规则,以便只匹配您希望以这种方式保护的路径