我有一个问题,当我使用带有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) 我一直试图制作一个通用的反向优先级队列,但在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)