小编Cen*_*nul的帖子

无法获取EnableOauth2Sso工作 - BadCredentialsException:无法获取访问令牌

我正在尝试使用简单的Spring OAuth2 SSO应用程序,但我无法这样做.以下是发生的事情的步骤和结果:

  1. 命中端点/user,由OAuth2保护
  2. 我被转发到一个简单的Spring OAuth2授权服务器
  3. 我向授权服务器进行身份验证
  4. 我批准了访问权限
  5. 然后,我在OAuth2 SSO应用程序上获得了一个白标错误页面,其中包含以下内容:

    Whitelabel Error Page
    
    This application has no explicit mapping for /error, so you are seeing this as a fallback.
    
    Mon Jul 13 08:19:18 EDT 2015
    There was an unexpected error (type=Unauthorized, status=401).
    Authentication Failed: Could not obtain access token
    
    Run Code Online (Sandbox Code Playgroud)

授权码位于URL中.以下是示例网址:

http://localhost:8083/login?code=9s63rU&state=Fo9S2M
Run Code Online (Sandbox Code Playgroud)

我没有看到HTTP POST授权服务器/oauth/token端点获取JWT.我通过/trace授权服务器上的端点验证了这一点.

异常堆栈是:

2015-07-13 08:23:32.695 DEBUG 3516 --- [nio-8083-exec-7] o.s.s.w.u.matcher.AntPathRequestMatcher  : Checking match of request : '/login'; against '/css/**'
2015-07-13 08:23:32.695 …
Run Code Online (Sandbox Code Playgroud)

spring spring-security spring-boot spring-security-oauth2 spring-cloud

26
推荐指数
1
解决办法
1万
查看次数

Spring Boot @ConfigurationProperties不从环境中检索属性

我正在使用Spring Boot 1.2.1并尝试@ConfigurationProperties使用如下验证创建一个bean:

package com.sampleapp;

import java.net.URL;

import javax.validation.constraints.NotNull;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties
public class SampleAppProperties {
    @NotNull
    private URL url;

    public URL getUrl() {
        return url;
    }
}
Run Code Online (Sandbox Code Playgroud)

引导应用程序的类是:

package com.sampleapp;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;

@SpringBootApplication
@EnableConfigurationProperties
public class SampleApplication implements EnvironmentAware {
    private static Logger LOGGER = LoggerFactory.getLogger(SampleApplication.class);

    public static void main(String[] args) {
        SpringApplication.run(SampleApplication.class, args);
    }

    @Override
    public void setEnvironment(Environment environment) {
        LOGGER.info("URL …
Run Code Online (Sandbox Code Playgroud)

java spring spring-boot

12
推荐指数
2
解决办法
2万
查看次数

如何解密@ConfigurationProperties bean中使用的属性?

我正在使用Spring Boot 1.2.3,我想了解是否可以在将属性值注入带注释的bean之前对其进行解密@ConfigurationProperties.

假设我在application.properties文件中有以下内容:

appprops.encryptedProperty=ENC(ENCRYPTEDVALUE)

和这样的示例应用程序:

package aaa.bb.ccc.propertyresearch;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;

import javax.annotation.PostConstruct;

@SpringBootApplication
@EnableConfigurationProperties(PropertyResearchApplication.ApplicationProperties.class)
public class PropertyResearchApplication {

    public static void main(String[] args) {
        SpringApplication.run(PropertyResearchApplication.class, args);
    }

    @ConfigurationProperties("appprops")
    public static class ApplicationProperties {
        private String encryptedProperty;

        @PostConstruct
        public void postConstruct() throws Exception {
            System.out.println("ApplicationProperties --> appprops.encryptedProperty = " + encryptedProperty);
        }

        public String getEncryptedProperty() {
            return encryptedProperty;
        }

        public void setEncryptedProperty(String encryptedProperty) {
            this.encryptedProperty = encryptedProperty;
        }
    }
} …
Run Code Online (Sandbox Code Playgroud)

java encryption spring spring-boot

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

使用 Spring Boot 和 Netflix Zuul 的简单反向代理

我正在寻找使用 Spring Boot 实现一个简单的反向代理,即:

  • 轻松添加路线
  • 能够在每个路由的基础上添加自定义身份验证
  • 根据需要添加其他标头

我查看了注释提供的功能@EnableZuulProxy,但它似乎太重量级了,因为我不想使用 Eureka、Ribbon 或 Hystrix。然而,@EnableZuulServer配置有点轻。

有人能提供一个我所追求的例子吗?Netflix Zuul 是正确的选择吗?还是还有其他我应该考虑的库?

谢谢!

netflix spring-boot spring-cloud netflix-zuul

5
推荐指数
1
解决办法
2万
查看次数