forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20130619.authconf.php
164 lines (151 loc) · 5.31 KB
/
20130619.authconf.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
$config_map = array(
'PhabricatorLDAPAuthProvider' => array(
'enabled' => 'ldap.auth-enabled',
'registration' => true,
'type' => 'ldap',
'domain' => 'self',
),
'PhabricatorAuthProviderOAuthDisqus' => array(
'enabled' => 'disqus.auth-enabled',
'registration' => 'disqus.registration-enabled',
'permanent' => 'disqus.auth-permanent',
'oauth.id' => 'disqus.application-id',
'oauth.secret' => 'disqus.application-secret',
'type' => 'disqus',
'domain' => 'disqus.com',
),
'PhabricatorFacebookAuthProvider' => array(
'enabled' => 'facebook.auth-enabled',
'registration' => 'facebook.registration-enabled',
'permanent' => 'facebook.auth-permanent',
'oauth.id' => 'facebook.application-id',
'oauth.secret' => 'facebook.application-secret',
'type' => 'facebook',
'domain' => 'facebook.com',
),
'PhabricatorAuthProviderOAuthGitHub' => array(
'enabled' => 'github.auth-enabled',
'registration' => 'github.registration-enabled',
'permanent' => 'github.auth-permanent',
'oauth.id' => 'github.application-id',
'oauth.secret' => 'github.application-secret',
'type' => 'github',
'domain' => 'github.com',
),
'PhabricatorAuthProviderOAuthGoogle' => array(
'enabled' => 'google.auth-enabled',
'registration' => 'google.registration-enabled',
'permanent' => 'google.auth-permanent',
'oauth.id' => 'google.application-id',
'oauth.secret' => 'google.application-secret',
'type' => 'google',
'domain' => 'google.com',
),
'PhabricatorPasswordAuthProvider' => array(
'enabled' => 'auth.password-auth-enabled',
'enabled-default' => false,
'registration' => false,
'type' => 'password',
'domain' => 'self',
),
);
foreach ($config_map as $provider_class => $spec) {
$enabled_key = idx($spec, 'enabled');
$enabled_default = idx($spec, 'enabled-default', false);
$enabled = PhabricatorEnv::getEnvConfigIfExists(
$enabled_key,
$enabled_default);
if (!$enabled) {
echo pht('Skipping %s (not enabled).', $provider_class)."\n";
// This provider was not previously enabled, so we can skip migrating it.
continue;
} else {
echo pht('Migrating %s...', $provider_class)."\n";
}
$registration_key = idx($spec, 'registration');
if ($registration_key === true) {
$registration = 1;
} else if ($registration_key === false) {
$registration = 0;
} else {
$registration = (int)PhabricatorEnv::getEnvConfigIfExists(
$registration_key,
true);
}
$unlink_key = idx($spec, 'permanent');
if (!$unlink_key) {
$unlink = 1;
} else {
$unlink = (int)(!PhabricatorEnv::getEnvConfigIfExists($unlink_key));
}
$config = id(new PhabricatorAuthProviderConfig())
->setIsEnabled(1)
->setShouldAllowLogin(1)
->setShouldAllowRegistration($registration)
->setShouldAllowLink(1)
->setShouldAllowUnlink($unlink)
->setProviderType(idx($spec, 'type'))
->setProviderDomain(idx($spec, 'domain'))
->setProviderClass($provider_class);
if (isset($spec['oauth.id'])) {
$config->setProperty(
PhabricatorAuthProviderOAuth::PROPERTY_APP_ID,
PhabricatorEnv::getEnvConfigIfExists(idx($spec, 'oauth.id')));
$config->setProperty(
PhabricatorAuthProviderOAuth::PROPERTY_APP_SECRET,
PhabricatorEnv::getEnvConfigIfExists(idx($spec, 'oauth.secret')));
}
switch ($provider_class) {
case 'PhabricatorFacebookAuthProvider':
$config->setProperty(
PhabricatorFacebookAuthProvider::KEY_REQUIRE_SECURE,
(int)PhabricatorEnv::getEnvConfigIfExists(
'facebook.require-https-auth'));
break;
case 'PhabricatorLDAPAuthProvider':
$ldap_map = array(
PhabricatorLDAPAuthProvider::KEY_HOSTNAME
=> 'ldap.hostname',
PhabricatorLDAPAuthProvider::KEY_PORT
=> 'ldap.port',
PhabricatorLDAPAuthProvider::KEY_DISTINGUISHED_NAME
=> 'ldap.base_dn',
PhabricatorLDAPAuthProvider::KEY_SEARCH_ATTRIBUTES
=> 'ldap.search_attribute',
PhabricatorLDAPAuthProvider::KEY_USERNAME_ATTRIBUTE
=> 'ldap.username-attribute',
PhabricatorLDAPAuthProvider::KEY_REALNAME_ATTRIBUTES
=> 'ldap.real_name_attributes',
PhabricatorLDAPAuthProvider::KEY_VERSION
=> 'ldap.version',
PhabricatorLDAPAuthProvider::KEY_REFERRALS
=> 'ldap.referrals',
PhabricatorLDAPAuthProvider::KEY_START_TLS
=> 'ldap.start-tls',
PhabricatorLDAPAuthProvider::KEY_ANONYMOUS_USERNAME
=> 'ldap.anonymous-user-name',
PhabricatorLDAPAuthProvider::KEY_ANONYMOUS_PASSWORD
=> 'ldap.anonymous-user-password',
// Update the old "search first" setting to the newer but similar
// "always search" setting.
PhabricatorLDAPAuthProvider::KEY_ALWAYS_SEARCH
=> 'ldap.search-first',
PhabricatorLDAPAuthProvider::KEY_ACTIVEDIRECTORY_DOMAIN
=> 'ldap.activedirectory_domain',
);
$defaults = array(
'ldap.version' => 3,
'ldap.port' => 389,
);
foreach ($ldap_map as $pkey => $ckey) {
$default = idx($defaults, $ckey);
$config->setProperty(
$pkey,
PhabricatorEnv::getEnvConfigIfExists($ckey, $default));
}
break;
}
$config->save();
}
echo pht('Done.')."\n";