Search code examples
jbpm

Login failed: Not Authorized,Login as Another user Error in Business-Central JBPM


I am new to working on the Red hat business process automation manager. We are developing a workflow application. Read hat business process automation includes java business process management (JBPM). This application is built to generate workflow.

Read hat business process automation manager has an application called Business central where users can authenticate and manage the workflows.

By default, the business process automation manager authenticates the user from the h2 database (java file system database).

Now I require that we move to the PostgreSQL database from h2. In this case, I need to authenticate the user from the PostgreSQL database.

For that implementation, I have referred and used the following docker image.

https://github.com/jboss-dockerfiles/business-central/blob/master/docker-compose-examples/jbpm-full-postgres.yml

I have followed all the described instructions to connect the PostgreSQL database.

Default user of h2 database is wbadmin.

In the PostgreSQL,

I have used the default database created by docker. The following are the details.

db : jbpm
user: jbpm
password : jbpm
driver : postgres

I have added a user to the user login table in PostgreSQL.

username: xyz
password: xyz
role: admin,analyst,user,process-admin,kie-server

I have made the following changes in the standalone/configuration/stanalone.xml file.

 <security-domain name="other" cache-type="default">
        <authentication>
            <login-module code="Remoting" flag="optional">
                <module-option name="password-stacking" value="useFirstPass"/>
            </login-module>
            <login-module code="org.jboss.security.auth.spi.DatabaseServerLoginModule" flag="required">
                <module-option name="dsJndiName" value="java:jboss/datasources/jBPMDS"/>
                <module-option name="principalsQuery" value="select password from userlogin where username=?"/>
                <module-option name="rolesQuery" value="select role,'Roles' from userlogin where username=?"/>
            </login-module>
            <login-module code="org.kie.security.jaas.KieLoginModule" flag="optional" module="deployment.business-central.war"/>
            <login-module name="org.kie.security.jaas.KieLoginModule-2" code="org.kie.security.jaas.KieLoginModule" flag="optional" module="deployment.jbpm-casemgmt.war"/>
        </authentication>
    </security-domain>

As a result of the above changes, now business central stop to authenticate the user from the h2 database. But surprisingly it does not authenticate the user from the PostgreSQL database.

It shows me an error message

"Login Failed: Not Authorised, login as another user"

enter image description here.

Looking forward to your response. Thanks in advance


Solution

  • I was able to login using "DatabaseServerLoginModule" after making the below changes.

    1) Created 2 different tables for username and "roles". The FIrst table only has a username and password. The second table has the corresponding role for the username.

    CREATE TABLE Users(username VARCHAR(64) PRIMARY KEY, passwd VARCHAR(64));
    CREATE TABLE UserRoles(username VARCHAR(64), userRoles VARCHAR(64))
    

    2) Below would be the security domain configuration.

     <security-domain name="other" cache-type="default">
                <authentication>
                    <login-module code="Remoting" flag="optional">
                         <module-option name="password-stacking" value="useFirstPass"/>
                    </login-module>
                    <login-module code="org.jboss.security.auth.spi.DatabaseServerLoginModule" flag="required">
                         <module-option name="dsJndiName" value="java:jboss/MySqlDS"/>
                         <module-option name="principalsQuery" value="select passwd from Users username where username=?"/>
                         <module-option name="rolesQuery" value="select userRoles, 'Roles' from UserRoles where username=?"/>
                     </login-module>
                    <login-module code="org.kie.security.jaas.KieLoginModule" flag="optional" module="deployment.business-central.war"/>
                 </authentication>
        </security-domain>
    

    3) In user roles table each row should have only one role, don't add multiple roles in comma seperated format. Here is sample data from my DB.

    username userRoles
    xyz       admin
    xyz       kie-server
    
    username passwd
    xyz      xyz@123