01: /**
02: * LibreSource
03: * Copyright (C) 2004-2008 Artenum SARL / INRIA
04: * http://www.libresource.org - contact@artenum.com
05: *
06: * This file is part of the LibreSource software,
07: * which can be used and distributed under license conditions.
08: * The license conditions are provided in the LICENSE.TXT file
09: * at the root path of the packaging that enclose this file.
10: * More information can be found at
11: * - http://dev.libresource.org/home/license
12: *
13: * Initial authors :
14: *
15: * Guillaume Bort / INRIA
16: * Francois Charoy / Universite Nancy 2
17: * Julien Forest / Artenum
18: * Claude Godart / Universite Henry Poincare
19: * Florent Jouille / INRIA
20: * Sebastien Jourdain / INRIA / Artenum
21: * Yves Lerumeur / Artenum
22: * Pascal Molli / Universite Henry Poincare
23: * Gerald Oster / INRIA
24: * Mariarosa Penzi / Artenum
25: * Gerard Sookahet / Artenum
26: * Raphael Tani / INRIA
27: *
28: * Contributors :
29: *
30: * Stephane Bagnier / Artenum
31: * Amadou Dia / Artenum-IUP Blois
32: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33: */package org.libresource.kernel.mappers;
34:
35: import org.libresource.Libresource;
36:
37: import org.libresource.kernel.KernelConstants;
38: import org.libresource.kernel.interfaces.KernelService;
39:
40: import org.libresource.membership.MembershipConstants;
41: import org.libresource.membership.interfaces.MembershipService;
42:
43: import java.net.URI;
44:
45: import java.security.Principal;
46:
47: import java.util.Map;
48:
49: /**
50: * LibreSource
51: *
52: * @author <a href="mailto:bort@loria.fr">Guillaume Bort</a> - <a
53: * href="http://www.inria.fr">INRIA Lorraine</a>
54: *
55: * Map all authentified Principals to MembershipService User's
56: */
57: public class MembershipPrincipalMapper implements PrincipalMapper {
58: private KernelService kernelService;
59: private MembershipService membershipService;
60: private Map options;
61: private String usersRoot;
62:
63: public MembershipPrincipalMapper(Map options) throws Exception {
64: this .options = options;
65: kernelService = (KernelService) Libresource
66: .getService(KernelConstants.SERVICE);
67: membershipService = (MembershipService) Libresource
68: .getService(MembershipConstants.SERVICE);
69: usersRoot = membershipService.getUsersRootURI().getPath();
70: }
71:
72: public URI map(Principal principal) throws Exception {
73: URI uri;
74: String userName;
75:
76: if (principal == null) {
77: userName = membershipService.getUnauthentifiedUserId();
78: } else {
79: userName = principal.getName();
80:
81: if (!userName.matches("[A-Za-z0-9_]+")) {
82: throw new Exception(
83: "MembershipPrincipalMapper can't map this username (doesn't match [A-Za-z0-9_]+)");
84: }
85: }
86:
87: uri = new URI(usersRoot + "/" + userName);
88:
89: // TODO check
90: //if (!kernelService.exist(uri)) {
91: // membershipService.systemCreateUser(userName);
92: //}
93: return uri;
94: }
95: }
|