Java Camel Jetty中的自定义基本身份验证
我有一个部署在ApacheKaraf中的Java Camel Jetty中的自定义基本身份验证,java,jetty,osgi,apache-camel,apache-karaf,Java,Jetty,Osgi,Apache Camel,Apache Karaf,我有一个部署在ApacheKaraf中的OSGi包。我正在使用BASIC身份验证来检查用户凭据。这是我的配置Spring文件: <beans...> ... <bean id="loginService" class="org.eclipse.jetty.plus.jaas.JAASLoginService"> <property name="name" value="karaf"/> <property name
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>
...
org.apache.karaf.jaas.modules.RolePrincipal
html>body>Hello from Fuse ESB服务器/body>/html>
....
当我输入此URL时:http://localhost:8282/services
在浏览器中,我看到基本身份验证窗口,需要用户名和密码。在这一点之前都没问题
用户凭据在apachekaraf
&{base.dir}/etc/
目录的user.properties
中设置。验证器从那里获取用户凭据以进行检查
我的问题是,我需要以某种方式重写身份验证器以使用数据库中的凭据。我还没有尝试任何东西来实现这一点,因为我不知道从哪里开始。我曾尝试在互联网上搜索,但没有任何线索表明如何使这项工作,甚至没有从哪里开始,使这项工作。因此,如果有人能为我指出正确的方向,我将不胜感激。如果您需要将其从自己的用户商店中取出,那么您需要提供自己的标识服务和登录服务,并在上面的示例中替换它们 这是一个登录服务的示例,它从属性类型文件加载用户并将其存储在hashmap中 您可能可以使用现有的BasicAuthenticator,因为它使用提供的LoginService和IdentityService…因此覆盖它们并替换它们,您应该可以继续使用
从上面的哈希示例中,有许多示例包含一个SPNEGO选项。< P>因为您似乎正在使用Spring,考虑使用Spring安全模块来为WebApp提供安全性。 甚至还有一个
JdbcDaoImpl
可以连接起来为安全性提供userdetails服务
实际上,我不必创建自己的IdentityService,我使用了默认的IdentityService。我所做的是创建了我自己的登录服务扩展了AbstractLifeCycle,实现了LoginService,实现了我需要的方法,现在就开始工作。我有来自数据库的用户。基本auth也可以工作。谢谢,你真的把我带到了正确的方向。