小编dwe*_*ner的帖子

按路由配置Spring Security标头()

弹簧安全是否可以header().contentSecurityPolicy("...")为不同的路线匹配器设置不同的设置?

我目前正在使用以下spring安全配置:

@Configuration
@EnableWebSecurity
public static class MyWebSecurityConfigurerAdapter extends  WebSecurityConfigurerAdapter {
    @Override
    protected final void configure(HttpSecurity httpSecurity) throws Exception     {
        httpSecurity.csrf().disable()
                .rememberMe().disable()
                .headers()
                .cacheControl().disable()
                .referrerPolicy().and()
                .contentSecurityPolicy("default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self'").
// followed by .authorizeRequests() section
Run Code Online (Sandbox Code Playgroud)

Chrome(https://bugs.chromium.org/p/chromium/issues/detail?id=271452)中存在一个错误或至少未指明的行为,如果资源是使用CSP提供的,则会阻止浏览器显示PDF文档-Header具有严格的object-src策略.

为了避免这种行为,我想contentSecurityPolicy()为不同的路由匹配器提供不同的配置(在这种情况下,一个用于"../*.pdf"(或者更好的是匹配响应内容类型的匹配器),另一个用于所有其他路由匹配器要求).

spring-security

10
推荐指数
1
解决办法
436
查看次数

用CDI/Weld注入通用豆类

我刚刚来自我的小型JavaSE/Guice世界,目前正在发现"由容器携带"-EE6的路径.在使用Glassfish3.1遇到麻烦之后,我刚刚切换到JBoss,现在面临的问题不应该是一个问题.

作为基础结构辅助类,我试图为任何类型的实体创建通用存储库/ DAO.以一种非常简单的方式,这可能看起来像这样.

public class Repository<E, K extends Serializable & Comparable<K>> {

    private final Instance<EntityManager> entityManagerInstance;

    protected final Class<E> getDomainObjectClass() {
        return domainObjectClass;
    }

    private final Class<E> domainObjectClass;

    protected final EntityManager getEntityManager() {
            return entityManagerInstance.get();
    }

    @Inject
    public Repository(Instance<EntityManager> entityManageryProvider, Provider<E> domainObjectProvider) {
            //This is a dirty hack, sadly :(
            domainObjectClass = (Class<E>)domainObjectProvider.get().getClass();
            this.entityManagerInstance = entityManageryProvider;
    }

    public final void persist(E domainObject) {
        final EntityManager em = getEntityManager();
        em.persist(domainObject);
    }

    public final Collection<E> getAllEntities() {
            final EntityManager em = getEntityManager(); …
Run Code Online (Sandbox Code Playgroud)

genericdao cdi java-ee-6 jboss-weld

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

标签 统计

cdi ×1

genericdao ×1

java-ee-6 ×1

jboss-weld ×1

spring-security ×1