~ubuntu-branches/ubuntu/karmic/lasso/karmic

« back to all changes in this revision

Viewing changes to docs/lasso-book/writing-a-java-sp.txt

  • Committer: Bazaar Package Importer
  • Author(s): Michael Bienia
  • Date: 2007-07-31 21:35:26 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070731213526-oc6jw5mprcd5tjyy
Tags: 2.0.0-1ubuntu1
* Merge from debian unstable. Remaining changes:
  + debian/control:
    - Modify Maintainer value to match DebianMaintainerField spec.
* debian/rules:
  + Add CC=gcc-4.2 to the configure call else configure won't find jni.h
    from libgcj8-dev.
* configure{,.ac}:
  + Add missing quotes around the value for PHP[45]_LIBS.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
==========================================
 
2
Writing a Liberty Service Provider in Java
 
3
==========================================
 
4
 
 
5
:author: Nicolas Clapiès
 
6
:contact: nclapies@entrouvert.com
 
7
:date: $Date: 2006/10/28 15:17:45 $
 
8
:revision: $Revision: 1.2 $
 
9
:copyright: Copyright © 2006 Entr'ouvert
 
10
 
 
11
.. contents:: Table of Contents
 
12
.. section-numbering::
 
13
 
 
14
 
 
15
Lasso Java Binding Settings
 
16
===========================
 
17
 
 
18
Java binding of Lasso is implemented by the Java package lasso.jar. In order to
 
19
compile Java sources importing this package, you need to set environment
 
20
variable CLASSPATH::
 
21
 
 
22
  export CLASSPATH=$CLASSPATH:/path/to/lasso/jar/lasso.jar
 
23
 
 
24
Lasso Java package is linked to C Lasso library thanks to JNI interface
 
25
library. Under UNIXes like Linux, the library is named linjlasso.so. Under Mac
 
26
OS X, library is named libjlasso.dynlib. Windows systems need jlasso.dll. You
 
27
need to add library directory path to system library loader.
 
28
 
 
29
For UNIXes system with bash, command is like::
 
30
 
 
31
  export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/lasso/jni/interface/
 
32
 
 
33
where /path/to/lasso/jni/interface/ is the Lasso JNI interface hosting
 
34
directory.
 
35
 
 
36
 
 
37
Liberty and Lasso profiles
 
38
==========================
 
39
 
 
40
Lasso provides the necessary functions to implement Liberty Alliance profiles,
 
41
as defined in the `Liberty ID-FF Bindings and Profiles Specification`_ :
 
42
 
 
43
- Single Sign-On and Federation
 
44
- Single Logout
 
45
- Federation Termination Notification
 
46
 
 
47
 
 
48
Lasso settings
 
49
==============
 
50
 
 
51
Java applications first need to import Lasso package::
 
52
 
 
53
  import com.entrouvert.lasso.*;
 
54
 
 
55
 
 
56
Service Provider keys and metadata files
 
57
========================================
 
58
 
 
59
Liberty key files
 
60
-----------------
 
61
 
 
62
Service Provider needs private and public keys to sign sent messages. It also
 
63
needs Identity Provider public key to verify received messages. Private and
 
64
public keys are loaded from PEM files by Lasso.
 
65
 
 
66
Liberty Metadata files
 
67
----------------------
 
68
 
 
69
Service Provider need to get Identity Provider metadata to know where to send
 
70
requests and how to process received requests from Identity Provider. Metadata
 
71
are xml document describing provider identifier, deployed urls where to send
 
72
requests and initiate profile and methods describing how to send or process
 
73
requests.
 
74
 
 
75
Service provider typically describe metadata like this::
 
76
 
 
77
  <?xml version="1.0"?>
 
78
  <EntityDescriptor
 
79
    providerID="http://sp.example.com/liberty/metadata" 
 
80
    xmlns="urn:liberty:metadata:2003-08">
 
81
    <SPDescriptor protocolSupportEnumeration="urn:liberty:iff:2003-08">
 
82
        <SoapEndpoint>http://sp.example.com/liberty/soap-endpoint</SoapEndpoint>
 
83
        <SingleLogoutServiceURL>sp.example.com/liberty/single-logout</SingleLogoutServiceURL>
 
84
        <AssertionConsumerServiceURL id="AssertionConsumerService1"isDefault="true">http://sp.example.com/liberty/assertion-consumer-service</AssertionConsumerServiceURL>
 
85
        <FederationTerminationNotificationProtocolProfile>http://projectliberty.org/profiles/fedterm-idp-soap</FederationTerminationNotificationProtocolProfile>
 
86
        <FederationTerminationNotificationProtocolProfile>http://projectliberty.org/profiles/fedterm-idp-http</FederationTerminationNotificationProtocolProfile>
 
87
        <SingleLogoutProtocolProfile>http://projectliberty.org/profiles/slo-idp-soap</SingleLogoutProtocolProfile>
 
88
        <SingleLogoutProtocolProfile>http://projectliberty.org/profiles/slo-idp-http</SingleLogoutProtocolProfile>
 
