Skip to content

Commit e1fe249

Browse files
authored
Merge pull request puppetlabs#109 from jpogran/ticket/master/MODULES-5229-iis-site-authentication
(MODULES-5229) Add authenticationinfo to iis_site
2 parents c400f93 + 482f18f commit e1fe249

6 files changed

Lines changed: 110 additions & 1 deletion

File tree

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,24 @@ iis_site {'mysite'
776776
}
777777
```
778778

779+
##### `authenticationinfo`
780+
781+
Enable and disable authentication schemas. The available schemas are: anonymous, basic, clientCertificateMapping, digest, iisClientCertificateMapping, windows.
782+
783+
###### Example
784+
785+
```
786+
iis_site { 'test_site':
787+
ensure => 'started',
788+
physicalpath => 'C:\\inetpub\\tmp',
789+
applicationpool => 'DefaultAppPool',
790+
authenticationinfo => {
791+
'basic' => true,
792+
'anonymous' => false,
793+
},
794+
}
795+
```
796+
779797
### iis_virtual_directory
780798

781799
Allows creation of a new IIS Virtual Directory and configuration of virtual directory parameters.

lib/puppet/provider/iis_site/webadministration.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,17 @@ def update
4949

5050
cmd << self.class.ps_script_content('serviceautostartprovider', @resource)
5151

52-
52+
if @resource[:authenticationinfo]
53+
@resource[:authenticationinfo].each do |auth,enable|
54+
args = Array.new
55+
args << "-Filter 'system.webserver/security/authentication/#{auth}Authentication'"
56+
args << "-PSPath 'IIS:\\'"
57+
args << "-Location '#{@resource[:name]}'"
58+
args << "-Name enabled"
59+
args << "-Value #{@resource[:authenticationinfo][auth]}"
60+
cmd << "Set-WebConfigurationProperty #{args.join(' ')} -ErrorAction Stop\n"
61+
end
62+
end
5363

5464
inst_cmd = cmd.join
5565

@@ -108,6 +118,9 @@ def self.prefetch(resources)
108118
sites = instances
109119
resources.keys.each do |site|
110120
if !sites.nil? && provider = sites.find { |s| s.name == site }
121+
if !resources[site]['authenticationinfo'].nil?
122+
resources[site]['authenticationinfo'] = provider.authenticationinfo.merge(resources[site]['authenticationinfo'])
123+
end
111124
resources[site].provider = provider
112125
end
113126
end
@@ -142,6 +155,7 @@ def self.instances
142155
binding.delete('certificatestorename') unless binding['protocol'] == 'https'
143156
end
144157
site['limits'] = {} if site['limits'].nil?
158+
site['authenticationinfo'] = {} if site['authenticationinfo'].nil?
145159

146160
site_hash[:ensure] = site['state'].downcase
147161
site_hash[:name] = site['name']
@@ -158,6 +172,7 @@ def self.instances
158172
site_hash[:logformat] = site['logformat']
159173
site_hash[:logflags] = site['logextfileflags'].split(/,\s*/).sort
160174
site_hash[:preloadenabled] = to_bool(site['preloadenabled']) unless site['preloadenabled'].nil?
175+
site_hash[:authenticationinfo] = site['authenticationinfo']
161176

162177
new(site_hash)
163178
end

lib/puppet/provider/templates/webadministration/_getwebsites.ps1.erb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ Get-WebSite | % {
77
$preloadenabled = [string](Get-ItemProperty -Path "IIS:\Sites\$($name)" -Name 'applicationDefaults.preloadEnabled' -ErrorAction 'Continue').Value
88
}
99

10+
$authenticationTypes = @(
11+
'anonymous',
12+
'basic',
13+
'clientCertificateMapping',
14+
'digest',
15+
'iisClientCertificateMapping',
16+
'windows'
17+
)
18+
$authenticationTypes | Foreach-Object -Begin { $info = @{} } -Process {
19+
$p = Get-WebConfiguration -Filter "system.webserver/security/authentication/$($_)Authentication" -PSPath "IIS:\sites\$($name)"
20+
$info["$($_)"] = $p.enabled
21+
}
22+
$authenticationinfo = New-Object -TypeName PSObject -Property $info
23+
1024
New-Object -TypeName PSObject -Property @{
1125
name = [string]$_.Name
1226
physicalpath = [string]$_.PhysicalPath
@@ -29,6 +43,7 @@ Get-WebSite | % {
2943
maxconnections = [int64]$_.limits.maxconnections
3044
connectiontimeout = [int]$_.limits.connectiontimeout.totalseconds
3145
}
46+
authenticationinfo = $authenticationinfo
3247
logformat = [string]$_.LogFile.logFormat
3348
logpath = [string]$_.LogFile.directory
3449
logperiod = [string]$_.LogFile.period

lib/puppet/type/iis_site.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'puppet/parameter/boolean'
22
require_relative '../../puppet_x/puppetlabs/iis/property/name'
3+
require_relative '../../puppet_x/puppetlabs/iis/property/hash'
34

45
Puppet::Type.newtype(:iis_site) do
56
@doc = "Create a new IIS website."
@@ -314,6 +315,18 @@ def insync?(is)
314315
end
315316
end
316317

318+
newproperty(:authenticationinfo) do
319+
desc 'Enable and disable authentication schemas. Note: some schemas require additional Windows features to be installed, for example windows authentication. This type does not ensure a given feature is installed before attempting to configure it.'
320+
valid_schemas = ['anonymous', 'basic', 'clientCertificateMapping',
321+
'digest', 'iisClientCertificateMapping', 'windows']
322+
validate do |value|
323+
fail "#{self.name.to_s} should be a Hash" unless value.is_a? ::Hash
324+
unless (value.keys & valid_schemas) == value.keys
325+
fail("All schemas must specify any of the following: anonymous, basic, clientCertificateMapping, digest, iisClientCertificateMapping, or windows")
326+
end
327+
end
328+
end
329+
317330
autorequire(:iis_application_pool) { self[:applicationpool] }
318331

319332
validate do

spec/acceptance/iis_site_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,32 @@
189189
end
190190
end
191191

192+
context 'when setting' do
193+
describe 'authenticationinfo' do
194+
before(:all) do
195+
@site_name = SecureRandom.hex(10)
196+
create_path('C:\inetpub\tmp')
197+
@manifest = <<-HERE
198+
iis_site { '#{@site_name}':
199+
ensure => 'started',
200+
physicalpath => 'C:\\inetpub\\tmp',
201+
applicationpool => 'DefaultAppPool',
202+
authenticationinfo => {
203+
'basic' => true,
204+
'anonymous' => false,
205+
},
206+
}
207+
HERE
208+
end
209+
210+
it_behaves_like 'an idempotent resource'
211+
212+
after(:all) do
213+
remove_all_sites
214+
end
215+
end
216+
end
217+
192218
# TestRail ID: C100071
193219
context 'can change site state from' do
194220
context 'stopped to started' do

spec/unit/puppet/type/iis_site_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,28 @@
5858
end
5959
end
6060

61+
context "property: authenticationinfo" do
62+
it "requires a hash or array of hashes" do
63+
expect {
64+
resource[:authenticationinfo] = "hi"
65+
}.to raise_error(Puppet::Error, /Hash/)
66+
expect {
67+
resource[:authenticationinfo] = ["hi"]
68+
}.to raise_error(Puppet::Error, /Hash/)
69+
end
70+
it "requires any of the schemas" do
71+
expect {
72+
resource[:authenticationinfo] = { 'wakka' => 'fdskjfndslk' }
73+
}.to raise_error(Puppet::Error, /schema/)
74+
end
75+
it "allows valid syntax" do
76+
resource[:authenticationinfo] = {
77+
'basic' => true,
78+
'anonymous' => false,
79+
}
80+
end
81+
end
82+
6183
context "property :bindings" do
6284
it "requires a hash or array of hashes" do
6385
expect {

0 commit comments

Comments
 (0)