java+mail+authen_JavaMail - 身份验证( Authentication)

JavaMail - 身份验证( Authentication)

在前面的“ 检查电子邮件和获取电子邮件”章节中,我们在连接到您的邮箱存储时传递了授权凭据(用户广告密码)和主机。 相反,我们可以将Properties配置为拥有主机,并告诉Session您的自定义Authenticator实例。 这显示在下面的示例中:

创建Java类 (Create Java Class)

我们将从“ 检查电子邮件 ”一章修改我们的CheckingMails.java。 其内容如下:package com.iowiki;

import java.util.Properties;

import javax.mail.Authenticator;

import javax.mail.Folder;

import javax.mail.Message;

import javax.mail.MessagingException;

import javax.mail.NoSuchProviderException;

import javax.mail.PasswordAuthentication;

import javax.mail.Session;

import javax.mail.Store;

public class CheckingMails {

public static void check(String host, String storeType, String user,

String password)

{

try {

// create properties field

Properties properties = new Properties();

properties.put("mail.pop3s.host", host);

properties.put("mail.pop3s.port", "995");

properties.put("mail.pop3s.starttls.enable", "true");

// Setup authentication, get session

Session emailSession = Session.getInstance(properties,

new javax.mail.Authenticator() {

protected PasswordAuthentication getPasswordAuthentication() {

return new PasswordAuthentication(

"manisha@gmail.com", "manisha123");

}

});

// emailSession.setDebug(true);

// create the POP3 store object and connect with the pop server

Store store = emailSession.getStore("pop3s");

store.connect();

// create the folder object and open it

Folder emailFolder = store.getFolder("INBOX");

emailFolder.open(Folder.READ_ONLY);

// retrieve the messages from the folder in an array and print it

Message[] messages = emailFolder.getMessages();

System.out.println("messages.length---" + messages.length);

for (int i = 0, n = messages.length; i < n; i++) {

Message message = messages[i];

System.out.println("---------------------------------");

System.out.println("Email Number " + (i + 1));

System.out.println("Subject: " + message.getSubject());

System.out.println("From: " + message.getFrom()[0]);

System.out.println("Text: " + message.getContent().toString());

}

// close the store and folder objects

emailFolder.close(false);

store.close();

} catch (NoSuchProviderException e) {

e.printStackTrace();

} catch (MessagingException e) {

e.printStackTrace();

} catch (Exception e) {

e.printStackTrace();

}

}

public static void main(String[] args) {

String host = "pop.gmail.com";// change accordingly

String mailStoreType = "pop3";

String username = "abc@gmail.com";// change accordingly

String password = "*****";// change accordingly

check(host, mailStoreType, username, password);

}

}您可以通过取消注释语句emailSession.setDebug(true);来设置调试emailSession.setDebug(true);

编译和运行 (Compile and Run)

现在我们的课已经准备好了,让我们编译上面的类。 我已将类CheckingMails.java保存到目录: /home/manisha/JavaMailAPIExercise 。 我们需要在类路径中使用jars javax.mail.jar和activation.jar 。 执行以下命令从命令提示符编译类(两个jar放在/ home/manisha /目录中):javac -cp /home/manisha/activation.jar:/home/manisha/javax.mail.jar: CheckingMails.java

现在编译了类,执行以下命令来运行:java -cp /home/manisha/activation.jar:/home/manisha/javax.mail.jar: CheckingMails

验证输出 (Verify Output)

您可以在命令控制台上看到类似的消息:messages.length---3

---------------------------------

Email Number 1

Subject: Today is a nice day

From: XYZ

Text: javax.mail.internet.MimeMultipart@45f676cb

---------------------------------

Email Number 2

Subject: hiiii....

From: XYZ

Text: javax.mail.internet.MimeMultipart@37f12d4f

---------------------------------

Email Number 3

Subject: helloo

From: XYZ

Text: javax.mail.internet.MimeMultipart@3ad5ba3a

