使用Java进行基本身份验证的最简单的HTTP POST方式?

时间:2014-08-12 23:48:34

标签: java java-ee authentication

在Java中使用基本身份验证进行HTTP POST的最简洁方法是什么?

2 个答案:

答案 0 :(得分:0)

'Cleanest'是旁观者的眼睛,但您可以使用URL,HttpURLConnection和Authenticator完成第一部分。第二部分属于另一个问题。

答案 1 :(得分:0)

When user tries to login the application , based on the information in database pull the username and password for that particular user.
1) Check whether user is present in DB , if not available then return that USER does not exists.
2)If user is present in DB the pull the password for the USER and compare that against the password which is posted by the user through html/jsp. If its same then allow the user to login else return that password is incorrect.
3)If both username and password are correct as compared to what is present in DB then allows access to home page of appliaction.

Also there are ways using XML :
Security is also maintained by making secure the web page access using the jdbc realm :
<login-config>
    <auth-method>FORM</auth-method>
    <realm-name>jdbcRealm</realm-name>
    <form-login-config>
        <form-login-page>/login.xhtml</form-login-page>
        <form-error-page>/login.xhtml</form-error-page>
    </form-login-config>
</login-config>
<security-constraint>
    <web-resource-collection>
        <web-resource-name>Secure Pages</web-resource-name>
        <description/>
        <url-pattern>/admin/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>ADMINS</role-name>
    </auth-constraint>
</security-constraint>