Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8188467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:55:20+00:00 2026-06-07T02:55:20+00:00

I get a ServeletException: Failed to authenticate a principal when I attempt to login

  • 0

I get a ServeletException: Failed to authenticate a principal when I attempt to login with the DatabaseServerLoginModule. I’m guessing the issue is either how passwords are written to the db or the rolesQuery that is incorrect. I certainly can use suggestions on how to troubleshoot at this point. Here is my setup:

login-config.xml

<application-policy name = "Avengers">
  <authentication>
    <login-module code = "org.jboss.security.auth.spi.DatabaseServerLoginModule" flag = "required">
       <module-option name = "dsJndiName">java:/jdbc/thor_ds</module-option>
       <module-option name = "principalsQuery">SELECT password FROM usertable WHERE username = ?</module-option>
       <module-option name="rolesQuery" value="SELECT groupid, 'Roles' FROM grouptable WHERE username=?" />
       <!--<module-option name="rolesQuery" value="SELECT gt.groupid as 'userRoles', gt.groupid as 'Roles' FROM grouptable as gt WHERE username=?" />-->
       <module-option name="hashAlgorithm">MD5</module-option>
       <module-option name="hashEncoding">base64</module-option>
    </login-module>
  </authentication>
</application-policy>  

jboss-web.xml

<jboss-web>
  <context-root>/Avengers</context-root>
  <security-domain>java:/jaas/Avengers</security-domain>
</jboss-web>

mysql-init.sql

create table usertable (
    username varchar(128) NOT NULL PRIMARY KEY,
    password varchar(128) NOT NULL,
    email varchar(128) NOT NULL,
    firstname varchar(128) NOT NULL,
    lastname varchar(128) NOT NULL
);

create table grouptable(
    username varchar(128) NOT NULL,
    groupid  varchar(128) NOT NULL,
    CONSTRAINT GROUP_PK PRIMARY KEY(username, groupid),
    CONSTRAINT USER_FK FOREIGN KEY(username) REFERENCES usertable(username)
        ON DELETE CASCADE ON UPDATE RESTRICT
);

insert into usertable(username,password,email,firstname,lastname) 
    values ('admin', '21232f297a57a5a743894a0e4a801fc3','','','');
insert into grouptable(username,groupid) values ('admin', 'USER');
insert into grouptable(username,groupid) values ('admin', 'ADMIN');

Snippet from web.xml

<security-constraint>
    <display-name>Admin</display-name>
    <web-resource-collection>
        <web-resource-name>Admin Views</web-resource-name>
        <url-pattern>/admin/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>USER</role-name>
        <role-name>ADMIN</role-name>
    </auth-constraint>
</security-constraint>
<security-constraint>
    <display-name>Compass Web</display-name>
    <web-resource-collection>
        <web-resource-name>Monitoring Module</web-resource-name>
        <url-pattern>/monitor/*</url-pattern>
    </web-resource-collection>
    <web-resource-collection>
        <web-resource-name>Core Web Module</web-resource-name>
        <url-pattern>/main/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>USER</role-name>
        <role-name>ADMIN</role-name>
    </auth-constraint>
</security-constraint>
<security-constraint>
    <display-name>Login</display-name>
    <web-resource-collection>
        <web-resource-name>Login Pages</web-resource-name>
        <url-pattern>/login/*</url-pattern>
    </web-resource-collection>
</security-constraint>
<login-config>
    <auth-method>FORM</auth-method>
    <realm-name>avengers</realm-name>
    <form-login-config>
        <form-login-page>/login/login.xhtml</form-login-page>
        <form-error-page>/login/error.xhtml</form-error-page>
    </form-login-config>
</login-config>
<security-role>
    <description/>
    <role-name>ADMIN</role-name>
</security-role>
<security-role>
    <description/>
    <role-name>USER</role-name>
</security-role>

My UserBean.login()

public String login() {

    System.out.println("user "+username+" is attempting to login...");

    FacesContext context = FacesContext.getCurrentInstance();
    HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
    try {
        request.login(this.username, this.password);
        this.cUser = Utils.getEntityManager().find(MyUser.class, username);
        System.out.println("User "+username+" successfully logged in...");
    } catch (ServletException e) {
        // Handle unknown username/password in request.login().
        context.addMessage(null, new FacesMessage("Invalid Login Credentials"));
        System.err.println("Invalid Login Credentials");
        e.printStackTrace();

        return "/login/error.xhtml";
    }

    return "/main/index.xhtml";
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T02:55:23+00:00Added an answer on June 7, 2026 at 2:55 am

    I was able to get help with this on the jboss as forums. My solution was to revise the markup of the rolesQuery from:

    <module-option name="rolesQuery" 
        value="SELECT groupid, 'Roles' FROM grouptable WHERE username=?" />
    

    to this:

    <module-option name="rolesQuery">
       SELECT groupid, 'Roles' FROM grouptable WHERE username=?
    </module-option>
    

    I also had to change the encoding style to HEX. Here is my working login-config.xml.

    <application-policy name="Avengers">
        <authentication>
           <login-module code="org.jboss.security.auth.spi.DatabaseServerLoginModule" flag = "required">
              <module-option name="dsJndiName">java:/jdbc/thor_ds</module-option>
              <module-option name="principalsQuery">SELECT password FROM usertable WHERE username = ?</module-option>
              <module-option name="rolesQuery">SELECT groupid, 'Roles' FROM grouptable WHERE username=?</module-option>
              <module-option name="hashAlgorithm">MD5</module-option>
              <module-option name="hashEncoding">HEX</module-option>
              <!--<module-option name="hashEncoding">base64</module-option>-->
           </login-module>
        </authentication>
     </application-policy>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a main Servlet that processes post/get requests. I am using connection pooling
There's a thrird party app that needs to get information via custom http headers,
I'm working on a setup that takes an http request (GET for testing purposes)
I've written a application with a custom login system. And then written my own
In my valve I get the execution time of my http query like that
Get class from div inside an li and add to the same li. The
//Get width and resize another element $(document).ready(function() { function ResizeSearch(GridID, SearchID) { var eleWidth
get an array of bluetooth ID's Broadcast the bluetooth signal manually
GET is a convenient method to post the form id, post the website id
//get the lat and loni throgh the loaddata function.java.util.ConcurrentModificationException at java.util.AbstractList$SimpleListIterator.next(AbstractList.java:64) How to resolve

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.