Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

web.xml, using form and basic authentication simultaneously

I have setup FORM-authentication within web.xml (java-webcontainer) successfully.

I did not find a way to sent the username/password within the get-request of the restful-uri from my client when using FORM-Authentication. So I have to use BASIC-Authentication only for the restful-uri.

So I have this question:

How can I set up both form-based authentication and basic authentication? Basic authentication should only be enabled for the restful-uri.

like image 997
nimo23 Avatar asked Jul 30 '12 12:07

nimo23


People also ask

How to authenticate a user in a web application?

One of the most common ways to authenticate a user in a web application is by using form login i.e. you provide a login page and user will enter his username and password for authentication. This works great for human users but sometimes there are situations where you can’t use a login form for authentication.

How to create a basic Auth-method in Tomcat?

In login-conf, we defined a BASIC auth-method. Pretty easy, isn’t it? Do not forget to stop and re-start Tomcat to make these our changes work. Create a login JSP page, on which the user will get a HTML form to enter his login and password Create a JSP error page that the user will get if an error happened during authorization

Which server should I use for JSP authentication?

As a Web server, we will consider Tomcat, which provides BASIC and FORM-based authentication through server.xml and web.xml files; the use of a j_security_check form (for FORM-based) in a JSP page that requires two parameters j_username and j_password; and specifying roles (groups) within the SQL database.

How to authenticate a protected area in JSP?

The simplest is a BASIC authentification method, and a little more original method is a FORM-based one. In the first case at attempting to access the protected area, a pop-up window will appear with the requirement to enter your login and password. In the second case, we will get a page on which we will pass authentification on our defined JSP.


1 Answers

I was also facing a similar problem and I realized that if you are using Wildfly then its possible to configure multiple mechanism using web.xml:-

    <auth-method>BASIC?silent=true,FORM</auth-method>

Using this silent basic authentication will be tried first, which is basic authentication that only takes effect if an Authorization header is present. If no such header is present then form authentication will be used instead.

Maybe its too late for a reply but I just updated this in case someone finds this useful :P

like image 157
nothingInTheName Avatar answered Nov 16 '22 23:11

nothingInTheName