Hi Murat,

These seem to be common problems getting going with Rife; I am CC'ing the RIFE Users list in order to (hopefully :) help some other folks who may be
having the same startup issues as well.

DB authentication is pretty easy once you get the hang of it; the key thing to remember is that out of the box Rife's authenication is very simple and keeps a minimal amount of infomration, namely: a) the user name, b) a long int or numeric User ID, c) the password, and d) a listing of roles the system knows about, and e) a mapping of numeric User IDs to the role(s) that the user ID is allowed to act under. All other info about the user is up to you and is kept in a structure (bean) of your own design. The two bits of info (Rife's auth table and your account beans) are tied together using Rife's metadata facilities by mapping the numeric user ID to your own expanded data about the user.

All of this is pretty well documented in http://rifers.org/wiki/ display/RIFE/GuideAuthentication

There are basically 5 things you need to do:

1) Enable database (as opposed to the XML-in-memory version) authentication in your site XML file.

2) Add a participant (Rife's term for the components run as part of the framework's internal startup processes) that will create the database tables that will hold the user credentials; this is less clear (I'm not sure this structure is shown explicitly anywhere in the docs -- This was the example that you saw Geert refer me to...), but involves making a new participant java file that gets run when the application starts up. It's contents are basically this:

package com.zeitgeist.nela.participants;

import com.uwyn.rife.authentication.credentialsmanagers.DatabaseUsers;
import com.uwyn.rife.authentication.credentialsmanagers.DatabaseUsersFactory; import com.uwyn.rife.authentication.credentialsmanagers.RoleUserAttributes; import com.uwyn.rife.authentication.remembermanagers.DatabaseRememberFactory; import com.uwyn.rife.authentication.sessionmanagers.DatabaseSessionsFactory;
import com.uwyn.rife.database.Datasource;
import com.uwyn.rife.database.Datasources;
import com.uwyn.rife.rep.BlockingParticipant;
import com.uwyn.rife.tools.ExceptionUtils;
import com.uwyn.rife.config.Config;

import java.util.logging.Logger;

/*
* This participant creates the structure that's needed for database authentication.
* It also populates the credentials with a default role and admin user.
* You should change this default user before putting your application in
* production.
*/
public class CreateAuthenticationStructure extends BlockingParticipant {
        protected void initialize() {
Datasource ds = Datasources.getRepInstance().getDatasource (Config.getRepInstance().getString("DATASOURCE"));

        try {
                        // Install the users structure and add the initial role
                        DatabaseUsers users = 
DatabaseUsersFactory.getInstance(ds);
                        users.install();
                        String admin_role = "admin";
                        String user_role = "user";
                        String maint_role = "maint";
                        users.addRole(admin_role);
                        users.addRole(user_role);
users.addRole(maint_role); // these are my examples... you can create as many roles as you need
                        // The password is 'password', don't forget to change 
this.
                        // Use the following command with the rife jar in the 
classpath
                        // to create a newly SHA encrypted password:
                        //     java com.uwyn.rife.tools.StringEncryptor -e 
"SHA:yourpassword"
users.addUser("admin", new RoleUserAttributes("***PUT-YOUR-ADMIN- PASSWORD-HASH-HERE***", new String[] {admin_role}));
                        
                        // Install authentication sessions structure
                        DatabaseSessionsFactory.getInstance(ds).install();
// Install remember-me structure -- allows users to remain logged in using a browser cookie that holds session info
                        DatabaseRememberFactory.getInstance(ds).install();
                } catch (Exception e) {
Logger.getLogger("com.uwyn.rifejumpstart").warning("The authentication database structure couldn't be installed, it probably already exists."); Logger.getLogger("com.uwyn.rifejumpstart").warning (ExceptionUtils.getExceptionStackTraceMessages(e));
                }
        }
}


3) Design a bean (for example "account") that will contain any additional info that you want users to supply when they register and will be kept around as the info about their account. You could store user preferences here too, however if you do, any time you want to add user-customizable features to your system you'll have to re-write the account class. Better to make a separate class (or classes) for prefs and tie it to the user's numeric ID which Rife stores in its authentication tables.

4) Make a form which people will use to register and populate the account structure with. You should decide if people get the accounts activated immediately as part of the registration form -- this is easy but of course can allow robots to make untold numbers of accounts on your system -- or, if people should get a confirmation email that they have to click through in order to have their accounts activated. This requires more coding, but gives you more control over how people can get access to your application. The in-line version of account activation is covered in http://tinyurl.com/2h4bpl on the Rife mailing list.

5) Lastly, define which parts of your application are "protected" by the roles you have defined in your authentication database. This is covered in several places in the cookbook entry above. This will allow you to have "user" content versus "administrative" content. You can, of course, define as many roles as you need (see the auth structure initialization, above).

Another good place to look for working examples is in the sources to Rife applications that Geert has made available. A pretty straightforward example of how to set up DB authentication can be found in the sources to Bamboo (https://bamboo.dev.java.net/). It actually does all of the things I listed above, including handling the email-based click-though account verification.


I hope this helps. (Geert, pls let me know if I've gone off into the weeds on any of the above...)

regards,
  David

On Jan 31, 2007, at 4:05 AM, [EMAIL PROTECTED] wrote:

Hi david i am murat, i am new to rife and of course have some prblems with it. I want to have database authentication. İ am searching for an exampla for it for a day but i cold not find enough (at least for me) information for it. Gert replied to your message by giving a link that he said there is an example of db authentication. The link he gave is http://rifers.org:8088/ changelog/rifers/?cs=3586 but this is not working now.
Could you help me how i can make a db authentication?
Thanks


------------------------------------------------------------------------ -------------------
                                          David HM Spector
spector (at) zeitgeist.com http://www.zeitgeist.com/ voice: +1 631.261.5013 fax: +1 212.656.1443
                                                    ~ ~ ~
"New and stirring things are belittled because if they are not belittled, the humiliating question arises, 'Why then are you not taking part in them?'" --H. G. Wells

_______________________________________________
Rife-users mailing list
[email protected]
http://lists.uwyn.com/mailman/listinfo/rife-users

Reply via email to