smtpauthenticator.java

来自「jGossip是一个简单而功能强大的Java论坛软件(消息板)」· Java 代码 · 共 97 行

JAVA
97
字号
/*
 * $Id: SmtpAuthenticator.java,v 1.3 2004/05/30 20:03:58 bel70 Exp $
 *
 * ***** BEGIN LICENSE BLOCK *****
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (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.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 * the License for the specific language governing rights and
 * limitations under the License.
 *
 * The Original Code is JGossip forum code.
 *
 * The Initial Developer of the Original Code is the JResearch, Org.
 * Portions created by the Initial Developer are Copyright (C) 2004
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *              Dmitriy Belov <bel@jresearch.org>
 *               .
 * * ***** END LICENSE BLOCK ***** */
/*
 * Created on 25.04.2004
 *
 */
package org.jresearch.gossip.mail;

import org.jresearch.gossip.IConst;
import org.jresearch.gossip.configuration.Configurator;
import org.jresearch.gossip.exception.ConfiguratorException;
import org.jresearch.gossip.util.DesEncrypter;

import java.io.IOException;

import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;

import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;


/**
 * DOCUMENT ME!
 *
 * @author Dmitry Belov
 */
public class SmtpAuthenticator extends Authenticator {
    private static Configurator config = Configurator.getInstance();
    private String mailuser;
    private String mailpassword;

    /**
     * Creates a new SmtpAuthenticator object.
     *
     * @throws InvalidKeyException DOCUMENT ME!
     * @throws InvalidKeySpecException DOCUMENT ME!
     * @throws NoSuchAlgorithmException DOCUMENT ME!
     * @throws NoSuchPaddingException DOCUMENT ME!
     * @throws InvalidAlgorithmParameterException DOCUMENT ME!
     * @throws IllegalStateException DOCUMENT ME!
     * @throws IllegalBlockSizeException DOCUMENT ME!
     * @throws BadPaddingException DOCUMENT ME!
     * @throws IOException DOCUMENT ME!
     * @throws ConfiguratorException DOCUMENT ME!
     */
    public SmtpAuthenticator()
        throws InvalidKeyException, InvalidKeySpecException, 
            NoSuchAlgorithmException, NoSuchPaddingException, 
            InvalidAlgorithmParameterException, IllegalStateException, 
            IllegalBlockSizeException, BadPaddingException, IOException, 
            ConfiguratorException {
        super();

        DesEncrypter encrypter = new DesEncrypter(IConst.VALUES.ENCRYPTER_KEY);
        mailuser = config.get(IConst.CONFIG.MAILUSER);
        mailpassword = encrypter.decrypt(config.get(IConst.CONFIG.MAILPASSWORD));
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication(mailuser, mailpassword);
    }
}

⌨️ 快捷键说明

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