1 /*****************************************************************************
2 * Copyright Igor Barma, Eric Brun, Alexandre Desoubeaux, Christian Martel,
5 * Ce logiciel est un programme informatique servant à l'évaluation des
8 * Ce logiciel est régi par la licence CeCILL soumise au droit français et
9 * respectant les principes de diffusion des logiciels libres. Vous pouvez
10 * utiliser, modifier et/ou redistribuer ce programme sous les conditions
11 * de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
12 * sur le site "http://www.cecill.info".
14 * En contrepartie de l'accessibilité au code source et des droits de copie,
15 * de modification et de redistribution accordés par cette licence, il n'est
16 * offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons,
17 * seule une responsabilité restreinte pèse sur l'auteur du programme, le
18 * titulaire des droits patrimoniaux et les concédants successifs.
20 * A cet égard l'attention de l'utilisateur est attirée sur les risques
21 * associés au chargement, à l'utilisation, à la modification et/ou au
22 * développement et à la reproduction du logiciel par l'utilisateur étant
23 * donné sa spécificité de logiciel libre, qui peut le rendre complexe à
24 * manipuler et qui le réserve donc à des développeurs et des professionnels
25 * avertis possédant des connaissances informatiques approfondies. Les
26 * utilisateurs sont donc invités à charger et tester l'adéquation du
27 * logiciel à leurs besoins dans des conditions permettant d'assurer la
28 * sécurité de leurs systèmes et ou de leurs données et, plus généralement,
29 * à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.
31 * Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
32 * pris connaissance de la licence CeCILL, et que vous en avez accepté les
34 *******************************************************************************/
35 package com.pentila.jackrabbit.auth;
40 * Copyright (c) 2000-2003 Yale University. All rights reserved.
42 * THIS SOFTWARE IS PROVIDED "AS IS," AND ANY EXPRESS OR IMPLIED
43 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
44 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE EXPRESSLY
45 * DISCLAIMED. IN NO EVENT SHALL YALE UNIVERSITY OR ITS EMPLOYEES BE
46 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
47 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED, THE COSTS OF
48 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA OR
49 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
50 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
51 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
52 * SOFTWARE, EVEN IF ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH
55 * Redistribution and use of this software in source or binary forms,
56 * with or without modification, are permitted, provided that the
57 * following conditions are met:
59 * 1. Any redistribution must include the above copyright notice and
60 * disclaimer and this list of conditions in any related documentation
61 * and, if feasible, in the redistributed software.
63 * 2. Any redistribution must include the acknowledgment, "This product
64 * includes software developed by Yale University," in any related
65 * documentation and, if feasible, in the redistributed software.
67 * 3. The names "Yale" and "Yale University" must not be used to endorse
68 * or promote products derived from this software.
71 import java.security.Principal;
74 import javax.jcr.Credentials;
75 import javax.jcr.SimpleCredentials;
76 import javax.security.auth.Subject;
77 import javax.security.auth.callback.Callback;
78 import javax.security.auth.callback.CallbackHandler;
79 import javax.security.auth.login.LoginException;
80 import javax.security.auth.spi.LoginModule;
82 import org.apache.jackrabbit.core.security.CredentialsCallback;
84 // TODO: Auto-generated Javadoc
86 * The Class CASLoginModule.
88 public class CASLoginModule implements LoginModule {
91 protected Subject subject;
93 /** The callback handler. */
94 protected CallbackHandler callbackHandler;
96 /** The cas validate url. */
97 protected String casValidateUrl;
100 protected String service;
102 /** The principal. */
103 protected Principal principal;
106 * @see javax.security.auth.spi.LoginModule#initialize(javax.security.auth.Subject, javax.security.auth.callback.CallbackHandler, java.util.Map, java.util.Map)
108 public void initialize(Subject subject, CallbackHandler callbackHandler,
109 Map sharedState, Map options) {
110 this.subject = subject;
111 this.callbackHandler = callbackHandler;
112 this.casValidateUrl = (String) options.get("cas_validate_url");
113 this.service = (String) options.get("service");
117 * @see javax.security.auth.spi.LoginModule#login()
119 public boolean login() throws LoginException {
123 n = new CasAuth().getUserName();
124 } catch (Exception e) {
126 CredentialsCallback ccb = new CredentialsCallback();
127 callbackHandler.handle(new Callback[] { ccb });
128 Credentials creds = ccb.getCredentials();
130 if (creds instanceof SimpleCredentials) {
131 SimpleCredentials sc = (SimpleCredentials) creds;
137 } catch (Exception e1) {
142 principal = new Principal() {
143 public String getName() {
155 * @see javax.security.auth.spi.LoginModule#commit()
157 public boolean commit() throws LoginException {
158 if (principal != null) {
159 subject.getPrincipals().add(principal);
166 * @see javax.security.auth.spi.LoginModule#abort()
168 public boolean abort() throws LoginException {
169 if (principal != null) {
177 * @see javax.security.auth.spi.LoginModule#logout()
179 public boolean logout() throws LoginException {
180 if (principal != null) {
181 subject.getPrincipals().remove(principal);