小编Yan*_*n39的帖子

Spring Security 在没有 WebSecurityConfigurerAdapter 的情况下公开 AuthenticationManager

我正在尝试传入 Spring Boot 2.7.0-SNAPSHOT,它使用 Spring Security 5.7.0,它不推荐使用WebSecurityConfigurerAdapter.

我阅读了这篇博文,但我不确定如何AuthenticationManager向我的 JWT 授权过滤器公开默认实现。

旧的WebSecurityConfig,使用WebSecurityConfigurerAdapter(工作正常):

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

    @Autowired
    private JWTTokenUtils jwtTokenUtils;

    @Bean
    protected AuthenticationManager getAuthenticationManager() throws Exception {
        return authenticationManager();
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                // disable CSRF as we do not serve browser clients
                .csrf().disable()
                // allow access restriction using request matcher
                .authorizeRequests()
                // authenticate requests to GraphQL endpoint
                .antMatchers("/graphql").authenticated() …
Run Code Online (Sandbox Code Playgroud)

java spring spring-security spring-boot

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

为什么在实体上一起使用 @AllArgsConstructor 和 @NoArgsConstructor ?

我在网上看到了有关 IntelliJ 中 Spring Boot 应用程序的多个代码,许多代码同时使用了@AllArgsConstructor@NoArgsConstructor,并且两者都是构造函数,但是每个代码的目的不同 -

  • @AllArgsConstructor为带注释的类中的每个字段生成一个需要参数的构造函数
  • @NoArgsConstructor生成一个不带参数的构造函数

那么为什么我们要在同一个实体上同时使用两者以及它们在这种情况下如何发挥作用?

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Entity
public class Product {
    @Id
    private int id;
    private String name;
    private String type;
}
Run Code Online (Sandbox Code Playgroud)

constructor jpa intellij-plugin lombok spring-boot

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

在构建期间调用 Flutter Provider setState() 或 markNeedsBuild()

我想加载事件列表并在获取数据时显示加载指示器。

我正在尝试提供者模式(实际上是重构一个现有的应用程序)。

因此,事件列表的显示取决于提供程序中管理的状态。

问题是当我打电话notifyListeners()太快时,我得到这个异常:

????????? 基础库捕获的异常 ????????

为 EventProvider 分派通知时抛出以下断言:

在构建期间调用 setState() 或 markNeedsBuild() 。

...

EventProvider 发送通知是:“EventProvider”的实例

??????????????????????????????????????????

在调用notifyListeners()解决问题之前等待几毫秒(请参阅下面提供程序类中的注释行)。

这是一个基于我的代码的简单示例(希望不要过于简化):

主要功能

Future<void> main() async {
    runApp(
        MultiProvider(
            providers: [
                ChangeNotifierProvider(create: (_) => LoginProvider()),
                ChangeNotifierProvider(create: (_) => EventProvider()),
            ],
            child: MyApp(),
        ),
    );
}
Run Code Online (Sandbox Code Playgroud)

根小部件

class MyApp extends StatelessWidget {

    @override
    Widget build(BuildContext context) {
        final LoginProvider _loginProvider = Provider.of<LoginProvider>(context, listen: true);
        final EventProvider _eventProvider = Provider.of<EventProvider>(context, listen: false);

        // load user …
Run Code Online (Sandbox Code Playgroud)

dart flutter flutter-provider

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

具有多个参数的MediatorLiveData或switchMap转换

Transformations.switchMap在我的ViewModel中使用,因此LiveData在我的片段中观察到的我的集合会对code参数的变化做出反应.

这非常有效:

public class MyViewModel extends AndroidViewModel {

    private final LiveData<DayPrices> dayPrices;
    private final MutableLiveData<String> code = new MutableLiveData<>();
    // private final MutableLiveData<Integer> nbDays = new MutableLiveData<>();
    private final DBManager dbManager;

    public MyViewModel(Application application) {
        super(application);
        dbManager = new DBManager(application.getApplicationContext());
        dayPrices = Transformations.switchMap(
            code,
            value -> dbManager.getDayPriceData(value/*, nbDays*/)
        );
    }

    public LiveData<DayPrices> getDayPrices() {
        return dayPrices;
    }

    public void setCode(String code) {
        this.code.setValue(code);
    }

    /*public void setNbDays(int nbDays) {
        this.nbDays.setValue(nbDays);
    }*/

}

public class …
Run Code Online (Sandbox Code Playgroud)

android observer-pattern android-livedata android-viewmodel android-architecture-components

21
推荐指数
3
解决办法
9882
查看次数

用颤振画布在形状上切出一个洞

如何使用颤振画布在形状上“切一个洞”?我有一组相当复杂的形状,看起来像一个真实世界的物体。这个物体有一个洞,形状像一个圆角矩形。

我真的很想从一个形状中减去一个 RRect,但我找不到任何关于如何做到这一点的信息。 canvas.clipRRect(myRRect)只是删除未覆盖的所有内容myRRect。我想要相反的。即myRRect在当前画布形状或形状中制作形状孔。

dart flutter flutter-canvas

14
推荐指数
3
解决办法
3672
查看次数

从applet安全警告中删除"UNKNOWN"发布者

我正在尝试签署一个applet,以便发布者不会显示为" UNKNOWN ":

显示

我在一个组织工作,我们有自己的证书颁发机构,证书链如下:ORG Root CA> ORG Trusted Certification Authority> Yann39(me:D)

我申请了证书,他们为我提供了一个链接,让它进入浏览器.然后我导出它(从Firefox)以获取名为mystore.p12的PKCS#12文件.

然后我做了以下签署我的applet:

/* TO KNOW THE ALIAS */
c:\testrep>keytool -list -storetype pkcs12 -keystore mystore.p12
Enter keystore password:  ********

Keystore type: pkcs12
Keystore provider: SunJSSE

Your keystore contains 1 entry

id de yann39, Oct 24, 2012, keyEntry,
Certificate fingerprint (MD5): D7:E3:83:1D:C1:40:68:72:5F:A8:6F:AC:3A:EA:DD:47

/* CREATE FAKE CLASS FILE AND BUILD A JAR */
c:\testrep>echo test > test.class
c:\testrep>C:\oracle\dev10gr2\jdk\bin\jar cf0 …
Run Code Online (Sandbox Code Playgroud)

java ssl applet signing certificate

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

使用graphql在spring boot中进行身份验证

我正在使用graphql开发一个spring boot项目.我正在使用graphql-java-tools和graphql-spring-boot-starter.我设法使用spring安全性配置安全性和会话管理,如下面的java配置文件中所示.

现在"/ graphql"路径是安全的(只能在请求的http头中发送"基本http身份验证"或会话令牌(x-auth-token)).在任何graphql操作上使用"基本http身份验证"进行身份验证将启动新会话并在标头中发回新会话令牌,并且可以进一步使用该令牌继续该会话.

如何让匿名用户访问某些graphql查询/突变保持上述行为?

如果我将antMatchers("/ graphql").authenticated()更改为antMatchers("/ graphql").permitAll()以允许匿名访问,那么即使我尝试使用"basic"进行身份验证,也不再调用自定义AuthenticationProvider http身份验证".

谢谢!

这是我的配置:

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

    @Autowired
    private AuthenticationProvider authenticationProvider;

    @Override
    public void configure(AuthenticationManagerBuilder authenticationManagerBuilder) {
        authenticationManagerBuilder.authenticationProvider(authenticationProvider);
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .csrf().disable()
            .authorizeRequests()
            .antMatchers("/graphql").authenticated()
            .and()
            .requestCache()
            .requestCache(new NullRequestCache())
            .and()
            .httpBasic()
            .and()
            .headers()
            .frameOptions().sameOrigin() // needed for H2 web console
            .and()
            .sessionManagement()
            .maximumSessions(1)
            .maxSessionsPreventsLogin(true)
            .sessionRegistry(sessionRegistry());
    }

    @Bean
    public SessionRegistry sessionRegistry() {
        return new SessionRegistryImpl();
    }

    @Bean
    public HttpSessionEventPublisher httpSessionEventPublisher() …
Run Code Online (Sandbox Code Playgroud)

authentication spring-security spring-boot graphql graphql-java

11
推荐指数
2
解决办法
6987
查看次数

数字和日期格式:更改NLS_SESSION_PARAMETER不起作用?

Oracle 11.2.0.3.0,APEX 4.1.1.00.23.

我们需要在我们的应用程序中显示数字,格式FM999999999990.000日期格式为英文DD-MON-YYYY.

即使应用程序语言将要改变(法语,西班牙等),我们总是需要这种格式的数字(组分隔符没有空格或逗号,小数分隔符的点,即-1254.010)和日期(3)英文月份名称的第一个字母,即12-FEB-2012).

以下是我们正在使用的全球化属性(Application Builder - > Application - > Edit Globalization Attributes):

  • 应用小学语言:法语(法国)(fr)
  • 应用程序语言派生自:Session
  • 申请日期格式:DD-MON-YYYY

我无法让它按预期工作......我仍然得到数字-1254,01和日期12-FÉVR.-2012而不是-1254.01012-FEB-2012.似乎APEX忽略任何改变会话的调用......

我试图在" 初始化PL/SQL代码 "属性(应用程序生成器 - >应用程序 - >编辑安全属性)中输入以下代码,但没有任何成功:

BEGIN
   EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_NUMERIC_CHARACTERS= ''.,'' ';
   EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_DATE_LANGUAGE = ''AMERICAN'' ';
   EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_LANGUAGE = …
Run Code Online (Sandbox Code Playgroud)

session nls number-formatting date-formatting oracle-apex

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

管理两个小部件之间的手势优先级

我正在尝试使用谷歌地图作为flutter插件,但在管理手势优先级时遇到了问题。

我的地图需要处理手势,PageView它是在一个也监听一些手势的内部渲染的。问题是,看起来手势处理程序PageView优先于地图,所以如果我在地图上垂直拖动,地图会移动,但如果我在地图上水平拖动,页面将切换而不是地图移动。

有没有办法管理小部件的手势处理程序之间的优先级来解决此类问题?

flutter

6
推荐指数
0
解决办法
1132
查看次数

Spring Security 6.x 已弃用 AccessDecisionVoter

在 Spring Boot 2.7.x 中,我使用了RoleHierarchyVoter

public RoleHierarchy roleHierarchy() {
    RoleHierarchyImpl roleHierarchy = new RoleHierarchyImpl();
    roleHierarchy.setHierarchy("ROLE_ADMINISTRATOR > ROLE_USER > ROLE_GUEST");
    return roleHierarchy;
}

@Bean
public RoleHierarchyVoter roleVoter() {
    return new RoleHierarchyVoter(roleHierarchy());
}
Run Code Online (Sandbox Code Playgroud)

在 Spring Boot 3.x 中已弃用 -建议AccessDecisionVoter使用。AuthorizationManager是否有可能使用 AuthorizationManager-Implementation 来设置角色层次结构?的用法

@Bean
AccessDecisionVoter hierarchyVoter() {
    RoleHierarchy hierarchy = new RoleHierarchyImpl();
    hierarchy.setHierarchy("ROLE_ADMIN > ROLE_STAFF > ROLE_USER" +
            "ROLE_USER > ROLE_GUEST");
    return new RoleHierarchyVoter(hierarchy);
}
Run Code Online (Sandbox Code Playgroud)

自从我使用以来就没有工作AuthorizationFilter

spring spring-security spring-boot

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