spring <custom-filter

本文探讨了在Spring Security 3中如何配置权限使得数据库中保存的权限信息优先级高于XML配置文件。作者遇到了配置custom-filter元素时出现的错误,并寻求帮助解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天在配置spring secutiry3,想让系统先从数据库中保存的权限信息优先于xml中配置的s:intercept-url权限,配置如下:
<beans:bean id="filterSecurityInterceptor"
class="org.springframework.security.web.access.intercept.FilterSecurityInterceptor"
autowire="byType">
<s:custom-filter before="FILTER_SECURITY_INTERCEPTOR" ref=""/>
<beans:property name="objectDefinitionSource" ref="filterInvocationDefinitionSource"/>
</beans:bean>
注意红色的那行,我看网上资料,都没有配置ref的,我不配置ref时tomcat启动时报错:
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.4: Attribute 'ref' must appear on element 's:custom-filter'.
但是如果需要配置的话,这个ref要写什么呢?我随便写,或者写成ref=""则报如下错:
Configuration problem: Security namespace does not support decoration of element [custom-filter]

好纠结啊,请各位帮忙看下,谢谢!
<?xml version="1.0" encoding="UTF-8" ?> <configuration> <include resource="org/springframework/boot/logging/logback/defaults.xml" /> <property name="LOG_FILE" value="./logs/jetlinks-pro.log"/> <include resource="org/springframework/boot/logging/logback/console-appender.xml" /> <appender name="LOGEventPublisher" class="org.jetlinks.community.logging.logback.SystemLoggingAppender"/> <appender name="ErrorLOGEventPublisher" class="org.jetlinks.community.logging.logback.SystemLoggingAppender"> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>WARN</level> </filter> </appender> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <encoder> <pattern>${FILE_LOG_PATTERN}</pattern> <charset>${FILE_LOG_CHARSET}</charset> </encoder> <file>${LOG_FILE}</file> <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> <fileNamePattern>${LOGBACK_ROLLINGPOLICY_FILE_NAME_PATTERN:-${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz}</fileNamePattern> <cleanHistoryOnStart>${LOGBACK_ROLLINGPOLICY_CLEAN_HISTORY_ON_START:-false}</cleanHistoryOnStart> <maxFileSize>${LOGBACK_ROLLINGPOLICY_MAX_FILE_SIZE:-100MB}</maxFileSize> <totalSizeCap>${LOGBACK_ROLLINGPOLICY_TOTAL_SIZE_CAP:-2}</totalSizeCap> <maxHistory>${LOGBACK_ROLLINGPOLICY_MAX_HISTORY:-7}</maxHistory> </rollingPolicy> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>WARN</level> </filter> </appender> <!--控制台使用异步打印,防止阻塞--> <appender name="AsyncConsoleAppender" class="ch.qos.logback.classic.AsyncAppender"> <!-- 队列的深度,该值会影响性能,默认 256 --> <queueSize>256</queueSize> <!-- 设为 0 表示队列达到 80%,也不丢弃任务--> <discardingThreshold>0</discardingThreshold> <!-- 日志上下文关闭后,AsyncAppender 继续执行写任务的时间,单位毫秒 --> <maxFlushTime>1000</maxFlushTime> <!-- 队列满了是否直接丢弃要写的消息,false、丢弃,true、不丢弃 --> <neverBlock>true</neverBlock> <!--是否记录调用栈--> <includeCallerData>true</includeCallerData> <!--One and only one appender may be attached to AsyncAppender,添加多个的话后面的会被忽略--> <appender-ref ref="CONSOLE"/> </appender> <springProfile name="dev"> <logger name="system" level="debug"> <appender-ref ref="LOGEventPublisher"/> </logger> <root level="INFO"> <appender-ref ref="AsyncConsoleAppender"/> <appender-ref ref="ErrorLOGEventPublisher"/> </root> </springProfile> <springProfile name="test"> <root level="INFO"> <appender-ref ref="AsyncConsoleAppender"/> <appender-ref ref="FILE"/> </root> </springProfile> <springProfile name="prod"> <root level="INFO"> <appender-ref ref="AsyncConsoleAppender"/> <appender-ref ref="LOGEventPublisher"/> <appender-ref ref="FILE"/> </root> </springProfile> </configuration>这样可以吗
03-08
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.rain4cloud</groupId> <version>1.0-SNAPSHOT</version> <artifactId>grpc-api</artifactId> <properties> <maven.compiler.source>17</maven.compiler.source> <maven.compiler.target>17</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <!-- 这里不需要手动设置 os.detected.classifier,插件会自动检测 --> <!--<os.detected.classifier>windows-x86_64</os.detected.classifier>--> <!--mac M暂未兼容,使用x86--> <os.detected.classifier>osx-x86_64</os.detected.classifier> <protobuf-maven-plugin.version>0.6.1</protobuf-maven-plugin.version> <protoc.version>3.25.3</protoc.version> <protobuf.java.version>3.25.3</protobuf.java.version> <grpc-java.version>1.70.0</grpc-java.version> </properties> <dependencies> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-stub</artifactId> <version>1.70.0</version> <exclusions> <exclusion> <groupId>javax.annotation</groupId> <artifactId>javax.annotation-api</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-protobuf</artifactId> <version>1.70.0</version> <exclusions> <exclusion> <groupId>javax.annotation</groupId> <artifactId>javax.annotation-api</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-api</artifactId> <version>1.70.0</version> </dependency> <!-- javax.annotation API --> <!-- <dependency>--> <!-- <groupId>javax.annotation</groupId>--> <!-- <artifactId>javax.annotation-api</artifactId>--> <!-- <version>1.3.2</version> <!– 使用最新版本或适合你项目的版本 –>--> <!-- </dependency>--> <!----> <dependency> <groupId>jakarta.annotation</groupId> <artifactId>jakarta.annotation-api</artifactId> <version>3.0.0</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.xolstice.maven.plugins</groupId> <artifactId>protobuf-maven-plugin</artifactId> <version>0.6.1</version> <configuration> <protocArtifact>com.google.protobuf:protoc:3.25.3:exe:${os.detected.classifier}</protocArtifact> <pluginId>grpc-java</pluginId> <pluginArtifact>io.grpc:protoc-gen-grpc-java:1.70.0:exe:${os.detected.classifier}</pluginArtifact> </configuration> <executions> <execution> <goals> <goal>compile</goal> <goal>compile-custom</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>com.google.code.maven-replacer-plugin</groupId> <artifactId>replacer</artifactId> <version>1.5.3</version> <executions> <execution> <phase>generate-sources</phase> <goals> <goal>replace</goal> </goals> </execution> </executions> <configuration> <includes> <include>**/*.java</include> </includes> <replacements> <replacement> <token>javax.annotation.Generated</token> <value>jakarta.annotation.Generated</value> </replacement> </replacements> </configuration> </plugin> </plugins> </build> </project>
最新发布
07-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

V火居道士V

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值