我试图在我的Spring Security配置中注册多个过滤器,但是我总是得到相同的异常:
04-Nov-2015 14:35:23.792警告[RMI TCP连接(3)-127.0.0.1] org.springframework.web.context.support.AnnotationConfigWebApplicationContext.refresh在上下文初始化期间遇到异常 - 取消刷新尝试org.springframework.beans .factory.BeanCreationException:创建名为'org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration'的bean时出错:注入自动连接的依赖项失败; 嵌套异常是java.lang.IllegalStateException:WebSecurityConfigurers上的@Order必须是唯一的.已经使用了100的订单,因此它不能用于com.payment21.webapp.MultiHttpSecurityConfig$ApiWebSecurityConfigurationAdapter$$EnhancerBySpringCGLIB $ 35c79fe4@1d381684.
由于我自己的尝试不起作用,我尝试了与Spring Security参考中显示的完全相同的代码:
@EnableWebSecurity
public class MultiHttpSecurityConfig {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER").and()
.withUser("admin").password("password").roles("USER", "ADMIN");
}
@Configuration
@Order(1)
public static class ApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception {
http
.antMatcher("/api/**")
.authorizeRequests()
.anyRequest().hasRole("ADMIN")
.and()
.httpBasic();
}
}
@Configuration
public static class FormLoginWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().authenticated()
.and() …Run Code Online (Sandbox Code Playgroud) 以下代码工作正常:
Stream.of("key1", "key2")
.map(key -> {
SomeObject foo = service.find(key);
if (foo == null) {
throw new RuntimeException("No entity found with key: " + key);
}
return foo;
})
// ...
Run Code Online (Sandbox Code Playgroud)
但是,当我从Optional使用orElseThrow时:
Stream.of("key1", "key2")
.map(key -> Optional.ofNullable(someService.find(key))
.orElseThrow(() -> new RuntimeException("No entity found with key: " + key)))
// ...
Run Code Online (Sandbox Code Playgroud)
我得到一个编译时错误:
错误:(129,33)java:未报告的异常X; 必须被抓住或宣布被抛出
两者都抛出一个RuntimeException,为什么使用Optional的方法不起作用的任何想法?
更新:我的构建基础架构,我尝试使用IntelliJ和Maven编译它:
$ mvn -version
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T17:41:47+01:00)
Maven home: C:\Tools\apache-maven-3.3.9
Java version: 1.8.0_91, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_91\jre
Default locale: de_AT, …Run Code Online (Sandbox Code Playgroud) 如何File在WebAssembly内存上下文中传递要读取的内容?
使用JavaScript在浏览器中读取文件很简单:
<input class="file-selector" type="file" id="files" name="files[]" />
Run Code Online (Sandbox Code Playgroud)
我能够使用crate stdweb来引导用Rust编写的WebAssembly代码,向DOM元素添加一个事件监听器并启动FileReader:
let reader = FileReader::new();
let file_input_element: InputElement = document().query_selector(".file-selector").unwrap().unwrap().try_into().unwrap();
file_input_element.add_event_listener(enclose!( (reader, file_input_element) move |event: InputEvent| {
// mystery part
}));
Run Code Online (Sandbox Code Playgroud)
在JavaScript中,我会从元素中获取文件并将其传递给阅读器,但是,stdweb的API需要以下签名:
pub fn read_as_array_buffer<T: IBlob>(&self, blob: &T) -> Result<(), TODO>
Run Code Online (Sandbox Code Playgroud)
我不知道如何实现IBlob,我确信我遗漏了一些明显的东西,无论是使用stdweb API还是我对WebAssembly/Rust的理解.我希望有一些东西比将东西转换为UTF-8更简洁.
我正在寻找一种非侵入性的方法来为某些api调用添加验证码过滤器.
我的设置包括两个WebSecurityConfigurerAdapters,每个都有一个过滤器(不是验证码过滤器):
如何在Spring Security内容,公共内部api或外部api调用之前添加过滤器?我不需要SecurityContext,只需要检查请求头中的Captcha,转发到filterChain(普通过滤器)或手动拒绝访问.我尝试在web.xml中声明一个过滤器,但这会破坏使用依赖注入的能力.
这是我的Spring安全配置:
@EnableWebSecurity
public class SpringSecurityConfig {
@Configuration
@Order(1)
@EnableGlobalMethodSecurity(securedEnabled = true)
public static class InternalApiConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Autowired
private Filter filterA;
public InternalApiConfigurerAdapter() {
super(true);
}
@Override
public void configure(WebSecurity web) throws Exception {
web
.ignoring()
.antMatchers("/public/**");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.antMatcher("/iapi/**")
.exceptionHandling().and()
.anonymous().and()
.servletApi().and()
.authorizeRequests()
.anyRequest().authenticated().and()
.addFilterBefore(filterA, (Class<? extends Filter>) UsernamePasswordAuthenticationFilter.class);
}
@Override
@Bean
public …Run Code Online (Sandbox Code Playgroud) 我想避免使用样板代码来创建一个SelectItems列表,以便在视图和模型之间映射我的实体/ dtos,所以我使用了这个通用对象转换器的片段:
@FacesConverter(value = "objectConverter")
public class ObjectConverter implements Converter {
private static Map<Object, String> entities = new WeakHashMap<Object, String>();
@Override
public String getAsString(FacesContext context, UIComponent component, Object entity) {
synchronized (entities) {
if (!entities.containsKey(entity)) {
String uuid = UUID.randomUUID().toString();
entities.put(entity, uuid);
return uuid;
} else {
return entities.get(entity);
}
}
}
@Override
public Object getAsObject(FacesContext context, UIComponent component, String uuid) {
for (Entry<Object, String> entry : entities.entrySet()) {
if (entry.getValue().equals(uuid)) {
return entry.getKey();
}
}
return null; …Run Code Online (Sandbox Code Playgroud) 在对JCR或RDBMS进行了一些研究并阅读了其他文章之后,我仍然不确定是否将JCR over JPA用于文档管理系统,该系统必须处理不同的文档类型,非常大的文件以及许多文档的并发访问用户。
我考虑JCR的主要理由是因为文档对我来说看起来像内容,并且该规范已经解决了它所带来的一些问题-大多数我对存储和版本控制感兴趣。另外,我想将文档内容封装在JCR实现中,并将JPA用于其他所有特定于应用程序的内容。
也许有人可以帮我解决剩余的问题:
更新:尽管已经详细回答了这个问题,但从更实际的角度来看,可能有人会对它的使用有更严格的了解。我个人越来越关注以下与技术无关的问题:
我有一个有效的自定义 Spring Security 配置,以使用 JSON Web 令牌而不是 HTTPSession 来保护某些 url 模式。
我为了启用与基于 url 模式相反的基于方法的安全性,我需要注册一个 AuthenticationManager,由于循环依赖而失败:
Caused by: org.springframework.beans.BeanInstantiationException:
Failed to instantiate [org.springframework.security.authentication.AuthenticationManager]:
Factory method 'authenticationManagerBean' threw exception; nested exception is org.springframework.beans.FatalBeanException:
A dependency cycle was detected when trying to resolve the AuthenticationManager. Please ensure you have configured authentication.
Run Code Online (Sandbox Code Playgroud)
我自己的依赖是我需要的过滤器来配置它。当我省略 AuthenticationManager 的注册时,一切正常:
@Configuration
@EnableWebSecurity
@Order(2)
@EnableGlobalMethodSecurity(securedEnabled = true)
public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private StatelessAuthenticationFilter statelessAuthenticationFilter;
public SpringSecurityConfig() {
super(true);
}
@Override
public void configure(WebSecurity web) throws …Run Code Online (Sandbox Code Playgroud) 我已经实现了一个控制器来上传多个文件:
public class Image implements Serializable {
private MultipartFile file;
private Ingeger imageNumber;
...
}
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public void handleFileUpload(@RequestBody Set<Image> images) {
...
}
Run Code Online (Sandbox Code Playgroud)
我使用以下命令直接在上传方法中仅使用一个MultipartFile正确检查了代码:
curl http://localhost:8080/upload -X POST -F 'file=@1.jpg;type=image/jpg' -H "Content-Type: multipart/form-data"
Run Code Online (Sandbox Code Playgroud)
我需要以三种方式扩展它,但不知道正确的语法:
java ×4
spring ×2
captcha ×1
converter ×1
curl ×1
dms ×1
file-upload ×1
http ×1
jackrabbit ×1
java-stream ×1
javascript ×1
jcr ×1
jpa ×1
jsf ×1
jsf-2 ×1
jwt ×1
optional ×1
rust ×1
spring-boot ×1
webassembly ×1