Fixed the Orchard behavior of passing windows credentials to e-mail server when no credentials where entered.

Added an option to the smptsettings configuration to explicitly configure windows authentication.
This fixes bugs #2536 and #5024.
This commit is contained in:
Kees Damen
2015-04-24 23:15:46 +02:00
parent 4a92ec7c5a
commit c91ff87773
6 changed files with 46 additions and 23 deletions

View File

@@ -41,6 +41,7 @@ namespace Orchard.Email.Controllers {
smtpSettings.Port = testSettings.Port;
smtpSettings.EnableSsl = testSettings.EnableSsl;
smtpSettings.RequireCredentials = testSettings.RequireCredentials;
smtpSettings.UseDefaultCredentials = testSettings.UseDefaultCredentials;
smtpSettings.UserName = testSettings.UserName;
smtpSettings.Password = testSettings.Password;
@@ -97,6 +98,7 @@ namespace Orchard.Email.Controllers {
public int Port { get; set; }
public bool EnableSsl { get; set; }
public bool RequireCredentials { get; set; }
public bool UseDefaultCredentials { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public string To { get; set; }

View File

@@ -1,6 +1,5 @@
using System;
using System.Text;
using JetBrains.Annotations;
using Orchard.ContentManagement;
using Orchard.Email.Models;
using Orchard.ContentManagement.Handlers;
@@ -10,7 +9,6 @@ using Orchard.Security;
using System.Configuration;
namespace Orchard.Email.Handlers {
[UsedImplicitly]
public class SmtpSettingsPartHandler : ContentHandler {
private readonly IEncryptionService _encryptionService;

View File

@@ -41,6 +41,12 @@ namespace Orchard.Email.Models {
set { this.Store(x => x.RequireCredentials, value); }
}
public bool UseDefaultCredentials
{
get { return this.Retrieve(x => x.UseDefaultCredentials); }
set { this.Store(x => x.UseDefaultCredentials, value); }
}
public string UserName {
get { return this.Retrieve(x => x.UserName); }
set { this.Store(x => x.UserName, value); }

View File

@@ -141,24 +141,24 @@
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target> -->
<!-- To enable MVC area subproject support, uncomment the following two lines:
<UsingTask TaskName="Microsoft.Web.Mvc.Build.CreateAreaManifest" AssemblyName="Microsoft.Web.Mvc.Build, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<UsingTask TaskName="Microsoft.Web.Mvc.Build.CopyAreaManifests" AssemblyName="Microsoft.Web.Mvc.Build, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<!-- To enable MVC area subproject support, uncomment the following two lines:
<UsingTask TaskName="Microsoft.Web.Mvc.Build.CreateAreaManifest" AssemblyName="Microsoft.Web.Mvc.Build, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<UsingTask TaskName="Microsoft.Web.Mvc.Build.CopyAreaManifests" AssemblyName="Microsoft.Web.Mvc.Build, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
-->
<Target Name="AfterBuild" DependsOnTargets="AfterBuildCompiler">
<PropertyGroup>
<AreasManifestDir>$(ProjectDir)\..\Manifests</AreasManifestDir>
</PropertyGroup>
<!-- If this is an area child project, uncomment the following line:
<CreateAreaManifest AreaName="$(AssemblyName)" AreaType="Child" AreaPath="$(ProjectDir)" ManifestPath="$(AreasManifestDir)" ContentFiles="@(Content)" />
<!-- If this is an area child project, uncomment the following line:
<CreateAreaManifest AreaName="$(AssemblyName)" AreaType="Child" AreaPath="$(ProjectDir)" ManifestPath="$(AreasManifestDir)" ContentFiles="@(Content)" />
-->
<!-- If this is an area parent project, uncomment the following lines:
<CreateAreaManifest AreaName="$(AssemblyName)" AreaType="Parent" AreaPath="$(ProjectDir)" ManifestPath="$(AreasManifestDir)" ContentFiles="@(Content)" />
<CopyAreaManifests ManifestPath="$(AreasManifestDir)" CrossCopy="false" RenameViews="true" />
<!-- If this is an area parent project, uncomment the following lines:
<CreateAreaManifest AreaName="$(AssemblyName)" AreaType="Parent" AreaPath="$(ProjectDir)" ManifestPath="$(AreasManifestDir)" ContentFiles="@(Content)" />
<CopyAreaManifests ManifestPath="$(AreasManifestDir)" CrossCopy="false" RenameViews="true" />
-->
</Target>
<Target Name="AfterBuildCompiler" Condition="'$(MvcBuildViews)'=='true'">

View File

@@ -133,7 +133,7 @@ namespace Orchard.Email.Services {
}
var smtpClient = new SmtpClient {
UseDefaultCredentials = !_smtpSettings.RequireCredentials,
UseDefaultCredentials = _smtpSettings.RequireCredentials && _smtpSettings.UseDefaultCredentials
};
if (!smtpClient.UseDefaultCredentials && !String.IsNullOrWhiteSpace(_smtpSettings.UserName)) {

View File

@@ -35,18 +35,32 @@
<label for="@Html.FieldIdFor(m => m.RequireCredentials)" class="forcheckbox">@T("Require credentials")</label>
@Html.ValidationMessage("RequireCredentials", "*")
</div>
<div data-controllerid="@Html.FieldIdFor(m => m.RequireCredentials)">
<div>
<label for="@Html.FieldIdFor(m => m.UserName)">@T("User name")</label>
@Html.TextBoxFor(m => m.UserName, new { @class = "text" })
@Html.ValidationMessage("UserName", "*")
<span class="hint">@T("The username for authentication.")</span>
@Html.RadioButtonFor(m => m.UseDefaultCredentials, false)
<label for="@Html.FieldIdFor(m => m.UseDefaultCredentials)" class="forcheckbox">@T("Specify username/password")</label>
@Html.ValidationMessage("UseDefaultCredentials", "*")
</div>
<div>
<label for="@Html.FieldIdFor(m => m.Password)">@T("Password")</label>
@Html.TextBoxFor(m => m.Password, new { type = "password", @class = "text medium" })
@Html.ValidationMessage("Password", "*")
<span class="hint">@T("The password for authentication.")</span>
<div>
<label for="@Html.FieldIdFor(m => m.UserName)">@T("User name")</label>
@Html.TextBoxFor(m => m.UserName, new { @class = "text" })
@Html.ValidationMessage("UserName", "*")
<span class="hint">@T("The username for authentication.")</span>
</div>
<div>
<label for="@Html.FieldIdFor(m => m.Password)">@T("Password")</label>
@Html.TextBoxFor(m => m.Password, new { type = "password", @class = "text medium" })
@Html.ValidationMessage("Password", "*")
<span class="hint">@T("The password for authentication.")</span>
</div>
</div>
<div>
@Html.RadioButtonFor(m => m.UseDefaultCredentials, true, new { id = "smtpUseDefaultCredentials" })
<label for="smtpUseDefaultCredentials" class="forcheckbox">@T("Use Windows authentication")</label>
@Html.ValidationMessage("UseCustomCredentials", "*")
<span class="hint">@T("When this option is checked, the aplication pool or host-process identity is used to authenticate with the mail server. ")</span>
</div>
</div>
</fieldset>
@@ -80,7 +94,8 @@
</div>
<div id="emailtesterror" class="message-Error" style="display:none;"></div>
<div id="emailtestinfo" class="message-Information" style="display:none;"></div>
@using (Script.Foot()) {
@using (Script.Foot())
{
<script type="text/javascript">
$(function () {
var url = "@Url.Action("TestSettings", "EmailAdmin", new {area = "Orchard.Email"})",
@@ -91,6 +106,7 @@
port = $("#@Html.FieldIdFor(m => m.Port)"),
enableSsl = $("#@Html.FieldIdFor(m => m.EnableSsl)"),
requireCredentials = $("#@Html.FieldIdFor(m => m.RequireCredentials)"),
useDefaultCredentials = $("input[name='@Html.NameFor(m => m.UseDefaultCredentials)']"),
userName = $("#@Html.FieldIdFor(m => m.UserName)"),
password = $("#@Html.FieldIdFor(m => m.Password)"),
to = $("#emailtestto"),
@@ -107,6 +123,7 @@
port: port.val(),
enableSsl: enableSsl.prop("checked"),
requireCredentials: requireCredentials.prop("checked"),
useDefaultCredentials: useDefaultCredentials.filter(':checked').val(),
userName: userName.val(),
password: password.val(),
to: to.val(),