[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jetspeed-user
Subject:    creation of PSML
From:       Pierre Henry <phenry () proconcept ! ch>
Date:       2003-01-31 10:38:04
[Download RAW message or body]


Hi all !
I am using 1.4b3 and psml files (not db).
Some months ago I wrote my own authentication class. I have some users that
are imported from another application into the Jetspeed database but don't
have any psml associated. What this authentication classe's login method do
is create a default psml if the user's psml doesn't exist.
It worked fine with 1.4b1 and created a psml apparently by copying the
turbine's user psml.
Now it creates like one pane with some rss portlets (apacheweek, mozilla and
xmlhack) but there is just this pane and the change pane bar doesn't show up
(and its also here you can customize the page ato add panes) and it doesnt'
save any psml file.
Why doesn't it work any more ? Is it because of the different version or is
there a parameter I should define or anything I omitted or did wrong ?
I would like to recreate the behaviour it had. How can I copy a user's psml
and assign it to another user ? I would define a 'model' user (or I could
use the anon user) and when a user logs in for the first time he has this
default psml.

I don't care wether I do it this way or any other way. Thanks for your
suggestions and ideas !

I also noticed that the create user action doesn't work. It gives a
nullPointerException, seems to be because the username field (and maybe
others) from the form is not passed well. Has anybody noticed this behavior
or is it due to a misconfiguration ?


Here is my authentication class :

//package and import statements...
package ch.proconcept.portal.security.services;

import javax.servlet.ServletConfig;

import org.apache.turbine.util.Log;
import org.apache.turbine.services.TurbineBaseService;
import org.apache.turbine.services.TurbineServices;
import org.apache.turbine.services.InitializationException;
import org.apache.turbine.services.resources.ResourceService;


import org.apache.jetspeed.om.security.JetspeedUser;
import org.apache.jetspeed.om.security.JetspeedUserFactory;
import org.apache.jetspeed.om.security.UserNamePrincipal;

import org.apache.jetspeed.services.JetspeedUserManagement;
import org.apache.jetspeed.services.JetspeedSecurity;
import org.apache.jetspeed.services.security.PortalAuthentication;
import org.apache.jetspeed.services.security.turbine.TurbineAuthentication;
import org.apache.jetspeed.services.security.turbine.TurbineUserManagement;
import org.apache.jetspeed.services.security.JetspeedSecurityService;
import org.apache.jetspeed.services.security.LoginException;
import org.apache.jetspeed.services.security.FailedLoginException;
import org.apache.jetspeed.services.security.UnknownUserException;
import org.apache.jetspeed.services.security.UserException;
import org.apache.jetspeed.services.security.JetspeedSecurityException;
import org.apache.jetspeed.services.security.JetspeedSecurityCache;
import org.apache.jetspeed.services.rundata.JetspeedRunDataService;
import org.apache.jetspeed.services.rundata.JetspeedRunData;
import org.apache.turbine.services.rundata.RunDataService;
import org.apache.jetspeed.services.PsmlManager;
import org.apache.jetspeed.om.profile.Profile;
import org.apache.jetspeed.om.profile.BaseProfile;
import org.apache.jetspeed.modules.actions.JLoginUser;
import org.apache.jetspeed.portal.BasePortletConfig;
import org.apache.jetspeed.services.Profiler;

public class PcsAuthentication extends TurbineAuthentication
{

  /**
   * The parent (TurbineAuthentication) login is called.
   * Then if the user is new and hasn't any PSML profile, a default one is
created, and he is granted the "user" role.
   */
	public JetspeedUser login(String username, String password)
        throws LoginException
    {
        System.out.println("PcsAuthentication.login()");
        JetspeedUser user = super.login(username, password);

        //if no PSML exists for this user, create the default PSML
        //get the profile of this user
        Profile aProfile = null;
        try
        {
          aProfile = Profiler.getProfile(super.getRunData());          
        }
        catch(org.apache.jetspeed.om.profile.ProfileException pe)
        {
          System.out.println("Could not get profile for user :
"+user.getUserName());
          System.out.println(pe.toString());
        }

        //if no profile, add default profile
        try{
          if(aProfile == null) addDefaultPSML(user);
        }
        catch(JetspeedSecurityException se)
        {
          System.out.println("Could not create profile for user
"+user.getUserName());
          System.out.println(se.toString());
        }
        
        super.getRunData().getSession().setAttribute("JETSPEED_USER", user);

        return user;
    }

    
    /*
     * A default PSML page is added for the user, and the Jetspeed default
roles
     * are assigned to the new user.
     * 
     * Based on the addDefaultPSML from TurbineUserManagement
     *
     * @param user The new user.
     * @throws JetspeedSecurityException
     */
    protected void addDefaultPSML(JetspeedUser user)
        throws JetspeedSecurityException
    {
        //grant "user" role to the new user
        try
        {
            JetspeedSecurity.grantRole(user.getUserName(), "user");
        }
        catch(Exception e)
        {
            Log.error("Could not grant role user to user " +
user.getUserName(), e);
        }
        
        try
        {
            JetspeedRunData rundata = super.getRunData();
            if (rundata != null)
            {
                Profile profile = new BaseProfile();
                profile.setUser(user);
                profile.setMediaType("html");
                Profiler.createProfile(getRunData(), profile);
            }
        }
        catch (Exception e)
        {
            //removeUser(new UserNamePrincipal(user.getUserName()));
            throw new UserException("Failed to create profile for new user
", e);
        }
        return;
    }
}



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic