小编Joe*_*oey的帖子

使用OAuth2保护REST API:创建名为"scopedTarget.oauth2ClientContext"的bean时出错:范围"会话"未激活

我已经工作了几天,试图在REST API上实现oauth2保护.我已经尝试了很多不同的配置,但仍然没有设法让它工作.

我正在证明我现在的代码,但我与这个实现没有任何结合.如果你能告诉我一些完全不同的方式来实现我想要完成的目标,那就太好了.

我的流程如下:

  1. 客户端检查Auth Server,获取令牌.
  2. 客户端将令牌发送到Resource Server.
  3. Resource Server使用Auth Server确保令牌有效.

Auth服务器运行正常.我在配置资源服务器时遇到问题.

资源服务器上的配置

这是我的一些配置.我有这个豆子:

誓言模板

@EnableOAuth2Client
@Configuration
@Import({PropertiesConfig.class}) //Imports properties from properties files.
public class OauthRestTemplateConfig {



 @Bean
    public OAuth2RestTemplate oAuth2RestTemplate(OAuth2ClientContext oauth2ClientContext) {
        OAuth2RestTemplate template = new OAuth2RestTemplate(oauth2ResourceDetails(), oauth2ClientContext);
        return template;
    }

    @Bean
    OAuth2ProtectedResourceDetails oauth2ResourceDetails() {
        AuthorizationCodeResourceDetails details = new AuthorizationCodeResourceDetails();
        details.setId("theOauth");
        details.setClientId("clientID");
        details.setClientSecret("SecretKey");
        details.setAccessTokenUri("https://theAuthenticationServer.com/oauthserver/oauth2/token");
        details.setUserAuthorizationUri("https://theAuthenticationServer.com/oauthserver/oauth2/token");
        details.setTokenName("oauth_token");
        details.setPreEstablishedRedirectUri("http://localhost/login");
        details.setUseCurrentUri(true);
        return details;
    }
}
Run Code Online (Sandbox Code Playgroud)

安全配置

我在Resource Server的主安全配置中使用该bean:

@Slf4j
@Configuration
@EnableWebSecurity
@EnableOAuth2Client
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, jsr250Enabled = true, proxyTargetClass …
Run Code Online (Sandbox Code Playgroud)

spring spring-security spring-security-oauth2

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

Java 11:导入 javax.xml.ws.WebFault:“无法解析符号 ws”

我正在尝试将服务升级到 Java 11。

我们目前使用 wsdl2java (Apache CXF) 来生成基于 WSDL 的源代码。我正在通过 Maven 完成这一切。源文件根据 wsdl 正确生成。

不幸的是,生成的一些源文件包括以下导入:

import javax.xml.ws.WebFault; 
import javax.jws.WebService;
Run Code Online (Sandbox Code Playgroud)

我缺少包 javax.xml.ws 和 javax.jws。

在我的研究中,我发现 Jaxb 从主 JDK 中被弃用,因此我需要在我的 pom.xml 文件中添加新的依赖项。我尝试了各种组合,但它们都归结为:

    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.0</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>jaxb-core</artifactId>
        <version>2.3.0.1</version>
    </dependency>

    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>2.3.0</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>jaxb-runtime</artifactId>
        <version>2.3.2</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

不幸的是,无论我做什么,我的 IDE 似乎都找不到 javax.xml.ws 和 javax.jws。

有谁知道我可能需要包含哪些依赖项才能获得这些包?

虽然它不是问题的核心,但这是我的 wsdl2java 内容:

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <version>3.3.2</version>
    <executions>
        <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <configuration>
                <sourceRoot>${project.build.directory}/generated-sources/cxf/</sourceRoot>

                <wsdlRoot>src/main/webapp/resources/wsdl/fedex</wsdlRoot>
                <includes>
                    <include>**/*.wsdl</include>
                </includes>
            </configuration>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
        </execution>
    </executions> …
Run Code Online (Sandbox Code Playgroud)

java wsdl wsdl2java jaxb java-11

7
推荐指数
1
解决办法
7313
查看次数

如果进行单个同步调用,Webflux 会发生什么?

我开始在 Spring Boot 中使用 Webflux 进入反应式 Java 编程的世界。

我遇到了一种情况,在这种情况下,很难被动地执行某个数据库调用。

如果我在 Mono 中执行单个阻塞数据库调用,会发生什么?

代码看起来像这样......

public Mono<ReturnThing> isThisAsyncOrNot() {
    //Async, non-blocking API call
    return webClient.doSomeAPIWork()
                     .flatMap(whatevers -> {
                         //Synchronous, blocking database call
                         ReturnThing returnThing= returnThingRepo.getByWhateverId(whatever.ID);
                         }
                         return returnThing;
                     });
}
Run Code Online (Sandbox Code Playgroud)

现在是的,我知道有一种简单的方法可以被动地做到这一点。这不是我要问的问题(实际上,真正的代码要复杂得多)。

我真正想知道的是同步数据库调用会对我的性能产生什么影响。整个方法是否仍然是异步非阻塞的(除了在进行 db 调用的部分,这是阻塞的)?或者这会以某种方式破坏整个反应式范式并导致整个事情,开始到结束,阻塞?

java reactive-programming project-reactor spring-webflux

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

将日期保存到 Room 数据库时,TypeConverter 会打乱数据

我已经为此工作了几个小时,但我似乎无法弄清楚如何将日期保存到我的 Room Sqllite 数据库中。我基本上是从 Android 文档中复制代码来进行批量处理。

这就是我所拥有的。

数据库:

@Database(entities = {Review.class},
        version = 3,
        exportSchema=false)
@TypeConverters(DateTypeConverter.class)
public abstract class NotecardDatabase extends RoomDatabase {
...etc...
}
Run Code Online (Sandbox Code Playgroud)

实体:

    @Entity(tableName = "review",
        indices = {
                @Index(value = "next_review"),
        }
public class Review {
...Other columns...
    @TypeConverters(DateTypeConverter.class)
    @ColumnInfo(name ="next_review")
    @NonNull
    private Date nextReview;
}
Run Code Online (Sandbox Code Playgroud)

接下来,我的转换器:

public class DateTypeConverter {

    private static Logger log = Logger.getLogger("DateTypeConverter");
    @TypeConverter
    public static Date fromTimestamp(Long value) {
        if(value != null) {
            log.info("Incoming long: " + value + "\nTo Date: …
Run Code Online (Sandbox Code Playgroud)

java sqlite android android-room

0
推荐指数
1
解决办法
5639
查看次数