Home » Java » Enterprise Java » Drools Guvnor – Manage access

About Gael Jurin Nkouyee

Drools Guvnor – Manage access

Externalize business or technical rules is very important for scalable applications but the BRMS service access should be managed. guvnor provides control UI access and operations using role based authorizations.

There are several permissions types as listed in drools-guvnor reference manual. Admin with all permissions. Analyst or Analyst read-only: analyst permissions for a specific category. Package admin, Package developer or Package read-only: package permissions for a specific package.

Allow user authentication control by updating the file compenent.xml located into the server deployed folder

...
<component name="org.jboss.seam.security.roleBasedPermissionResolver>
      <property name="enableRoleBasedAuthorization">false</property>
</component>
// change false to true
...

Embedded Guvnor in Jboss server control access configuration:

Stop guvnor server if started in user guest mode and enable role based authorization.

Add drools-guvnor access policy in the file login-config.xml located in server/default/conf

<application-policy name="drools-guvnor">
<authentication>
<login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule" 
flag="required">
<module-option name="usersProperties">
props/drools-guvnor-users.properties</module-option>
<module-option name="rolesProperties">
props/drools-guvnor-roles.properties</module-option>
</login-module>
</authentication>
</application-policy>

Create properties files for users and roles with respective contents:

# A roles.properties file for UsersRolesLoginModule (drools-guvnor-roles.properties)
superuser=admin
packuser=package.admin
rulesviewer=package.readonly
# A users.properties file for UsersRolesLoginModule (drools-guvnor-users.properties)
rulesviewer=drools
packuser=proto
superuser=admin

Restart the Jboss guvnor server and log into web interface using created accounts.

Using lightweight container Tomcat and Mysql server – Configuring drools-guvnor JAAS authentication module

Prequisites: Working with Drools Guvnor 5.3 deployed in Apache tomcat 6 running with Mysql 5.JDK version 1.6

0 – Deploy guvnor application with context name drools-guvnor.

All users are guests then go the administration panel and set authorization for user admin or create another user with authorizations. Stop the server and we are going to enable Jaas database authentication

1 – Create authdb schema with guvnorusers table in mysql database.

CREATE TABLE guvnorusers (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `username` varchar(255) DEFAULT NULL,
  `password` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
);

INSERT INTO guvnorusers values (1,"admin","admin");

2 – Build a custom loginModule 

Download my custom loginModule sources customloginmodule_sources Compile and export this sources as java archive (jar).

3 – In %TOMCAT_HOME%/lib 

Copy the loginModule exported jar file and the mysql connector jar.

4 – In %TOMCAT_HOME%/conf/context.xml, we add a resource declaration

<Resource name="jdbc/URDroolsDS" auth="Container"
 type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver"
 url="jdbc:mysql://yourserveradress:3306/authdb" username="dbuser"
 password="dbuserpassword" maxActive="20" maxIdle="10" maxWait="-1" />

5 – Update %TOMCAT_HOME%/webapps/drools-guvnor/WEB-INF/components.xml to configure our repository to use external database and security settings

<security:identity authenticate-method="#{authenticator.authenticate}" 
     jaas-config-name="drools-guvnor"/>

<security:role-based-permission-resolver 
     enable-role-based-authorization="true"/>

6 – Update %TOMCAT_HOME%/conf/server.xml to add a Realm declaration

<Realm className="org.apache.catalina.realm.LockOutRealm">
...
<Realm appName="drools-guvnor" 
  className="com.test.droolsproto.loginModule.Realm.DroolsJaasRealm" 
  dataSourceName="jdbc/URDroolsDS" localDataSource="true"/>
...
</Realm>

7 – Create a file jaasConfig on %TOMCAT_HOME%/conf with this content:

drools-guvnor{
com.test.droolsproto.loginModule.module.DroolsLoginModule
required debug=true;
};

8 – Before runing Tomcat create in %TOMCAT_HOME%/bin a setenv.sh file if you running on linux or setenv.bat on windows with this content (Working on linux)

…
JAVA_OPTS=”-Xms128m -Xmx256m -Djava.security.auth.login.config=$CATALINA_HOME/conf/jaasConfig”
export JAVA_OPTS
…

Now it’s time to restart your guvnor server and check authentication!

Reference: Drools-guvnor manage access – part 1 ,Drools-guvnor manage access – part 2 from our JCG partner Gael-Jurin Nkouyee at the NGJWEBLOG blog.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

and many more ....

 

2 comments

  1. Hi,
    After doing everything I get following error message. I tried to to debug and I see username quest is being passed to loginModule and I don’t see any login window for guvnor. How would I configure guvnor to see login window that way I can put valid username and password?

    ERROR 08-08 11:07:04,600 (Logger.java:error:1092) JAAS authentication fai
    led
    javax.security.auth.login.LoginException: Security Exception
    at javax.security.auth.login.LoginContext.invoke(LoginContext.java:856)
    at javax.security.auth.login.LoginContext.access$000(LoginContext.java:1
    86)
    at javax.security.auth.login.LoginContext$4.run(LoginContext.java:683)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:6
    80)

  2. Please provide the link to download customLoginModule.

Leave a Reply

Your email address will not be published. Required fields are marked *

*


− 2 = two

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Want to take your Java Skills to the next level?
Grab our programming books for FREE!
  • Save time by leveraging our field-tested solutions to common problems.
  • The books cover a wide range of topics, from JPA and JUnit, to JMeter and Android.
  • Each book comes as a standalone guide (with source code provided), so that you use it as reference.
Last Step ...

Where should we send the free eBooks?

Good Work!
To download the books, please verify your email address by following the instructions found on the email we just sent you.