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.authentication.CredentialsCallback;
86 // TODO: Auto-generated Javadoc
88 * The Class CASLoginModule.
90 public class CASLoginModule implements LoginModule {
93 protected Subject subject;
95 /** The callback handler. */
96 protected CallbackHandler callbackHandler;
98 /** The cas validate url. */
99 protected String casValidateUrl;
102 protected String service;
104 /** The principal. */
105 protected Principal principal;
108 * @see javax.security.auth.spi.LoginModule#initialize(javax.security.auth.Subject, javax.security.auth.callback.CallbackHandler, java.util.Map, java.util.Map)
110 public void initialize(Subject subject, CallbackHandler callbackHandler,
111 Map sharedState, Map options) {
112 this.subject = subject;
113 this.callbackHandler = callbackHandler;
114 this.casValidateUrl = (String) options.get("cas_validate_url");
115 this.service = (String) options.get("service");
119 * @see javax.security.auth.spi.LoginModule#login()
121 public boolean login() throws LoginException {
125 n = CasAuth.getUserName();
126 } catch (Exception e) {
128 CredentialsCallback ccb = new CredentialsCallback();
129 callbackHandler.handle(new Callback[] { ccb });
130 Credentials creds = ccb.getCredentials();
132 if (creds instanceof SimpleCredentials) {
133 SimpleCredentials sc = (SimpleCredentials) creds;
139 } catch (Exception e1) {
144 principal = new Principal() {
145 public String getName() {
157 * @see javax.security.auth.spi.LoginModule#commit()
159 public boolean commit() throws LoginException {
160 if (principal != null) {
161 subject.getPrincipals().add(principal);
168 * @see javax.security.auth.spi.LoginModule#abort()
170 public boolean abort() throws LoginException {
171 if (principal != null) {
179 * @see javax.security.auth.spi.LoginModule#logout()
181 public boolean logout() throws LoginException {
182 if (principal != null) {
183 subject.getPrincipals().remove(principal);