Hello All

My mistake Aykut you are using glassfish. Sorry it is a late night
here in Africa and my reading skills seems to get weaker with the old
age.

The first step would be to make sure you database complies to the JDBC
Realm Requirements.

1) The group name column absolutely needs to be a string. So, for
example, if you use numeric foreign keys in your database, you will
need to create a view that maps user names to user groups by string.
You then use this database view for the group table/group name column
fields. Thus if you have a usergroup table the group column HAS to be
a string.

2) Please make sure that you don't use reserved words such as password
as MySQL can get confused. I made my username = uname and my password
fields = PWD.

Secondly here is some guide lines and pitfalls to watch for when
setting up JDBC Realm authentication:

1) Setup the connection pool resource in the GlassFish Administration
console.

a) If you are using netbeans without installing glassfish separately
please make sure you install the mysql jdbc drivers for glassgish(the
version of glassfish  at       comes with netbeans do NOT have these
drivers) look at this link to get some more information
http://codepimpsdotorg.blogspot.com/2007/12/glassfish-jdbc-realm-authentication.html

b) Configure you connection pool. In the first step of the wizard give
your pool a name i.e. javapassionpool then select javax.sql.Datasource
from the Resource drop down and select mysql from the database vendor
drop down. Click on next. In this step will in your database name,
username and password according to most documents however please make
sure that the URL and url fields have a complete string ie not
jdbc:mysql://:3306/ but something like jdbc:mysql://:3306/
mydatabasename. If you don't complete your URL entries you will
encounter database errors later on.

c) Click on the ping button to make sure that the connection pool is
working(by the way even if you DON'T fill in the URL fields ping will
work which is a bug according to me)

d) Setup your JDBC resource for the connection pool.

2) Setup the JDBC Realm

a) Give the realm a name.

b) Select the JDBCRealm class from the class type drop down list.

c) Make the JAAS context jdbcRealm

d) Fill out the User Table, UserName, Password Column, Group Table and
Group Name Column with your table and column names (NOTE: these must
all be string values)

e) The Digest Algorithm column is special. If you will be storing
encrypted passwords in our database please make sure that you indicate
which encryption algorithm you are using.  To start of with store plan
text passwords in your database and set the Digest Algorithm column to
none. If you leave it blank it does not work it has to be none or
something like MD5,ShA1 etc.

3) Now setup your web.xml to reflect the security.

a) Add security roles (using the security tab in Netbeans)

b) Add Secured resources and add the security roles that can access
the secured resources.

c) Example:

<security-role>
        <description/>
        <role-name>administrator</role-name>
</security-role>

<security-constraint>
        <display-name>SecuredResources</display-name>
        <web-resource-collection>
            <web-resource-name>Secured</web-resource-name>
            <description/>
            <url-pattern>/Secure/*</url-pattern>
            <http-method>GET</http-method>
            <http-method>POST</http-method>
            <http-method>HEAD</http-method>
            <http-method>PUT</http-method>
            <http-method>OPTIONS</http-method>
            <http-method>TRACE</http-method>
            <http-method>DELETE</http-method>
        </web-resource-collection>
        <auth-constraint>
            <description/>
            <role-name>administrator</role-name> /* this is the role
you defined earlier
            </auth-constraint>
        </security-constraint>

4) Add security role mappings to your sun-web.xml file on the security
tab. This will map your user group to a web.xml <auth-constraint>

a) Let say you call the administrators group admin in your database
you will have to map the admin group(database) to the administrator
group in your web.xml.

b) Example:
  <security-role-mapping>
    <role-name>administrator</role-name>  /* name/value in your
web.xml */
    <group-name>admin</group-name>       /* name/value of the group in
your database remember thi shas to be a string */
  </security-role-mapping>

6) test your setup.

Please let me know if you have anymore errors as I have done this
several time over and ran into walls more than once.

Cheers
Neil

http://news.bbc.co.uk/2/hi/8248056.stm
<To Know more about me read the article, I complained about ADSL
speeds in Africa!>

On Feb 16, 8:21 pm, Neil Franken <ncjfran...@gmail.com> wrote:
> Hi There
>
> New to the group but eager to help. I also had a hard time to get JDBC
> Realm Authentication working at first. Are you using Glassfish? If you
> are using GF I might be able to help. To the all Asians on the list
> Happy New Year!
>
> Regards
> Neil
>
> On Feb 9, 9:42 pm, aykut kanyýlmaz <onbira...@gmail.com> wrote:
>
> > hi dear frends,
> > i have a problem. i want to authenticate from mysql user table. but it is
> > not working.
> > in web.xml
>
> >       <display-name>AdminConstraints</display-name>
> >         <web-resource-collection>
> >             <web-resource-name>Admin</web-resource-name>
> >             <url-pattern>/secureAdmin/*</url-pattern>
> >         </web-resource-collection>
> >         <auth-constraint>
> >             <role-name>Admin</role-name>
> >             <role-name>User</role-name>
> >         </auth-constraint>
> >     </security-constraint>
> >     <security-constraint>
> >         <display-name>UserConstraint</display-name>
> >         <web-resource-collection>
> >             <web-resource-name>User</web-resource-name>
> >             <url-pattern>/secureUser/*</url-pattern>
> >         </web-resource-collection>
> >         <auth-constraint>
> >             <description/>
> >             <role-name>User</role-name>
> >             <role-name>Admin</role-name>
> >         </auth-constraint>
> >     </security-constraint>
> >     <login-config>
> >         <auth-method>FORM</auth-method>
> >         <realm-name>JDBCAuth</realm-name>
> >         <form-login-config>
> >             <form-login-page>/login.jsp</form-login-page>
> >             <form-error-page>/loginError.jsp</form-error-page>
> >         </form-login-config>
> >     </login-config>
> >     <security-role>
> >         <description/>
> >         <role-name>Admin</role-name>
> >     </security-role>
> >     <security-role>
> >         <description/>
> >         <role-name>User</role-name>
> >     </security-role>
> > in login.jsp
> >   <form action="j_security_check" method="POST">
> >               Username:<input type="text" name="j_username"><br>
> >               Password:<input type="password" name="j_password">
> >               <input type="submit" value="Login">
> >             </form>
>
> > in glassfish admin console, i added a securty realm called 'JDBCAuth'. i
> > configured this realm's username, password etc.. column but it is not
> > working:(
>
> > i want to use this in my next project help me please
> > AYKUT KANYILMAZ

-- 
You received this message because you are subscribed to the Google
Groups "Java EE (J2EE) Programming with Passion!" group.
To post to this group, send email to
java-ee-j2ee-programming-with-passion@googlegroups.com
To unsubscribe from this group, send email to
java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en

Reply via email to