JavaMail - 获取电子邮件( Fetching Emails)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
iPod+Authentication+Coprocessor+Spec+2.0C+R1Contents Chapter 1 Introduction 7 Overview 7 Authentication protocol 7 Terminology Used in This Document 8 General Specification Terms 9 s Related documents 9 Chapter 2 Signal Descriptions and Reference Circuit 11 CP Signals and Pinouts 11 Address selection 12 Reference circuit 12 Chapter 3 Hardware Configuration and Interface 13 System Voltage/ 13 Startup of the 12C Interface/13 Starting Up the cp by turning power on /13 Starting Up the Cp by Warm Reset 14 Communication Process15/ Low-Power Sleep Mode-16 Chapter 4 Coprocessor Registers 17 Register Addresses 17 Register Descriptions 19 Device version 19 Firmware version 19 Authentication Protocol Major and Minor Versions 20 Device iD 20 Error Code 20 Authentication Control and status 21 Signature Data Length 22 Signature Data 22 hallenge Data Length 23 Challenge data 23 Accessory Certificate Data Length 23 Accessory Certificate Data 23 Self- Test Control and status 23 System Event Counter 24 Apple Device Certificate Data Lengt 3 2011-06-22 I @2011 Apple Inc. All Rights Reserved. CONTENTS Apple device certificate data 25 Chapter 5 Authentication Data flows 27 Apple Device Authentication of Accessory 27 Accessory Authentication of the Apple Device 28 Chapter 6 12C Communication Protocol 31 Slave selection and reset 31 s Coprocessor Busy. 31 Writing to the Coprocessor 31 Reading from the Coprocessor 32 Chapter 7 CP Device Characteristics 33 Physical Configuration 33 Maximum Environmental Conditions 33 Recommended Operating Conditions 34 12C Interface Characteristics 34 DC Electrical Characteristics 34 Timing Characteristics 35 ppendix a Coprocessor 2.0B to 2.0C Migration Guide 37(Ay Only 12C Communication Protocol 37 Increased SCL Speed 37 Shorter Reset Cycle 37 Warm Reset Supported 37 Automatic Sleep State Entry and Exit 38 NACK Responses Replace Clock Stretching 38 Shorter Accessory Certificate Data 38 System Event Counter Must Be Zero Betore Power-Down 38 Document Revision History 39 2011-06-22 I @2011 Apple Inc. All Rights Reserved. igures and Tables Chapter 1 Introduction 7 Table 1 Document-specific terminology 8 Chapter 2 Signal Descriptions and Reference Circuit 11 Fi ure 2-1 CP chip pinouts, top view 11 Figure 2-2 Reference circuit for CP 12 Table 2-1 CP signals 11 Table 2-2 Address se n signals 12 Chapter 3 Hardware Configuration and Interface 13 Figure 3-1 P2C interface startup timing 1 Figure 3-2 1C interface warm reset timing 15 Fi gure 3-3 12C slave write address 15 Figure 3-4 12C slave read address 15 Chapter 4 Coprocessor Registers 17 Figure 4-1 Authentication Control and Status register, read-only bits 21 igure 4-2 Fi Authentication Control and Status register, write-only bits 21 Figure 4-3 Self-test Control and Status register, write-only bits 23 Figure 4-4 Self-test Control and Status register, read-only bits/24 Table 4-1 iPod Authentication Coprocessor 2.0C register map 17 Table 4-2 Error codes 20 Table 4-3 Authentication ERR SET values 21 Table 4-4 Authentication PROC RESULTS values 21 Table 4-5 Authentication Proc control values 22 Table 4-6 Self-test proc control values 24 Table 4-7 Self-test result bits 24 Chapter 5 Authentication Data flows 27 Table 5-1 Sequence of interactions by which an Apple device authenticates an accessory 27 Table 5-2 Sequence of interactions by which an accessory authenticates an Apple device 28 5 2011-06-22 I @2011 Apple Inc. All Rights Reserved. FIGURES AND TABLES Chapter 7 CP Device Characteristics 33 Figure 7-1 Authentication coprocessor 2. 0C package 33 Figure 7-2 Typical 1/0 port input waveform 35 Table 7 Maximum electrical and temperature ranges 34 Table 7-2 Recommended operating conditions 34 Table 7-3 I2C interface ranges 34 Table 7-4 Supply current into VcC, excluding external current 35 Table 7 Inputs 35> Table 7-6 Outputs 35 Table 7-7 Values for Figure 7-236 2011-06-22 I @2011 Apple Inc. All Rights Reserved. CHAPTER 1 Introduction N IOTICE OF PROPRIE TARY PROPERTY THE INFORMATION CONTAINED HEREIN IS THE PROPRIETARY PROPERTY OF APPLE INC. THE POSSESSOR AGREES TO THE FOLLOWING: (DTO MAINTAIN THIS DOCUMENT IN CONFIDENCE (ID NOT TO REPRODUCE OR COPY IT, (IID NOT TO REVEAL OR PUBLISH IT IN WHOLE OR IN PART, (IV) ALL RIGHTS RESERVED ACCESS TO THIS DOCUMENT AND THE INFORMATION CONTAINED THEREIN IS GOVERNED BY THE TERMS OF THE MFI LICENSE AGREEMENT AND/OR THE IPOD-IPHONE AIS EVALUATION AGREEMENT. ALL OTHER USE SHALL BE AT APPLES SOLE DISCRETION Note: This document uses the term"Apple device"to refer generically to iPods, iPhones, and iPads, all of which support the iPod Accessory Protocol (iAP) interface. Among these products, those that also run iOS (Apples mobile operating system)are referred to as"ioS devices. "Specifications in this document that are designated for ioS devices apply only to those products Specifications designated for iPods apply only to Apple devices that are not ios devices. Overview device by issuing an authentication challenge to the accessory the accessory must respond to the apol o An Apple device verifies whether a third-party accessory attached to it is authorized for use with the apple device's challenge, and it can do so only with the assistance of an iPod Authentication Coprocessor( CP) chip located in the accessory. Conversely, the accessory can use its CP chip to authenticate the iPod. Certain control and reporting functions of the apple device are made available externally only after it has authenticated an attached accessory as being authorized Earlier versions of the ipod authentication Coprocessor(1.0, 2.0A, and 2.0B)were implemented in QFN-40 QFN-20, and sop-8 packages. The current version, 2.0C, is supplied in a smaller and more efficient PG-USON-8-1 ackage. This document describes the configuration, usage, and specifications of Apple's iPod Authentication Coprocessor 2.00 Authentication Protocol The authentication protocol supported by the iPod Authentication Coprocessor 2.0C is based on standard X509 version 3 certification. Each certificate is generated and signed by a recognized certificate authority and has a unique serial number. Information about the X509 standard can be found at the letf website http://tools.ietf.org/html/3280 For information about the iAP General lingo commands required to perform authentication using the ipod Authentication Coprocessor 2.0C, see apple's MFi Accessory Firmware Specification Overview 2011-06-22 I @2011 Apple Inc. All Rights Reserved. CHAPTER 1 Introduction The iPod Authentication Coprocessor 2.0C supports iAP General lingo commands Ox14 through Ox1E providing five authentication-related services: For Apple device authentication of the accessory: Certificate delivery: To initiate authenticatication of the accessory that contains it, the Cp supplies an X 509 digital certificate for public key verification by the attached apple device Signature generation: To complete authentication of the accessory that contains it, the Cp generates valid digital signature in response to a challenge from an attached Apple device This signature authorizes the apple device to respond to messages and commands from the accessory For accessory authentication of the apple device: Apple device certificate validation: To initiate the authentication of an Apple device attached to an accessory, the CP verifies that the X509 certificate supplied by Apple device has been signed by the proper certificate authority. Challenge generation: To continue the authentication of an Apple device attached to an accessory, the accessory's CP can generate a challenge to be sent to the apple device Signature verification: To complete the authentication of an Apple device attached to the accessory the Cp can verify the signature returned by the apple device in response to the previous challenge Terminology Used in This Document Certain technical terms specific to this document are defined in table 1-1 Table 1-1 Document-specific terminology Teri Definition Accessory controller The microcontroller in an accessory responsible for implementing application-specific logic. Authenticatⅰon a device in an accessory controller that provides apple device-related digital coprocessor signature creation and verification services Challenge A random number sent via iAP from an apple device to an accessory controller, or vice versa. the device being challenged must perform a digital signature computation on the offered challenge and return the resulting digital signature to the challenging device for verification. Digital signature he result obtained by performing a digital signing process on an offered challenge IAP od Accessory Protocol. See Apple's MFi Accessory Firmware Specification 12C b A 2-wire serial bus designed by philips to allow easy communication between components that reside on the same circuit board. The l2C specification is located Ithttp://www.semiconductors.philipscom/acrobat_download/itera ture/9398/39340011pdf Terminology Used in This Document 2011-06-22 I @2011 Apple Inc. All Rights Reserved. CHAPTER 1 Introduction Ter Definition X 509 certification/ A standard defined by the International Telecommunication Union(ITU)that governs the format of certificates used for authentication and sender identity verification in public-key cryptography. X509 certificates contain the public keys used in the apple device's accessory authentication process General Specification terms Parts of this document contain specification requirements that are incorporated by reference into legal agreements between Apple Inc and its licensees. the use of the words"must, " "should " and "may"in these specifications have the following meanings Must"means that the specification is an absolute requirement Must not"means that the specification is an absolute prohibition Should"means that there may be valid reasons in particular circumstances to ignore the specification, but their full implications must be understood and carefully weighed before choosing to do so Should not"means that there may be valid reasons in particular circumstances that make the specifie action or feature acceptable but their full implications must be understood and carefully weighed before choosing to include it May"means that the indicated action or feature does not contravene this specification Related documents For further information about authenticating Apple devices and their attached accessories, see apple's MFi Accessory Firmware Specification and MFi Accessory Hardware Specification Related documents 9 2011-06-22 I @2011 Apple Inc. All Rights Reserved. CHAPTER 1 Introduction Related documents 2011-06-22 I@ 2011 Apple Inc. All Rights Reserved.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值