Monday, June 22, 2009

Cost Bonded Insured Ontario

Authentication by database using Apache 2.2.x mod_dbd, mod_auth_user mod_authn_dbd and Windows 2003 Server


In a previous post, I explain how to configure the access to a directory using the utility htpasswd which works for few users and must be done manually for each . The authentication database offers a more flexible configuación less laborious and ideal for environments where the number of users is high. For this exercise I will use an Oracle Database 11g (11.1.0.7.0) which is supported under the Apache documentation is on file
[APACHE_HOME] \\ README-win32.txt
. You must have Oracle client installed and properly configure a connection string (tnsnames) like the following image





opens a sqlplus session

C: \\> sqlplus sys as sysdba SQL * Plus: Release 11.1.0.7.0 - Production on Sun June 21 23:17:37 2009 Copyright (c) 1982, 2008, Oracle. All rights reserved.
Enter password: Connected to

: Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production With the Partitioning , OLAP, Data Mining and Real Application Testing options SQL> create a user


SQL> ; create apache user account unlock IDENTIFIED BY test;


User created
assign it the appropriate privileges

SQL> grant create session to apache;

Grant succeeded.

SQL> grant resource to apache;

Grant succeeded.
connect to the apache user, create the table and inserts a record which will serve the connection tests

SQL> conn apache / test
Connected.
SQL> create table users (username
2 varchar2 (10 byte),
3 passwd varchar2 (10 byte)
4);

Table created.

SQL> insert into users (username, passwd) values \u200b\u200b('Sergio', 'test');

1 row created.
SQL> commit; Commit complete.
Update your Apache configuration file modules / mod_authn_dbd.so
LoadModule dbd_module modules / mod_dbd.so and finally add the following. Do not forget
create the directory C: \\ Apache22 \\ htdocs \\ private
mod_dbd # oracle configuration

DBDriver DBDParams "testserver host = port = 1521 user = apache pass = test dbname = testdb" DBDMin 4 DBDKeep 8 20 DBDExptime DBDMax 300
\u0026lt;Directory "C:/Apache22/htdocs/private">
# core authentication and mod_auth_basic configuration
# for mod_authn_dbd

AuthType Basic AuthName "Private directory" dbd
AuthBasicProvider

# core Authorization
configuration Require valid-user # mod_authn_dbd

SQL query to authenticate a user
AuthDBDUserPWQuery "SELECT passwd FROM users WHERE username =% s"
\u0026lt;/ Directory> Lift

Apache, but do it from the command line because if you do not appreciate it from the console error messages that might occur.

C: \\ Apache22 \\ bin> httpd-k start
if you do not see any error message it is worth reviewing the file
[APACHE_HOME] \\ logs \\ error.log

And finally make the connection test from a browser










Troubleshooting Q: I get the following message when I try to build Apache:

C: \\ Apache22 \\ bin> httpd-k start
Syntax error on line 485 of C: / Apache22/conf/httpd.conf:
Invalid command 'DBDriver' Perhaps misspelled or defined by a module not included in the server configuration

R: You have not enabled on your file
[APACHE_HOME] \\ conf \\ httpd.conf line


dbd_module LoadModule modules / mod_dbd.so


P: The following message appears when I try to build Apache:

C: \\ Apache22 \\ bin> httpd-k start Syntax error on line 498 of C: / Apache22/conf/httpd.conf: Unknown AuthN provider: dbd
R: You have not enabled on your file
[APACHE_HOME] \\ conf \\ httpd.conf line

authn_dbd_module LoadModule modules / mod_authn_dbd.so
Q: I built Apache, but does not connect to the database, review
file [APACHE_HOME] \\ logs \\ error.log
and get the following error

(20014) Internal error: DBD: Can not connect to oracle
(20014) Internal error: DBD: failed to initialise

A. The error message is generic and only tells you what happened without any clue to the cause, it is here where you review what you did from the beginning to determine what happens and how to fix.
Check the file


[APACHE_HOME] \\ README-win32.txt
and verify that the version of the database engine you are using is supported by the version of Apache installed.

Check that the parameters are correct

DBDParams. In this regard, the

Apache documentation is not correct in terms of specifying Oracle and Oracle


user, pass, dbname, server
however, specifically "server" is not recognized as valid and It is therefore necessary to use "host" and "port" instead.

P: The browser asks for my username and password but after to write them I get the error message "Internal Server Error" A: Check your file
[APACHE_HOME] \\ logs \\ error.log
looking for specifics. You can find, for example, the query you specified in the parameter
AuthDBDUserPWQuery
is not correct (20014) Internal error: DBD: failed to prepare SQL statements: ORA-00904: "USER_NAME": invalid identifier ( 20014) Internal error: DBD: failed to initialise

Reference http://httpd.apache.org/docs/2.2/mod/mod_authn_dbd.html



0 comments:

Post a Comment