码头9 HashLoginService [英] Jetty 9 HashLoginService

查看:96
本文介绍了码头9 HashLoginService的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是在显示第一页之前提示用户登录网站.页面是通过HTTPS提供的.

My objective is to prompt user for a login into the website before displaying the first page. Page is served over HTTPS.

使用Jetty 9.2及以下版本分别进行配置:

Using Jetty 9.2 and below are the respective configurations done:

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">
    <display-name>test-jetty</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Secured area</web-resource-name>
            <url-pattern>/*</url-pattern>
        </web-resource-collection>
        <user-data-constraint>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>
    <login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>Test Realm</realm-name>
    </login-config>
</web-app>

还可以在{jetty.home}/etc/jetty.xml中进行配置:

Also done the configuration at {jetty.home}/etc/jetty.xml:

<Configure id="Server" class="org.eclipse.jetty.server.Server">
…
<Call name="addBean">
        <Arg>
                <New class="org.eclipse.jetty.security.HashLoginService">
                        <Set name="name">Test Realm</Set>
                        <Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/realm.properties</Set>
                        <Set name="refreshInterval">5</Set>
                        <Call name="start"></Call>
                </New>
        </Arg>
    </Call>
</Configure>

并在{jetty.home}/etc/realm.properties上设置realm.properties文件:

and also setup the realm.properties file at {jetty.home}/etc/realm.properties:

admin: CRYPT:1a97ec915dcd5bd27d34ef8a7a86f918,admin

重启码头之后,日志文件中没有错误,并且在 https://加载服务器页面时,登录提示符也不起作用本地主机:8443

after restarted jetty, there are no errors in log file, neither do the login prompt works when loading the server page at https://localhost:8443

有什么想法我错过了吗?

Any ideas what did I missed?

谢谢 /d

推荐答案

好,刚刚发现我错过了web.xml中的两个条目:<security-role><auth-constraint>.

Ok, just found out that I missed out two entries in web.xml: <security-role> and <auth-constraint>.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">
    <display-name>test-jetty</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Secured area</web-resource-name>
            <url-pattern>/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>admin</role-name>
        </auth-constraint>
        <user-data-constraint>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>
    <login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>Test Realm</realm-name>
    </login-config>
    <security-role>
        <role-name>admin</role-name>
    </security-role>
</web-app>

这篇关于码头9 HashLoginService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