我有一个部署在 Apache Karaf 中的 OSGi
包。我正在使用 BASIC
身份验证来检查用户凭据。这是我的配置 Spring
文件:
<beans...>
...
<bean id="loginService" class="org.eclipse.jetty.plus.jaas.JAASLoginService">
<property name="name" value="karaf"/>
<property name="loginModuleName" value="karaf"/>
<property name="roleClassNames">
<list>
<value>org.apache.karaf.jaas.modules.RolePrincipal</value>
</list>
</property>
</bean>
<bean id="identityService" class="org.eclipse.jetty.security.DefaultIdentityService"/>
<bean id="constraint" class="org.eclipse.jetty.http.security.Constraint">
<property name="name" value="BASIC"/>
<property name="roles" value="admin"/>
<property name="authenticate" value="true"/>
</bean>
<bean id="constraintMapping" class="org.eclipse.jetty.security.ConstraintMapping">
<property name="constraint" ref="constraint"/>
<property name="pathSpec" value="/*"/>
</bean>
<bean id="securityHandler" class="org.eclipse.jetty.security.ConstraintSecurityHandler">
<property name="authenticator">
<bean class="org.eclipse.jetty.security.authentication.BasicAuthenticator"/>
</property>
<property name="constraintMappings">
<list>
<ref bean="constraintMapping"/>
</list>
</property>
<property name="loginService" ref="loginService"/>
<property name="strict" value="false"/>
<property name="identityService" ref="identityService"/>
</bean>
<camelContext trace="true" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="jetty:http://0.0.0.0:8282/services?handlers=securityHandler&matchOnUriPrefix=true"/>
<transform>
<constant><html><body>Hello from Fuse ESB server</body></html></constant>
</transform>
</route>
</camelContext>
....
</beans>
当我在浏览器中输入此 URL:http://localhost:8282/services
时,我会看到基本身份验证窗口,需要用户名和密码。到这一步就OK了。
用户凭据在 Apache Karaf
&{base.dir}/etc/
目录的 user.properties
中设置。从那里,身份 validator 将获取用户凭据进行检查。
我的问题是我需要以某种方式覆盖身份 validator 才能使用数据库中的凭据。我还没有尝试任何事情来完成这项工作,因为我不知道从哪里开始。我尝试在互联网上搜索,但没有任何线索如何使这项工作有效,甚至从哪里开始,使这项工作有效。因此,如果有人能为我指出如何做到这一点的正确方向,我将非常感激。
最佳答案
如果您需要将其从您自己的用户存储中取出,那么您需要提供您自己的 IdentityService 和 LoginService 并在上面的示例中替换它们。
这是一个登录服务的示例,它从属性类型文件加载用户并将它们存储在 HashMap 中。
您可能会很好地使用现有的 BasicAuthenticator,因为它使用提供的 LoginService 和 IdentityService...因此覆盖它们并替换它们,您应该可以开始了。
上面的哈希示例中的目录中有许多示例,其中包括 spnego 选项。
关于java - Camel Jetty 中的自定义基本身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12052364/