|
Tomcat example source code file (JAASMemoryLoginModule.java)
The Tomcat JAASMemoryLoginModule.java source code
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.catalina.realm;
import java.io.File;
import java.io.IOException;
import java.security.Principal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import javax.security.auth.Subject;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.callback.UnsupportedCallbackException;
import javax.security.auth.login.FailedLoginException;
import javax.security.auth.login.LoginException;
import javax.security.auth.spi.LoginModule;
import org.apache.catalina.Context;
import org.apache.catalina.Realm;
import org.apache.catalina.connector.Request;
import org.apache.catalina.deploy.SecurityConstraint;
import org.apache.catalina.util.RequestUtil;
import org.apache.catalina.util.StringManager;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.util.digester.Digester;
/**
* <p>Implementation of the JAAS LoginModule interface,
* primarily for use in testing <code>JAASRealm. It utilizes an
* XML-format data file of username/password/role information identical to
* that supported by <code>org.apache.catalina.realm.MemoryRealm
* (except that digested passwords are not supported).</p>
*
* <p>This class recognizes the following string-valued options, which are
* specified in the configuration file (and passed to our constructor in
* the <code>options argument:
* <ul>
* <li>debug - Set to "true" to get debugging messages
* generated to System.out. The default value is <code>false.
* <li>pathname - Relative (to the pathname specified by the
* "catalina.base" system property) or absolute pahtname to the
* XML file containing our user information, in the format supported by
* {@link MemoryRealm}. The default value matches the MemoryRealm
* default.</li>
* </ul>
*
* <p>IMPLEMENTATION NOTE - This class implements
* <code>Realm only to satisfy the calling requirements of the
* <code>GenericPrincipal constructor. It does not actually perform
* the functionality required of a <code>Realm implementation.
*
* @author Craig R. McClanahan
* @version $Revision: 543691 $ $Date: 2007-06-02 03:37:08 +0200 (sam., 02 juin 2007) $
*/
public class JAASMemoryLoginModule extends MemoryRealm implements LoginModule, Realm {
// We need to extend MemoryRealm to avoid class cast
private static Log log = LogFactory.getLog(JAASMemoryLoginModule.class);
// ----------------------------------------------------- Instance Variables
/**
* The callback handler responsible for answering our requests.
*/
protected CallbackHandler callbackHandler = null;
/**
* Has our own <code>commit() returned successfully?
*/
protected boolean committed = false;
/**
* The configuration information for this <code>LoginModule.
*/
protected Map options = null;
/**
* The absolute or relative pathname to the XML configuration file.
*/
protected String pathname = "conf/tomcat-users.xml";
/**
* The <code>Principal identified by our validation, or
* <code>null if validation falied.
*/
protected Principal principal = null;
/**
* The set of <code>Principals loaded from our configuration file.
*/
protected HashMap principals = new HashMap();
/**
* The string manager for this package.
*/
protected static StringManager sm =
StringManager.getManager(Constants.Package);
/**
* The state information that is shared with other configured
* <code>LoginModule instances.
*/
protected Map sharedState = null;
/**
* The subject for which we are performing authentication.
*/
protected Subject subject = null;
// --------------------------------------------------------- Public Methods
public JAASMemoryLoginModule() {
log.debug("MEMORY LOGIN MODULE");
}
/**
* Phase 2 of authenticating a <code>Subject when Phase 1
* fails. This method is called if the <code>LoginContext
* failed somewhere in the overall authentication chain.
*
* @return <code>true if this method succeeded, or
* <code>false if this
Other Tomcat examples (source code examples)Here is a short list of links related to this Tomcat JAASMemoryLoginModule.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.