Project

General

Profile

Session with multiple contexts

Added by Hajnal Akos almost 12 years ago

Dear Developers,

In my use-case a user may use more contexts to access more resources in one session, and sometimes the user wants to change his/her previous context used to access a specific resource. I noticed that jSaga session is sensitive for the addition of more than one contexts, if more contexts added, "nothing" is returned:

import org.ogf.saga.context.*;
import org.ogf.saga.namespace.*;
import org.ogf.saga.session.*;
import org.ogf.saga.url.*;

public class SessionSshMultiContext {

    public static void main(String[] args) throws Exception {
        URL url = URLFactory.createURL( "sftp://192.168.153.100/tmp/");
        Session session = SessionFactory.createSession(false);

        Context ctx = ContextFactory.createContext("UserPass"); 
        ctx.setAttribute(Context.USERID, "user");
        ctx.setAttribute(Context.USERPASS, "pass");
        ctx.setVectorAttribute("DataServiceAttributes", new String[]{"sftp.KnownHosts="});
        session.addContext(ctx);

        ctx = ContextFactory.createContext("SSH");
        ctx.setAttribute(Context.USERID, "user");
        ctx.setAttribute(Context.USERKEY, "id_rsa");
        ctx.setAttribute(Context.USERPASS, "");
        ctx.setVectorAttribute("DataServiceAttributes", new String[]{"sftp.KnownHosts="});
        session.addContext(ctx);

        NSDirectory dir = NSFactory.createNSDirectory(session, url);
        dir.close();
    }
}

Exception in thread "main" AuthenticationFailed: Security context class 'fr.in2p3.jsaga.adaptor.security.NoneSecurityCredential' not supported for protocol: sftp
    at fr.in2p3.jsaga.engine.factories.ServiceAdaptorFactory.getCredential(ServiceAdaptorFactory.java:75)

Two contexts in some cases live happily together without conflict, e.g. SSH context and Globus context can be added, and sftp and gsiftp can be accessed without a problem. (SessionImpl.getBestMatchingContext() is not called which returns "None" context if m_contexts.size() > 1.)

My problem is that the Session interface does not really support the query whether I have already registered some context to access some resource of a specific protocol.

I know that I can specify contexts for specific hosts by adding ctx.setVectorAttribute("BaseUrlIncludes", new String[]{"sftp://192.168.153.100"});, but that still does not resolve the problem of accessing the same resource with multiple contexts (one at a time).

Maybe I use contexts in a wrong way (and maybe I should remove some previous contexts before adding a new one) - I still miss here something that warns me about possible conflicts. Any idea how to administer contexts in a proper way?

Sorry for the long and messy question...

Regards,
Akos Hajnal


Replies (3)

RE: Session with multiple contexts - Added by Hajnal Akos almost 12 years ago

Sorry, I made a mistake, SSH and Globus contexts do not live happily together either.

RE: Session with multiple contexts - Added by Schwarz Lionel almost 12 years ago

Hi Akos,
if "BaseUrlIncludes" does not the job for you because you want to access the same resource with 2 differents contexts, then you can use the JSAGA-specific "URL Prefix" mechanism. Just add an atrribute named "UrlPrefix" with the value you want, for example:

        Context ctx = ContextFactory.createContext("UserPass"); 
        ctx.setAttribute(Context.USERID, "user");
        ctx.setAttribute(Context.USERPASS, "pass");
        ctx.setVectorAttribute("DataServiceAttributes", new String[]{"sftp.KnownHosts="});
        ctx.setAttribute("UrlPrefix","userpass");
        session.addContext(ctx);

        ctx = ContextFactory.createContext("SSH");
        ctx.setAttribute(Context.USERID, "user");
        ctx.setAttribute(Context.USERKEY, "id_rsa");
        ctx.setAttribute(Context.USERPASS, "");
        ctx.setVectorAttribute("DataServiceAttributes", new String[]{"sftp.KnownHosts="});
        ctx.setAttribute("UrlPrefix","sshkey");
        session.addContext(ctx);

and then refer to either:

userpass-sftp://192.168.153.100/tmp/

or
sshkey-sftp://192.168.153.100/tmp/

whether you want to access this machine with your password or with your key.
UrlPrefix is used internally in JSAGA to build a kind of pseudo-protocol (UrlPrefix + "-" + scheme) that represent in fact the link between a URL and a security context.

Contact me directly by email or IM if you need more details.
Lionel

RE: Session with multiple contexts - Added by Hajnal Akos almost 12 years ago

Dear Lionel,

Thanks for your help. Now I always attach contexts to "protocol://host" using BaseUrlIncludes before adding them to the session, and this solution works perfectly in my use case.

Each time the user wants to register a new context, I always check and clear previous one (if exists) from the session:

Context prevContext = ((SessionImpl)session).findContext(protocol + "://" + host);
if (prevContext != null) session.removeContext(prev);
session.addContext(newContext);

(I don't want to access the same resource with different contexts at a time, but thanks for the idea using UrlPrefix...)

Thanks,
Akos

    (1-3/3)