小编She*_*i7y的帖子

来自数据库的 Spring Boot 安全 REST 基本身份验证

我有一个问题,当我使用带有inMemoryAuthentication 的基本身份验证时,如下面的代码片段所示,它工作得很好。

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    DataSource dataSource;

    @Autowired
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
                .withUser("user1").password("secret1").roles("USER")
                .and()
                .withUser("admin").password("123456").roles("ADMIN");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.httpBasic().and().authorizeRequests().antMatchers("/**").hasRole("ADMIN").and()
                .csrf().disable().headers().frameOptions().disable();
    }

}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试使用 get database 来获取将用于身份验证的用户数据时,它不起作用,只会发回 403 响应。

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    DataSource dataSource;//MySQL db via JPA

    @Autowired
    protected void configureGlobal(AuthenticationManagerBuilder auth) throws Exception{
        auth.jdbcAuthentication().dataSource(dataSource).usersByUsernameQuery("select username, password, 1 as enabled from user where username=?")
                .authoritiesByUsernameQuery("select username, role from user …
Run Code Online (Sandbox Code Playgroud)

java spring spring-security spring-boot spring-rest

9
推荐指数
1
解决办法
8704
查看次数

在C#中使用IComparer <T> .Compare(T,T)

我一直试图制作一个通用的反向优先级队列,但在EnQueue中,但我仍然无法管理使用IComparer带来的错误.

错误:错误1非静态字段,方法或属性'System.Collections.Generic.IComparer.Compare(T,T)'需要对象引用

public void inQ(T dat)//adding element in place, increasing order
    {
        if (start == null)//that means that the RPQ is empty
        {
            start = new node(dat);
            return;
        }
        if (IComparer<T>.Compare(start.data, dat) > 0)//Doesn't work
        {
            start = new node(dat, start);
            return;
        }
        //Default Case
        //no need for an else, actually
        node q = start;
        while (q.next != null && Comparer<T>.Default.Compare(q.next.data, dat) < 0)//Works Perfectly
            q++;
        q.next = new node(dat, q.next);
    }
Run Code Online (Sandbox Code Playgroud)

c# icomparer

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