Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [lyo-dev] Consumer with auth

Stefan has documented the right way to approach this.   There is an enhancement open to create a convenience class in Lyo, but the method described should work.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=397573

Regards,
Mike


On Tue, Apr 16, 2013 at 2:51 AM, Paschke, Stefan <Stefan.Paschke@xxxxxxx> wrote:
Hi Alessio,

just for clarification you want to develop an OSLC Consumer that uses Basic Authentication against a service provider, right?

I just had a quick look at the source code of org.eclipse.lyo.oslc4j.client.OslcRestClient.
I did not implement it, but I am quite sure it should do the trick.

If you look at the constructor carefully.

public OslcRestClient(final Set<Class<?>> providers,
                              final String        uri,
                              final String        mediaType,
                              final int           readTimeout,
                              final ClientHandler ... handlers)

You will see you can pass a ClientHandler.
If one looks up the Wink Documentation (https://cwiki.apache.org/WINK/62-configuring-the-apache-wink-client.html)
that forms the basis of the OslcRestClient you can find 'org.apache.wink.client.handlers.BasicAuthSecurityHandler'.

Following the example there. You should be able to do something like that.
// Define your authentication mechanism and user credentials
BasicAuthSecurityHandler basicAuthHandler = new BasicAuthSecurityHandler();
 basicAuthHandler.setUserName("foo");
 basicAuthHandler.setPassword("bar");

//Set the other values for the OsclRestClient to your values
private static final String MEDIA_TYPE = OslcMediaType.APPLICATION_RDF_XML;
private final int timeout = 1500;
private final String queryBase = "http://hostname:port/ServiceProviderName/resources";
private final Set<Class<?>> providers = new HashSet<Class<?>>();
providers.addAll(JenaProvidersRegistry.getProviders());
providers.addAll(Json4JProvidersRegistry.getProviders());

//Initialize the OslcRestClient
final OslcRestClient oslcRestClient = new OslcRestClient(providers, queryBase, MEDIA_TYPE, timeout, basicAuthHandler);

Hope that helps. ;-)

Regards,
  Stefan


DI (FH) Stefan Paschke
Researcher/Area Information & Process Management

Kompetenzzentrum - Das Virtuelle Fahrzeug Forschungsgesellschaft mbH (ViF) Inffeldgasse 21/A/EG 8010 Graz AUSTRIA

Telefon:        +43 316 873 9049
Fax:    +43 316 873 9002
stefan.paschke@xxxxxxx
www.v2c2.at


Firmenname: Kompetenzzentrum - Das virtuelle Fahrzeug, Forschungsgesellschaft mbH
Rechtsform: Gesellschaft mit beschränkter Haftung
Firmensitz: A-8010 Graz, Inffeldgasse 21/A
Firmenbuchnummer: 224755y
Firmenbuchgericht: Landesgericht für ZRS Graz




>-----Ursprüngliche Nachricht-----
>Von: lyo-dev-bounces@xxxxxxxxxxx [mailto:lyo-dev-bounces@xxxxxxxxxxx] Im
>Auftrag von Alessio Bucaioni
>Gesendet: Montag, 15. April 2013 09:07
>An: lyo-dev@xxxxxxxxxxx
>Cc: Cristina Seceleanu
>Betreff: [lyo-dev] Consumer with auth
>
>Dear all,
>is there anyone whom knows how to implement a consumer with a
>authentication mechanism, i.e. which do we have to modify?
>
>Thanks in advance.
>
>
>--
>
>Alessio Bucaioni,
>Research Engineering @Mälardalen University (Västerås, SE)
>
>Swedish mobile:  +46725298579
>Italian mobile:  +393497925734
>Email:  alessiounivaq@xxxxxxxxx <mailto:alessiounivaq@xxxxxxxxx>
>Linkedin:  http://www.linkedin.com/pub/alessio-bucaioni/27/5b2/b18
><http://www.linkedin.com/pub/alessio-bucaioni/27/5b2/b18>
>
>Address: via Pier Michele Vizioli 5
>              Camarda, L'Aquila
>              67100, AQ, Italy
>
>

_______________________________________________
lyo-dev mailing list
lyo-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/lyo-dev


Back to the top