gpt4 book ai didi

java - 在 Java Swing 应用程序中实现 Spring Security

转载 作者:行者123 更新时间:2023-12-04 05:24:37 24 4
gpt4 key购买 nike

你们中有人清楚我如何实现这个过程吗?我知道我们需要一个 XML,我们可以在其中对数据库进行查询,如下所示:

<security:authentication-manager>
<security:authentication-provider >
<security:jdbc-user-service data-source-ref="dataSource"
users-by-username-query="
select emailid username,password,'true' enabled from tbl_LoginDetails
where emailid=?"
authorities-by-username-query="
select a.emailid username,b.authority from tbl_LoginDetails a,tbl_UserRoles b
where a.userId=b.userId
and a.emailid=?"/>
<security:password-encoder ref="passwordEncoder">
</security:password-encoder>
</security:authentication-provider>
</security:authentication-manager>
<bean name="passwordEncoder" class="org.springframework.security.authentication.encoding.ShaPasswordEncoder">

但是,我还需要从 Java Swing 应用程序中做些什么。我的意思是:我有一个带有两个文本框的窗口,用于输入用户和密码。我还需要做什么?

最佳答案

如果要在 Swing 应用程序中使用 Spring Security,则需要使用 GlobalSecurityContextHolderStrategy在您的 SecurityContextHolder .

A static field-based implementation of SecurityContextHolderStrategy. This means that all instances in the JVM share the same SecurityContext. This is generally useful with rich clients, such as Swing.



查看 SecurityContextHolder 的 Java 文档了解如何配置:

Associates a given SecurityContext with the current execution thread. This class provides a series of static methods that delegate to an instance of SecurityContextHolderStrategy. The purpose of the class is to provide a convenient way to specify the strategy that should be used for a given JVM. This is a JVM-wide setting, since everything in this class is static to facilitate ease of use in calling code. To specify which strategy should be used, you must provide a mode setting. A mode setting is one of the three valid MODE_ settings defined as static final fields, or a fully qualified classname to a concrete implementation of SecurityContextHolderStrategy that provides a public no-argument constructor. There are two ways to specify the desired strategy mode String. The first is to specify it via the system property keyed on SYSTEM_PROPERTY. The second is to call setStrategyName(String) before using the class. If neither approach is used, the class will default to using MODE_THREADLOCAL, which is backwards compatible, has fewer JVM incompatibilities and is appropriate on servers (whereas MODE_GLOBAL is definitely inappropriate for server use).

关于java - 在 Java Swing 应用程序中实现 Spring Security,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13336418/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com