89
        <SingleLogoutProtocolProfile>http://projectliberty.org/profiles/slo-sp-soap</SingleLogoutProtocolProfile>
 
90
        <AuthnRequestsSigned>true</AuthnRequestsSigned>
 
91
    </SPDescriptor>
 
92
    <Organization>
 
93
        <OrganizationName>Example Organization</OrganizationName>
 
94
    </Organization>
 
95
  </EntityDescriptor>
 
96
 
 
97
Where sp.example.com is the domain name of Service Provider.
 
98
 
 
99
``http://sp.example.com/liberty/metadata`` is the Service Provider Liberty
 
100
identifier.
 
101
 
 
102
``http://sp.example.com/liberty/soap-endpoint`` is the Service Provider SOAP
 
103
endpoint where Identity Provider send SOAP single logout or defederation
 
104
requests.
 
105
 
 
106
``http://sp.example.com/liberty/assertion-consumer-service`` is the Service
 
107
Provider assertion consumer url where Identity Provider must return single sign
 
108
on authentication response.
 
109
 
 
110
``http://sp.example.com/liberty/single-logout`` is the Service Provider single
 
111
logout url. Service Provider can initiate single logout from this url or
 
112
process HTTP single logout request from Identity Provider.  `
 
113
 
 
114
Lasso Server and remote providers settings
 
115
==========================================
 
116
 
 
117
LassoServer
 
118
-----------
 
119
 
 
120
Every time needing to initiate a Liberty Profile or process a Liberty request,
 
121
Lasso needs to set a Lasso Profile object with a Lasso Server to set Service
 
122
Provider informations (private key and metadata) and identity Provider
 
123
informations (public key, certificate and metadata).
 
124
 
 
125
The Server object may be created as follows::
 
126
 
 
127
  Server lassoServer = new Server("sp-metadata.xml",
 
128
                  "sp-privatekey.pem", null, null);
 
129
  lassoServer.addProvider(lasso.PROVIDER_ROLE_IDP,
 
130
                  "idp-metadata.xml", "idp-publickey.pem", null);
 
131
 
 
132
- sp-metadata.xml is the Liberty metadata file of the service provider
 
133
- idp-metadata.xml is the Liberty metadata file for the identity provider
 
134
- sp-privatekey.pem is the service provider private key; used to sign documents
 
135
- idp-publickey.pem is the identity provider public key; used to verify
 
136
  signature in documents sent by the identity provider
 
137
 
 
138
Serialisation
 
139
-------------
 
140
 
 
141
It can be useful to dumps Server object and save it for next use. LassoServer
 
142
objects can be serialised into a XML formatted string::
 
143
 
 
144
  String lassoServerDump = lassoServer->dump();`
 
145
 
 
146
It is then really easy to get back properly constructed objects::
 
147
 
 
148
  Server lassoServer = Server.newFromDump(lassoServerDump);
 
149
 
 
150
 
 
151
Single Sign On
 
152
==============
 
153
 
 
154
Initiating Single Sign On::
 
155
 
 
156
  Login lassoLogin = new Login(lassoServer);
 
157
  lassoLogin.initAuthnRequest(lassoServer.getProviderIds().getItem(0),
 
158
                  lasso.HTTP_METHOD_REDIRECT);
 
159
  LibAuthnRequest authnRequest = (LibAuthnRequest) login.getRequest();
 
160
  authnRequest.setNameIdPolicy(lasso.LIB_NAMEID_POLICY_TYPE_FEDERATED);
 
161
  authnRequest.setProtocolProfile(lasso.LIB_PROTOCOL_PROFILE_BRWS_ARTIFACT);
 
162
  lassoLogin.buildAuthnRequestMsg();
 
163
  String msgUrl = lassoLogin.getMsgUrl();
 
164
 
 
165
Processing Single Sign On Identity Provider Artifact response from
 
166
AssertionConsumerServiceURL metadata URL::
 
167
 
 
168
  lassoLogin.initRequest(queryString, lasso.HTTP_METHOD_REDIRECT);
 
169
  lassoLogin.buildRequestMsg();
 
170
  String soapEndpoint = lassoLogin.getMsgUrl();
 
171
  String soapRequestMsg = lassoLogin.getMsgBody();
 
172
  // If a lassoSessionDump or a lassoIdentityDump was saved, restore them.
 
173
  lassoLogin.setSessionFromDump(lassoSessionDump);
 
174
  lassoLogin.setIdentityFromDump(lassoIdentityDump);
 
175
  try {
 
176
    lassoLogin.acceptSso();
 
177
  } catch (RuntimeException e) {
 
178
  }
 
179
  String lassoSessionDump = lassoLogin.getSession().dump();
 
180
  String lassoIdentityDump = lassoLogin.getIdentity().dump();
 
181
  String nameIdentifier = lassoLogin.getNameIdentifier().getContent();
 
182
 
 
183
 
 
184
Single Logout
 
185
=============
 
186
 
 
187
Initiate SOAP Single Logout from Service Provider
 
188
-------------------------------------------------------
 
189
 
 
190
Initiating single logout from SingleLogoutServiceURL metadata url::
 
