Jer*_*Pip 1 authentication jetty
我在jetty中配置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>
Run Code Online (Sandbox Code Playgroud)
这是我尝试添加LoginService的java代码
HashLoginService myrealm = new HashLoginService("MyRealm");
myrealm.setConfig("src/main/resources/jetty-realm.properties");
root.getSecurityHandler().setLoginService(myrealm);
Run Code Online (Sandbox Code Playgroud)
我的jetty-realm.properties文件有以下用户
user: Lag976JGQdeosfQM,user
Run Code Online (Sandbox Code Playgroud)
我可以建立连接,但我无法进行身份验证,而且我现在已经坚持了很长时间,所以无论谁帮助我获得免费的数字啤酒!;)
好的,所以我发现了我没做的事情,你必须先启动一个LoginService才能使用它,所以我把我的java代码更改为
HashLoginService myrealm = new HashLoginService("MyRealm");
myrealm.setConfig("src/main/resources/jetty-realm.properties");
myrealm.start();
root.getSecurityHandler().setLoginService(myrealm);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3621 次 |
| 最近记录: |