Skip to main content

Using servlet request.login with jdbcRealm?

1 reply [Last post]
pacific202
Offline
Joined: 2012-11-04
Points: 0

I would like to use the new Servlet 3.0 login with a jdbcRealm, but I don't see any documentation on how to set this up.

GlassFish 3.1.2
Netbeans 7.3
SQL Server 2008 R2 with Microsoft's Type 4 JDBC driver

I have a jdbcRealm set up as follows:

JAAS Context: jdbcRealm
JNDI: jdbc/omSecurity
User Table: OM_SECURITY.User
User Name Column: Name
Password Column: Password
Group Table: OM_SECURITY.SignInGroup
Group Table User Name Column: UserName
Group Name Column: GroupName
Assign Groups: (blank)
Database User: (blank)
Database Password: (blank)
Digest Algorithm: SHA-512
Password Encryption Algorithm: AES
Encoding: Hex
Charset: (blank)

The user table is created using this script:

CREATE TABLE [OM_SECURITY].[User](
[UserID] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](32) NOT NULL,
[Password] [char](128) NOT NULL,
[LastName] [nvarchar](32) NULL,
[FirstName] [nvarchar](32) NULL,
[Email] [nvarchar](64) NULL,
[Active] [bit] NOT NULL
) ON [PRIMARY]

This is the View used to return every user in that table as being in the "User" group/role:

SELECT     'User' AS GroupName, Name AS UserName
FROM         OM_SECURITY.[User]
WHERE     (Active = 1)

There is one record in the User table (admin/password):

1   admin   B109F3BBBC244EB82441917ED06D618B9008DD09B3BEFD1B5E07394C706A8BB980B1D7785E5976EC049B46DF5F1326AF5A2EA6D103FD07C95385FFAB0CACBC86    NULL    NULL    NULL    1

Here is my web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <login-config>
        <realm-name>omRealm</realm-name>
    </login-config>
    <security-role>
        <description/>
        <role-name>User</role-name>
    </security-role>
</web-app>

These are the errors that come up in the GlassFish console when I try to log in:

SEVERE: jdbcrealm.invaliduserreason WARNING: WEB9102: Web Login Failed: com.sun.enterprise.security.auth.login.common.LoginException: Login failed: Security Exception
SEVERE: Servlet Exception: javax.servlet.ServletException: Exception thrown while attempting to authenticate for user: admin
WARNING: DPL5032:An authentication method was not defined in the web.xml descriptor. Using default BASIC for login configuration.
WARNING: No Principals mapped to Role [User].

These are the request parameters as copied from the Chrome network tool:

username:admin
password:b109f3bbbc244eb82441917ed06d618b9008dd09b3befd1b5e07394c706a8bb980b1d7785e5976ec049b46df5f1326af5a2ea6d103fd07c95385ffab0cacbc86

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
pacific202
Offline
Joined: 2012-11-04
Points: 0

It has been suggested to me that I should be sending the password cleartext instead of SHA-512 hashed. When I turn off the client-side hashing I still get these errors:

SEVERE: jdbcrealm.invaliduserreason
WARNING: WEB9102: Web Login Failed: com.sun.enterprise.security.auth.login.common.LoginException: Login failed: Security Exception
SEVERE: Servlet Exception: javax.servlet.ServletException: Exception thrown while attempting to authenticate for user: admin