191
 
 
192
  Logout lassoLogout = new Logout(sp.server);
 
193
  lassoLogout.setSessionFromDump(lassoSessionDump);
 
194
  lassoLogout.setIdentityFromDump(lassoIdentityDump);
 
195
  lassoLogout.initRequest(sp.server.getProviderIds().getItem(0),
 
196
                lasso.HTTP_METHOD_SOAP);
 
197
  lassoLogout.buildRequestMsg();
 
198
  String soapEndpoint = lassoLogout.getMsgUrl();
 
199
  String soapRequestMsg = lassoLogout.getMsgBody();
 
200
  // Send SOAP request and get SOAP response ...
 
201
  try {
 
202
    lassoLogout.processResponseMsg(soapResponseMsg);
 
203
  } catch (RuntimeException e) {
 
204
    // an error occured
 
205
    return;
 
206
  }
 
207
  // Everything is ok, remove lasso session dump from application storage
 
208
 
 
209
Process Single Logout HTTP request from Identity Provider
 
210
-------------------------------------------------------------
 
211
 
 
212
Process single logout from SoapEndpoint metadata url::
 
213
 
 
214
  Logout lassoLogout = new Logout(lassoServer);
 
215
  lassoLogout.processRequestMsg(logoutRequestMsg);
 
216
  lassoLogout.setIdentityFromDump(lassoIdentityDump);
 
217
  lassoLogout.setSessionFromDump(lassoSessionDump);
 
218
  try {
 
219
     lassoLogout.validateRequest();
 
220
  } catch (RuntimeException e) {    
 
221
  }
 
222
  lassoLogout.buildResponseMsg();
 
223
  String soapResponseMsg = lassoLogout.getMsgBody();
 
224
 
 
225
 
 
226
Defederation
 
227
============
 
228
 
 
229
Processing SOAP defederation from SoapEndpoint metadata url::
 
230
 
 
231
  if (lasso.getRequestTypeFromSoapMsg(soapRequestMsg) == lasso.REQUEST_TYPE_DEFEDERATION) {
 
232
    Defederation lassoDefederation = new Defederation(lassoServer);
 
233
    lassoDefederation.processNotificationMsg(soapRequestMsg);
 
234
    lassoDefederation.setIdentityFromDump(lassoIdentityDump);
 
235
    try {
 
236
        lassoDefederation.validateNotification();
 
237
    } catch () {
 
238
      // an error occured
 
239
    }
 
240
    // return 204 HTTP status code
 
241
  }
 
242
 
 
243
Database Considerations
 
244
=======================
 
245
 
 
246
Lasso has been designed to let the service provider keep on using existing
 
247
databases.  Typically there is already a table describing users; just add an
 
248
identity dump column to the existing table:
 
249
 
 
250
=======    ========================================    ==============
 
251
User Id    existing data (name, address...)            Identity dump
 
252
=======    ========================================    ==============
 
253
1          ...                                         <Identity> ...
 
254
2          ...                                         <Identity> ...
 
255
=======    ========================================    ==============
 
256
 
 
257
Mapping between existing users and name identifiers sent by the identity
 
258
provider can be done with a simple table.
 
259
 
 
260
===============    =======
 
261
Name Identifier    User Id
 
262
===============    =======
 
263
AQWWRRS...         1
 
264
CGFASDE...         2
 
265
YYSSSDS...         1
 
266
===============    =======
 
267
 
 
268
.. note:: A separate table is needed because one user Id could map
 
269
          to several name identifiers; in case there are several identity
 
270
          providers.
 
271
 
 
272
Sessions are also commonly stored in databases; just add a session dump column
 
273
to the existing session table:
 
274
 
 
275
==========    =================    =============
 
276
Session Id    misc session data    Session dump
 
277
==========    =================    =============
 
278
6744066       ...                  <Session> ...
 
279
3338824       ...                  <Session> ...
 
280
==========    =================    =============
 
281
 
 
282
Likewise sessions should be mapped to name identifiers.
 
283
 
 
284
===============    ==========
 
285
Name Identifier    Session Id
 
286
===============    ==========
 
287
AQWWRRS...         3338824
 
288
===============    ==========
 
289
 
 
290
 
 
291
API Reference
 
292
=============
 
293
 
 
294
- LassoLogin_
 
295
- LassoLogout_
 
296
- LassoIdentity_
 
297
- LassoServer_
 
298
- LassoSession_
 
299
 
 
300
 
 
301
 
 
302
 
 
303
.. _Liberty ID-FF Bindings and Profiles Specification:
 
304
   http://www.projectliberty.org/specs/draft-liberty-idff-bindings-profiles-1.2-errata-v1.0.pdf
 
305
 
 
306
.. _LassoLogin: /documentation/api-reference/lassologin.html
 
307
.. _LassoLogout: /documentation/api-reference/lassologout.html
 
308
.. _LassoIdentity: /documentation/api-reference/lassoidentity.html
 
309
.. _LassoServer: /documentation/api-reference/lassoserver.html
 
310
.. _LassoSession: /documentation/api-reference/lassosession.html