You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by ipas <mi...@gmail.com> on 2011/07/05 09:36:10 UTC

Re: Shiro Jdbc Realm Mysql.

Hi, 
Here are my DataSpurce configurations . And i think there is no problem in
connection.

jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
                jdbcRealm.permissionsLookupEnabled = true
                jdbcRealm.authenticationQuery = "SELECT user_pass FROM users
WHERE user_name = ?"
                jdbcRealm.userRolesQuery = "SELECT role_name FROM user_roles
WHERE user_name = ?"
                jdbcRealm.permissionsQuery = "SELECT permission FROM
roles_permissions WHERE role_name = ?"
				ds = org.apache.commons.dbcp.BasicDataSource
				ds.driverClassName = com.mysql.jdbc.Driver
				ds.username = user
				ds.password = pass
				ds.url = jdbc:mysql://localhost:3306/iaau
				ds.maxActive = 10
                jdbcRealm.dataSource = $ds

But still it is giving me exception There was a SQL error while
authenticating user [admin] . 
How to see if the sql query is correct? 

Thank you.

--
View this message in context: http://shiro-user.582556.n2.nabble.com/Shiro-Jdbc-Realm-Mysql-tp6519616p6548700.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: Shiro Jdbc Realm Mysql.

Posted by Phil Steitz <ph...@gmail.com>.
On 7/6/11 4:17 AM, ipas wrote:
> Hi, Thanks for reply.
> The thing is i can not find full stack trace. It is not showing me on
> eclipse and i tried to find it on apache tomcat server logs too but without
> luck. 
>
> In Eclipse it is giving only one line of exception which i wrote above.

Your code that does the login must be swallowing the
AuthenticationException.  In your code that does the authentication,
try catching the AuthenticationException and dumping its stack trace
(like the quickstart example):

try {
    currentUser.login( token );
    //if no exception, that's it, we're done!
} catch ( UnknownAccountException uae ) {
    //username wasn't in the system, show them an error message?
} catch ( IncorrectCredentialsException ice ) {
    //password didn't match, try again?
} catch ( LockedAccountException lae ) {
    //account for that username is locked - can't login.  Show them a message?
} 
    ... more types exceptions to check if you want ...
} catch ( AuthenticationException ae ) {
    ae.printStackTrace();
}

Phil


> Thank you.
>
>
> --
> View this message in context: http://shiro-user.582556.n2.nabble.com/Shiro-Jdbc-Realm-Mysql-tp6519616p6553999.html
> Sent from the Shiro User mailing list archive at Nabble.com.
>


Re: Shiro Jdbc Realm Mysql.

Posted by ipas <mi...@gmail.com>.
Ok this issue is resolved. It is up and running now. 
I just used  https://github.com/eneuwirt/vaadin-shiro-simple
vaadin-shiro-simple  as a background and made changes to use Shiro
jdbcRealm. It is obvious that there is no need to make changes in Java code.
So changes made only in shiro.ini and in particular MySql database.

Content of shiro.ini is :
[main]
jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
jdbcRealm.permissionsLookupEnabled = true
jdbcRealm.authenticationQuery = SELECT password FROM users WHERE username =
?
jdbcRealm.userRolesQuery = SELECT role_name FROM user_roles WHERE username =
?
jdbcRealm.permissionsQuery = SELECT roleper FROM roles_permissions WHERE
role_name = ?
ds = com.jolbox.bonecp.BoneCPDataSource
ds.driverClass=com.mysql.jdbc.Driver
ds.jdbcUrl=jdbc:mysql://localhost:3306/dbname
ds.username = username
ds.password = password
jdbcRealm.dataSource=$ds

database:
CREATE TABLE IF NOT EXISTS `roles_permissions` (
 `roleper` char(50) NOT NULL,
 `role_name` char(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE IF NOT EXISTS `users` (
 `username` char(50) NOT NULL,
 `password` char(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE IF NOT EXISTS `user_roles` (
 `role_name` char(50) NOT NULL,
 `username` char(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

For maven users pom.xml dependencies:

<repository>
		  <releases>
                                  <enabled>true</enabled>
                  </releases>
    		 <id>bonecp-repo</id>
 		 <name>BoneCP Repository</name>
		 <url>http://jolbox.com/bonecp/downloads/maven</url>
</repository>

                <dependency>
			<groupId>org.apache.shiro</groupId>
			<artifactId>shiro-core</artifactId>
			<version>1.1.0</version>
		</dependency>

		<dependency>
			<groupId>org.apache.shiro</groupId>
			<artifactId>shiro-web</artifactId>
			<version>1.1.0</version>
		</dependency>

		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>1.6.1</version>
		</dependency>
		<dependency>
			<groupId>com.jolbox</groupId>
			<artifactId>bonecp</artifactId>
			<version>0.6.5</version>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.18</version>
		</dependency>
		<dependency>
			<groupId>commons-logging</groupId>
			<artifactId>commons-logging</artifactId>
			<version>1.1.1</version>
		</dependency>

Thats it , it is working just like shiro-vaadin-simple.

--
View this message in context: http://shiro-user.582556.n2.nabble.com/Shiro-Jdbc-Realm-Mysql-tp6519616p7000979.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: Shiro Jdbc Realm Mysql.

Posted by ipas <mi...@gmail.com>.
Hi, Thanks for reply.
The thing is i can not find full stack trace. It is not showing me on
eclipse and i tried to find it on apache tomcat server logs too but without
luck. 

In Eclipse it is giving only one line of exception which i wrote above.

Thank you.


--
View this message in context: http://shiro-user.582556.n2.nabble.com/Shiro-Jdbc-Realm-Mysql-tp6519616p6553999.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: Shiro Jdbc Realm Mysql.

Posted by Jared Bunting <ja...@digitalreasoning.com>.
Nothing jumps out at me. 

However, all that error tells us is that there was a SQL exception.     
The JdbcRealm class logs this entire exception.  It also throws an
AuthenticationException with the cause set as the SQLException.  Do you
have a full stack trace for this error?  That would likely be very telling.