Reputation: 330
I've done it as it is described in all the tutorials.
module add --name=com.mysql --resources=/path/to/mysql-connector-java-5.1.24-bin.jar --dependencies=javax.api,javax.transaction.api
/subsystem=datasources/jdbc-driver=mysql:add(driver-name=mysql,driver-module-name=com.mysql,driver-class-name=com.mysql.jdbc.Driver)
[standalone@localhost:9990 /] /subsystem=datasources/data-source=niwads:add(
driver-name=mysql,
user-name=db_user,
password=secret,
connection-url=jdbc:mysql://localhost:3306/appdb,
min-pool-size=5,
max-pool-size=15,
jndi-name=java:/jdbc/niwads,
enabled=true,
validate-on-match=true,
valid-connection-checker-class-name=org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker,
exception-sorter-class-name=org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter
)
Created Security Domain with GUI in Browser, not CLI. With final result was like this:
<security-domain name="niwasdnew" cache-type="default">
<authentication>
<login-module code="Database" flag="required">
<module-option name="dsJndiName" value="java:/jbdc/niwads" />
<module-option name="principalsQuery" value="select password as 'Password' from user_account where nickname=?" />
<module-option name="rolesQuery" value="select r.rolname as 'Role', r.rolname as 'RoleGroup' from user_account u, role r where r.id=u.role_key and u.nickname=?" />
</login-module>
</authentication>
Created and added jboss-web.xml to WEB-INF:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<security-domain>niwasdnew</security-domain>
</jboss-web>
My web.xml with FORM authentication roles and so so:
<security-constraint>
<web-resource-collection>
<web-resource-name>pages for masters</web-resource-name>
<url-pattern>/sections/master/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>pages for gardeners</web-resource-name>
<url-pattern>/sections/gardener/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>gardener</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/login.xhtml</form-login-page>
<form-error-page>/error.xhtml</form-error-page>
</form-login-config>
</login-config>
<security-role>
<role-name>admin</role-name>
</security-role>
<security-role>
<role-name>gardener</role-name>
</security-role>
After all this, I start my project on WildFly, I see my welcome page, go to login page, fill needed fields press Login Button and it redirects me to appropriate place depend on user's role
BUT I see only the "Forbidden" error page!
What I'm doing wrong? What I've missed?
Upvotes: 0
Views: 3545
Reputation: 330
Finaly I found the answer to my question. On this recourse
It shows me that I make a mistake at step 3 where I write module-option name="rolesQuery"
in SQL sentense: select r.rolname as 'Role', r.rolname as 'RoleGroup' from user_account u, role r where r.id=u.role_key and u.nickname=?
From resource
Note: Value of RoleGroup column always has to be Roles (with capital 'R'). This is specific to JBoss.
So propper SQL sentence do work, in my case — select r.rolname as 'Role', 'Roles' as 'RoleGroup' from user_account u, role r where r.id=u.role_key and u.nickname=? — the right answer
Upvotes: 1