You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by sohsoh <bo...@gmail.com> on 2012/09/29 10:57:20 UTC

Problems with Realm

Hello Tomcatters,

I am beginner in development, I wanted to do the user authentication, I am I
followed a tutorial for it to the letter, but in the final step I fell into
a problem that I did not arrive for a week of web search to solve it
-- after login he goes search on the database and when it's a fake login or
passe  he derige me to the error page<form-error-page> but when the password
and login are correct i get HTTP 403 and that is my problem it does not
Derige me to my desired page

brief  all I've done is
>> in web.xml

  <security-constraint>
       <display-name>AdminConstraint</display-name>
       <web-resource-collection>
           <web-resource-name>Admin</web-resource-name>
           <description>Only for administrators</description>
           <url-pattern>/pages/protected/admin/*</url-pattern>
       </web-resource-collection>
       <auth-constraint>
           <role-name>ADMIN</role-name>
           </auth-constraint>
   </security-constraint> 
    <login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
      <form-login-page>/pages/public/login.xhtml</form-login-page>
      <form-error-page>/pages/public/loginError.xhtml</form-error-page>
    </form-login-config>
  </login-config>
   <security-role>
       <role-name>ADMIN</role-name>
   </security-role>

>> in server.xml 

<Context path="/myapp" docBase="myapp" >
<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/mabase" userTable="users"
userNameCol="name" userCredCol="pass" userRoleTable="user_roles"
connectionName="tomcat" connectionPassword="TomcatPassword"
roleNameCol="role_name" debug="99" />
</Context>


*where is the error?? is what I need to add anything else??*



--
View this message in context: http://tomcat.10.n6.nabble.com/Problems-with-Realm-tp4987265.html
Sent from the Tomcat - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Problems with Realm

Posted by Konstantin Kolinko <kn...@gmail.com>.
2012/9/29 sohsoh <bo...@gmail.com>:
> Hello Tomcatters,
>
> I am beginner in development, I wanted to do the user authentication, I am I
> followed a tutorial for it to the letter, but in the final step I fell into
> a problem that I did not arrive for a week of web search to solve it
> -- after login he goes search on the database and when it's a fake login or
> passe  he derige me to the error page<form-error-page> but when the password
> and login are correct i get HTTP 403 and that is my problem it does not
> Derige me to my desired page
>

It is hard to understand your writing.

1. Can you describe your actions and the behaviour that you observe
step-by-step, chronologically?

http://www.catb.org/~esr/faqs/smart-questions.html

2. What pages are you accessing? What are their URLs?
3. What is the actual behaviour that you see?
4. What behaviour did you expect? What do you want?

5. What is in the logs? What is in Tomcat's access log?


> brief  all I've done is
>>> in web.xml
>
>   <security-constraint>
>        <display-name>AdminConstraint</display-name>
>        <web-resource-collection>
>            <web-resource-name>Admin</web-resource-name>
>            <description>Only for administrators</description>
>            <url-pattern>/pages/protected/admin/*</url-pattern>
>        </web-resource-collection>
>        <auth-constraint>
>            <role-name>ADMIN</role-name>
>            </auth-constraint>
>    </security-constraint>
>     <login-config>
>     <auth-method>FORM</auth-method>
>     <form-login-config>
>       <form-login-page>/pages/public/login.xhtml</form-login-page>
>       <form-error-page>/pages/public/loginError.xhtml</form-error-page>
>     </form-login-config>
>   </login-config>
>    <security-role>
>        <role-name>ADMIN</role-name>
>    </security-role>
>
>>> in server.xml
>
> <Context path="/myapp" docBase="myapp" >
> <Realm className="org.apache.catalina.realm.JDBCRealm"
> driverName="com.mysql.jdbc.Driver"
> connectionURL="jdbc:mysql://localhost:3306/mabase" userTable="users"
> userNameCol="name" userCredCol="pass" userRoleTable="user_roles"
> connectionName="tomcat" connectionPassword="TomcatPassword"
> roleNameCol="role_name" debug="99" />
> </Context>
>
>
> *where is the error?? is what I need to add anything else??*
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Problems with Realm

Posted by sohsoh <bo...@gmail.com>.
I resolved it by changing the column of login from "name" to user_name ,,,
thanks to all those who want to help me



--
View this message in context: http://tomcat.10.n6.nabble.com/Problems-with-Realm-tp4987265p4987275.html
Sent from the Tomcat - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Problems with Realm

Posted by Martin Gainty <mg...@hotmail.com>.
Jose is correct
did you implement these steps from the documentation:
http://tomcat.apache.org/tomcat-7.0-doc/funcspecs/fs-jdbc-realm.html
Acquire the one and only connection [Current] or acquire a connection
        from the connection pool [Requested].
MG>do you have a valid connection handle?

Select the one and only row from the user's table for this user,
        and retrieve the corresponding password column.  If zero rows (or
        more than one row) are found, return null.
MG>do you have the password retrieved from users table that corresponds to username?

Authenticate the user by comparing the (possibly encrypted) password
        value that was received against the password presented by the user.
        If there is no match, return null.
MG>do the passwords match?

Acquire a List of the security roles assigned to the
        authenticated user by selecting from the roles table.
MG>do you have a list of roles from the roles table corresponding to the supplied username?

Construct a new instance of class
        org.apache.catalina.realm.GenericPrincipal, passing as
        constructor arguments:  this realm instance, the authenticated
        username, and a List of the security roles associated
        with this user.
MG>are you able to construct GenericPrincipal object?

WARNING - Do not attempt to cache and reuse previous
        GenericPrincipal objects for a particular user, because
        the information in the directory server might have changed since the
        last time this user was authenticated.Return the newly constructed GenericPrincipal.
Buena Suerte,
Martin 
______________________________________________ 
Porfavor..no altere ni interrumptir esta communicacion..Gracias


> Date: Sat, 29 Sep 2012 01:57:20 -0700
> From: boudali.souhail@gmail.com
> To: users@tomcat.apache.org
> Subject: Problems with Realm
> 
> Hello Tomcatters,
> 
> I am beginner in development, I wanted to do the user authentication, I am I
> followed a tutorial for it to the letter, but in the final step I fell into
> a problem that I did not arrive for a week of web search to solve it
> -- after login he goes search on the database and when it's a fake login or
> passe  he derige me to the error page<form-error-page> but when the password
> and login are correct i get HTTP 403 and that is my problem it does not
> Derige me to my desired page
> 
> brief  all I've done is
> >> in web.xml
> 
>   <security-constraint>
>        <display-name>AdminConstraint</display-name>
>        <web-resource-collection>
>            <web-resource-name>Admin</web-resource-name>
>            <description>Only for administrators</description>
>            <url-pattern>/pages/protected/admin/*</url-pattern>
>        </web-resource-collection>
>        <auth-constraint>
>            <role-name>ADMIN</role-name>
>            </auth-constraint>
>    </security-constraint> 
>     <login-config>
>     <auth-method>FORM</auth-method>
>     <form-login-config>
>       <form-login-page>/pages/public/login.xhtml</form-login-page>
>       <form-error-page>/pages/public/loginError.xhtml</form-error-page>
>     </form-login-config>
>   </login-config>
>    <security-role>
>        <role-name>ADMIN</role-name>
>    </security-role>
> 
> >> in server.xml 
> 
> <Context path="/myapp" docBase="myapp" >
> <Realm className="org.apache.catalina.realm.JDBCRealm"
> driverName="com.mysql.jdbc.Driver"
> connectionURL="jdbc:mysql://localhost:3306/mabase" userTable="users"
> userNameCol="name" userCredCol="pass" userRoleTable="user_roles"
> connectionName="tomcat" connectionPassword="TomcatPassword"
> roleNameCol="role_name" debug="99" />
> </Context>
> 
> 
> *where is the error?? is what I need to add anything else??*
> 
> 
> 
> --
> View this message in context: http://tomcat.10.n6.nabble.com/Problems-with-Realm-tp4987265.html
> Sent from the Tomcat - User mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
 		 	   		  

Re: Problems with Realm

Posted by sohsoh <bo...@gmail.com>.
from log file

29 sept. 2012 08:50:36 org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
29 sept. 2012 08:50:36 org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
29 sept. 2012 08:51:52 org.apache.catalina.realm.JDBCRealm getRoles
GRAVE: Exception pendant le traitement de l'authentification
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column
'name' in 'where clause'
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
	at com.mysql.jdbc.Util.getInstance(Util.java:381)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2554)
	at
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1761)
	at
com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1912)
	at org.apache.catalina.realm.JDBCRealm.getRoles(JDBCRealm.java:644)
	at org.apache.catalina.realm.JDBCRealm.authenticate(JDBCRealm.java:436)
	at org.apache.catalina.realm.JDBCRealm.authenticate(JDBCRealm.java:361)
	at
org.apache.catalina.authenticator.FormAuthenticator.authenticate(FormAuthenticator.java:259)
	at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:449)
	at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
	at
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
	at
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
	at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1555)
	at java.lang.Thread.run(Thread.java:619)



--
View this message in context: http://tomcat.10.n6.nabble.com/Problems-with-Realm-tp4987265p4987274.html
Sent from the Tomcat - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Problems with Realm

Posted by Jose María Zaragoza <de...@gmail.com>.
Have a look at Tomcat log files


2012/9/29 sohsoh <bo...@gmail.com>:
> I tried and the same problem !
>
>
>
> --
> View this message in context: http://tomcat.10.n6.nabble.com/Problems-with-Realm-tp4987265p4987268.html
> Sent from the Tomcat - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Problems with Realm

Posted by sohsoh <bo...@gmail.com>.
I tried and the same problem !



--
View this message in context: http://tomcat.10.n6.nabble.com/Problems-with-Realm-tp4987265p4987268.html
Sent from the Tomcat - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Problems with Realm

Posted by Jose María Zaragoza <de...@gmail.com>.
Maybe the web page requested (under /pages/protected/admin/*)
is allowed to visit after you login, but that page could need to
access to resources stored under others folders non-authorized

Try to access a simple web page ( a blank page ) stored under
/pages/protected/admin/
to test if realm mechanism is working fine





2012/9/29 sohsoh <bo...@gmail.com>:
> Hello Tomcatters,
>
> I am beginner in development, I wanted to do the user authentication, I am I
> followed a tutorial for it to the letter, but in the final step I fell into
> a problem that I did not arrive for a week of web search to solve it
> -- after login he goes search on the database and when it's a fake login or
> passe  he derige me to the error page<form-error-page> but when the password
> and login are correct i get HTTP 403 and that is my problem it does not
> Derige me to my desired page
>
> brief  all I've done is
>>> in web.xml
>
>   <security-constraint>
>        <display-name>AdminConstraint</display-name>
>        <web-resource-collection>
>            <web-resource-name>Admin</web-resource-name>
>            <description>Only for administrators</description>
>            <url-pattern>/pages/protected/admin/*</url-pattern>
>        </web-resource-collection>
>        <auth-constraint>
>            <role-name>ADMIN</role-name>
>            </auth-constraint>
>    </security-constraint>
>     <login-config>
>     <auth-method>FORM</auth-method>
>     <form-login-config>
>       <form-login-page>/pages/public/login.xhtml</form-login-page>
>       <form-error-page>/pages/public/loginError.xhtml</form-error-page>
>     </form-login-config>
>   </login-config>
>    <security-role>
>        <role-name>ADMIN</role-name>
>    </security-role>
>
>>> in server.xml
>
> <Context path="/myapp" docBase="myapp" >
> <Realm className="org.apache.catalina.realm.JDBCRealm"
> driverName="com.mysql.jdbc.Driver"
> connectionURL="jdbc:mysql://localhost:3306/mabase" userTable="users"
> userNameCol="name" userCredCol="pass" userRoleTable="user_roles"
> connectionName="tomcat" connectionPassword="TomcatPassword"
> roleNameCol="role_name" debug="99" />
> </Context>
>
>
> *where is the error?? is what I need to add anything else??*
>
>
>
> --
> View this message in context: http://tomcat.10.n6.nabble.com/Problems-with-Realm-tp4987265.html
> Sent from the Tomcat - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org