【问题标题】:adding security to embedded jetty为嵌入式码头增加安全性
【发布时间】:2012-02-14 21:31:48
【问题描述】:

我在码头配置 BASIC-auth 时遇到问题 这是我的 web.xml

<security-constraint>
    <web-resource-collection>
        <web-resource-name>resources</web-resource-name>
        <url-pattern>/resources/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>user</role-name>
    </auth-constraint>
</security-constraint>
<login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>MyRealm</realm-name>
</login-config>
<security-role>
    <role-name>user</role-name>
</security-role>

这是我尝试添加 LoginService 的 java 代码

HashLoginService myrealm = new HashLoginService("MyRealm");
    myrealm.setConfig("src/main/resources/jetty-realm.properties");
    root.getSecurityHandler().setLoginService(myrealm);

我的 jetty-realm.properties 文件有以下用户

user: Lag976JGQdeosfQM,user

我可以建立连接,但我无法进行身份验证,而且我在这个问题上卡了很长时间,所以帮助我的人可以获得免费的数字啤酒! ;)

【问题讨论】:

    标签: authentication jetty


    【解决方案1】:

    好的,所以我发现了我没有做的事情, 你必须先启动一个 LoginService 才能使用它,所以我将我的 java 代码更改为

    HashLoginService myrealm = new HashLoginService("MyRealm");
    
    myrealm.setConfig("src/main/resources/jetty-realm.properties");
    myrealm.start();
    
    root.getSecurityHandler().setLoginService(myrealm);
    

    【讨论】:

    • root 参数是什么?我应该把这个放在contextInitialized()里面吗?
    猜你喜欢
    • 2012-06-02
    • 2011-03-09
    • 2012-01-15
    • 1970-01-01
    • 2012-06-16
    • 1970-01-01
    • 1970-01-01
    • 2014-02-25
    • 2019-09-25
    相关资源
    最近更新 更多