Jetty对某个web应用启用安全认证

http://can-do.iteye.com/blog/2246946
1、Jetty的版本为:【jetty-7.6.7.v20120910】 

2、使用了spring bean格式的Jetty配置文件【jetty.xml】,需要修改如下配置段 
//begin/ 
<!-- modified by can_do on web app security login not for [/*]=begin= --> 
<bean id="securityConstraint" class="org.eclipse.jetty.util.security.Constraint"> 
<property name="name" value="BASIC" /> 
<property name="roles" value="admin" /> 
<property name="authenticate" value="true" /> 
</bean> 
<bean id="securityConstraintMapping" class="org.eclipse.jetty.security.ConstraintMapping"> 
<property name="constraint" ref="securityConstraint" /> 
<property name="pathSpec" value="/console/*" /> 
</bean> 
<!-- modified by can_do on web app security login =end= --> 
//end/// 
其中要改两处: 
(1)、参数【authenticate】开启,即改为true; 
(2)、参数【pathSpec】调整映射的context路径,默认是所有war应用【/*】,此处根据需要可调整为针对当前应用的, 
       即需要改为【/console/*】 

注意:配置多个角色的方式时,角色间以comma隔开,如下: 

<property name="roles" value="admin,read-only" /> 

3、调整认证域中指定的配置信息,即用户名、密码、角色等,如下: 
//begin/ 
<bean id="securityLoginService" class="org.eclipse.jetty.security.HashLoginService"> 
<property name="name" value="FMQRealm" /> 
<property name="config" value="${fmq.conf}/jetty-realm.properties" /> 
</bean> 
//end/// 
此处指定了配置文件为【${fmq.conf}/jetty-realm.properties】 
//begin 
# username: password [,rolename ...] 
admin: console, admin 
//end// 
注意:配置格式为[用户名]: [密码], [角色] 

4、通过Jetty自动工具类,可以对密码进行安全保护,有三种格式:混淆、MD5、校验和 
用法如下: 
begin/// 
Usage - java org.eclipse.jetty.security.Password [<user>] <password> 
C:\fabric\fmq\lib\web>java -cp .;./jetty-all-server-7.6.7.v20120910.jar org.eclipse.jetty.util.security.Password admin console 
console 
OBF:1sot1wg21wu61ym71wu81wfw1sox 
MD5:bfafd813d7ea65ee4db1f09d7c8ffbf4 
CRYPT:adL4jzDus01r6 
///end/ 

5、将认证域配置文件中的明文转发为密文存储起来,如下: 
/begin// 
# username: password [,rolename ...] 
admin: MD5:bfafd813d7ea65ee4db1f09d7c8ffbf4, admin 
/end 

注意:此处的前缀很重要,【OBF:】、【MD5:】、【CRYPT:】其告诉Jetty认证服务验证时,采用哪种方式进行验证。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值