当前位置: 首页>>代码示例>>Java>>正文


Java CRLFTerminatedReader.readLine方法代码示例

本文整理汇总了Java中org.subethamail.smtp.io.CRLFTerminatedReader.readLine方法的典型用法代码示例。如果您正苦于以下问题:Java CRLFTerminatedReader.readLine方法的具体用法?Java CRLFTerminatedReader.readLine怎么用?Java CRLFTerminatedReader.readLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.subethamail.smtp.io.CRLFTerminatedReader的用法示例。


在下文中一共展示了CRLFTerminatedReader.readLine方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import org.subethamail.smtp.io.CRLFTerminatedReader; //导入方法依赖的package包/类
/** */
@Override
public void execute(String commandString, Session sess)
		throws IOException
{
	if (sess.isAuthenticated())
	{
		sess.sendResponse("503 Refusing any other AUTH command.");
		return;
	}

	AuthenticationHandlerFactory authFactory = sess.getServer().getAuthenticationHandlerFactory();

	if (authFactory == null)
	{
		sess.sendResponse("502 Authentication not supported");
		return;
	}

	AuthenticationHandler authHandler = authFactory.create();

	String[] args = this.getArgs(commandString);
	// Let's check the command syntax
	if (args.length < 2)
	{
		sess.sendResponse("501 Syntax: " + VERB + " mechanism [initial-response]");
		return;
	}

	// Let's check if we support the required authentication mechanism
	String mechanism = args[1];
	if (!authFactory.getAuthenticationMechanisms().contains(mechanism.toUpperCase(Locale.ENGLISH)))
	{
		sess.sendResponse("504 The requested authentication mechanism is not supported");
		return;
	}
	// OK, let's go trough the authentication process.
	try
	{
		// The authentication process may require a series of challenge-responses
		CRLFTerminatedReader reader = sess.getReader();

		String response = authHandler.auth(commandString);
		if (response != null)
		{
			// challenge-response iteration
			sess.sendResponse(response);
		}

		while (response != null)
		{
			String clientInput = reader.readLine();
			if (clientInput.trim().equals(AUTH_CANCEL_COMMAND))
			{
				// RFC 2554 explicitly states this:
				sess.sendResponse("501 Authentication canceled by client.");
				return;
			}
			else
			{
				response = authHandler.auth(clientInput);
				if (response != null)
				{
					// challenge-response iteration
					sess.sendResponse(response);
				}
			}
		}

		sess.sendResponse("235 Authentication successful.");
		sess.setAuthenticationHandler(authHandler);
	}
	catch (RejectException authFailed)
	{
		sess.sendResponse(authFailed.getErrorResponse());
	}
}
 
开发者ID:voodoodyne,项目名称:subethasmtp,代码行数:78,代码来源:AuthCommand.java


注:本文中的org.subethamail.smtp.io.CRLFTerminatedReader.readLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。