⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 anonymousloginmodule.java

📁 jspwiki source code,jspwiki source code
💻 JAVA
字号:
/*    JSPWiki - a JSP-based WikiWiki clone.    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 com.ecyrd.jspwiki.auth.login;import java.io.IOException;import javax.security.auth.callback.Callback;import javax.security.auth.callback.UnsupportedCallbackException;import javax.security.auth.login.LoginException;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpSession;import org.apache.log4j.Logger;import com.ecyrd.jspwiki.auth.WikiPrincipal;/** * <p> * Logs in a user based solely on IP address; no other authentication is * performed. Barring a mis-configuration or I/O error, this LoginModule * <em>always</em> succeeds. * </p> * This module must be used with a CallbackHandler (such as * {@link WebContainerCallbackHandler}) that supports the following Callback * types: * </p> * <ol> * <li>{@link HttpRequestCallback}- supplies the IP address, which is used as * a backup in case no name is supplied.</li> * </ol> * <p> * After authentication, a generic WikiPrincipal based on the IP address will be * created and associated with the Subject. * @see javax.security.auth.spi.LoginModule#commit() *      </p> * @author Andrew Jaquith * @since 2.3 */public class AnonymousLoginModule extends AbstractLoginModule{    /**     * Bogus prompt sent to the callback handler.     */    public static final String PROMPT            = "User name";    protected static final Logger log            = Logger.getLogger( AnonymousLoginModule.class );    /**     * Logs in the user by calling back to the registered CallbackHandler with an     * HttpRequestCallback. The CallbackHandler must supply the current servlet     * HTTP request as its response.     * @return the result of the login; this will always be <code>true</code>.     * @see javax.security.auth.spi.LoginModule#login()     * @throws {@inheritDoc}     */    public boolean login() throws LoginException    {        // Let's go and make a Principal based on the IP address        HttpRequestCallback hcb = new HttpRequestCallback();        Callback[] callbacks = new Callback[]        { hcb };        try        {            m_handler.handle( callbacks );            HttpServletRequest request = hcb.getRequest();            WikiPrincipal ipAddr = new WikiPrincipal( request.getRemoteAddr() );            if ( log.isDebugEnabled() )            {                HttpSession session = request.getSession( false );                String sid = (session == null) ? NULL : session.getId();                log.debug("Logged in session ID=" + sid + "; IP=" + ipAddr);            }            // If login succeeds, commit these principals/roles            m_principals.add( ipAddr );            return true;        }        catch( IOException e )        {            log.error("IOException: " + e.getMessage());            return false;        }        catch( UnsupportedCallbackException e )        {            String message = "Unable to handle callback, disallowing login.";            log.error( message, e );            throw new LoginException( message );        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -