我正在编写ContainerRequestFilter
来检查请求标头并提供可插入的身份验证机制,该机制将迭代已配置的AS安全域(例如Glassfish)并提供自定义SecurityContext
。
我试图注入RealmsManager
(在com.sun.enterprise.security.auth.realm.RealmsManager
[1]中定义),在@Singleton
中注明为ContainerRequestFilter
。这是我的代码:
public class AuthenticationFilter implements ContainerRequestFilter {
@Inject
RealmsManager rm;
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
if (rm != null) {
requestContext.abortWith(Response.ok("OKAY").build());
} else {
requestContext.abortWith(Response.ok("NULL").build());
}
}
但在部署WAR时出现此错误:
org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied
dependencies for type RealmsManager with qualifiers @Default
at injection point [BackedAnnotatedField] @Inject
如何在RelamsManager
中注入ContainerRequestFilter
单身?
[1]以下是RealmsManager
的来源:https://svn.java.net/svn/glassfish~svn/trunk/main/nucleus/security/core/src/main/java/com/sun/enterprise/security/auth/realm/RealmsManager.java