我正在尝试设置一个 CXF + Spring + 嵌入式 jetty ,并依赖 JAAS 进行基本身份验证,但在连接所有部分时遇到问题。
我想使用 CXF JAASLoginInterceptor,它看起来很容易配置,因此我在 ApplicationContext 中的服务定义如下
<jaxws:endpoint address="/soapService">
<jaxrs:serviceBeans>
<ref bean="serviceImpl" />
</jaxrs:serviceBeans>
<jaxws:inInterceptors>
<ref bean="authenticationInterceptor"/>
</jaxws:inInterceptors>
</jaxws:endpoint>
<bean id="authenticationInterceptor" class="org.apache.cxf.interceptor.security.JAASLoginInterceptor">
<property name="contextName" value="jaasContext"/>
<property name="roleClassifier" value="ROLE_"/>
</bean>
正如文档所述:“JAAS 身份 validator 是使用 JAAS 登录上下文的名称进行配置的(通常在服务器知道的 JAAS 配置资源中指定)”
我如何以最基本的方式设置“JAAS 配置资源”?
谢谢!
最佳答案
最后很容易做到。您唯一需要的就是在类路径上放置一个包含登录模块配置的文件,并将系统属性“java.security.auth.login.config”设置为指向该文件。
例如用于启用基于属性文件的身份验证的文件:
jaasContext {
org.eclipse.jetty.plus.jaas.spi.PropertyFileLoginModule 可选
文件=“src/main/resources/credentials.props”;
};
请注意,CXF 拦截器中的 contextName 与 jaas 配置文件中的 contextName 相同。
关于java - 使用 CXF 和 Spring 在嵌入式 Jetty 中配置 JAAS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21043646/