小编Jou*_*ner的帖子

Spring安全配置@Order不是唯一的例外

我试图在我的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)

java configuration spring spring-security

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

使用Optional.orElseThrow在Stream中抛出RuntimeException

以下代码工作正常:

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)

java optional runtimeexception java-stream

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

如何使用Rust将带有JavaScript的文件读取到WebAssembly?

如何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更简洁.

javascript rust webassembly

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

如何仅为特定URL添加Spring Security验证码过滤器

我正在寻找一种非侵入性的方法来为某些api调用添加验证码过滤器.

我的设置包括两个WebSecurityConfigurerAdapters,每个都有一个过滤器(不是验证码过滤器):

  • 内部api("/ iapi"在所有呼叫上使用过滤器A,但也忽略一些公共请求,如/ authenticate)
  • 外部api("/ eapi"在所有呼叫中使用过滤器B)

如何在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)

java captcha spring spring-security

11
推荐指数
1
解决办法
8910
查看次数

针对具有静态WeakHashMap的通用JSF对象转换器的参数

我想避免使用样板代码来创建一个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)

jsf converter jsf-2

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

DMS的JCR与JPA:性能,优点,缺点

在对JCR或RDBMS进行了一些研究并阅读了其他文章之后,我仍然不确定是否将JCR over JPA用于文档管理系统,该系统必须处理不同的文档类型,非常大的文件以及许多文档的并发访问用户。

我考虑JCR的主要理由是因为文档对我来说看起来像内容,并且该规范已经解决了它所带来的一些问题-大多数我对存储和版本控制感兴趣。另外,我想将文档内容封装在JCR实现中,并将JPA用于其他所有特定于应用程序的内容。

也许有人可以帮我解决剩余的问题:

  • JCR的读取/查询性能与JPA有什么关系(我知道它在实现上应该有很大的不同,但是可能会有一些经验法则)?
  • 是否有人在具有某些特定JCR实现的类似用例中具有实际经验?如果是这样,您是否将其与关系数据库(JPA)混合使用?
  • 考虑到文件存储和版本控制的好处,值得引入JCR的开销吗?(我很可能会使用自己的自定义使用访问控制(JPA),并且不需要额外的灵活性即可在运行时引入新的节点属性)
  • 是否有人对数据完整性和备份解决方案有任何经验?

更新:尽管已经详细回答了这个问题,但从更实际的角度来看,可能有人会对它的使用有更严格的了解。我个人越来越关注以下与技术无关的问题:

  1. 文档:Jackrabbit的文档很差,OCM的指南第一段中包含一个无效链接,一些示例搜索查询由于未知原因引发了异常,非常基础的教程中有一个TODO,并且它的独立服务器在JDK8中无法正常工作,完全没有记录。
  2. 成熟度:Jackrabbit Oak似乎仍在开发中,其他解决方案似乎要么被放弃,要么正在边缘化。
  3. 社区:在对面JPA,做JCR导致更少的方式研究命中。当刚接触该技术的项目团队陷入(重大)问题中时,这可能是一个真正的问题。

java jpa jackrabbit jcr dms

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

Spring Security 配置循环依赖错误

我有一个有效的自定义 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)

dependency-injection spring-security jwt

2
推荐指数
1
解决办法
1994
查看次数

如何使用 Spring Boot 上传多个文件并使用 cURL 进行测试

我已经实现了一个控制器来上传多个文件:

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)

我需要以三种方式扩展它,但不知道正确的语法:

  1. POST 一组 JSON 项
  2. 为每个项目添加字段“imageNumber”
  3. 最棘手的部分:为每个项目添加一个嵌套的文件

curl file-upload http spring-boot

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