Permalink
Browse files

Make password login configurable

  • Loading branch information...
1 parent ad1ff99 commit 4da50b198bf39668f7636f4d72a8469400197a3d @rolfbjarne rolfbjarne committed Apr 11, 2012
Showing with 19 additions and 0 deletions.
  1. +14 −0 MonkeyWrench.Web.UI/Login.aspx.cs
  2. +2 −0 MonkeyWrench.Web.UI/doc/Configuration.html
  3. +3 −0 MonkeyWrench/Configuration.cs
@@ -40,6 +40,7 @@ protected void Page_Load (object sender, EventArgs e)
{
string action = Request ["action"];
string referrer = Request ["referrer"];
+ bool noOpenIdResponse = false;
if (!string.IsNullOrEmpty (referrer))
@@ -55,6 +56,14 @@ protected void Page_Load (object sender, EventArgs e)
} else {
cmdLoginOpenId.Visible = true;
+ if (!Configuration.AllowPasswordLogin) {
+ cmdLogin.Visible = Configuration.AllowPasswordLogin;
+ txtPassword.Visible = Configuration.AllowPasswordLogin;
+ txtUser.Visible = Configuration.AllowPasswordLogin;
+ lblUser.Visible = Configuration.AllowPasswordLogin;
+ lblPassword.Visible = Configuration.AllowPasswordLogin;
+ }
+
OpenIdRelyingParty openid = new OpenIdRelyingParty ();
var oidresponse = openid.GetResponse ();
if (oidresponse != null) {
@@ -87,6 +96,8 @@ protected void Page_Load (object sender, EventArgs e)
lblMessageOpenId.Text = "Could not login using OpenId: " + oidresponse.Status.ToString ();
break;
}
+ } else {
+ noOpenIdResponse = true;
}
}
@@ -107,6 +118,9 @@ protected void Page_Load (object sender, EventArgs e)
Response.Redirect (txtReferrer.Value, false);
return;
}
+
+ if (!Configuration.AllowPasswordLogin && string.IsNullOrEmpty (action) && Configuration.AllowAnonymousAccess && noOpenIdResponse)
+ cmdLoginOpenId_Click (null, null);
}
protected void cmdLogin_Click (object sender, EventArgs e)
@@ -47,6 +47,7 @@ <h1 style='color: black;'>
&lt;AllowAnonymousAccess /&gt;
&lt;AutomaticScheduler /&gt;
&lt;AutomaticSchedulerInterval /&gt;
+ &lt;AllowPasswordLogin /&gt;
&lt;/Configuration&gt;
&lt;/MonkeyWrench&gt;
</pre>
@@ -109,6 +110,7 @@ <h1 style='color: black;'>
<h3>AllowAnonymousAccess</h3>If anonymous access is allowed for everything that's not specifically marked as internal (default: true).
<h3>OpenIdProvider</h3>The OpenId provider to use.
<h3>OpenIdRoles</h3>Specifies how OpenId emails are to translate into roles. Format: email:role1,role2;email:role2,role3. Email can be a regex. Sample: .*@xamarin.com:Admin
+ <h3>AllowPasswordLogin</h3>If password login is allowed (default: true). Disabling password logins only has an effect if OpenId is enabled (i.e. an OpenIdProvider has been configured).
<h3>AutomaticScheduler</h3>'true' or 'false'. If the scheduler is invoked automatically. Only relevant for the server. Defaults to false.
<h3>AutomaticSchedulerInterval</h3>The interval (in seconds) the scheduler is invoked automatically. Only relevant if AutomaticScheduler is set to true. Defaults to 60.
<h2>
@@ -49,6 +49,7 @@ public static class Configuration
// openid
public static string OpenIdProvider = null;
public static string OpenIdRoles = null;
+ public static bool AllowPasswordLogin = true;
public static bool AutomaticScheduler = false;
public static int AutomaticSchedulerInterval = 60;
@@ -187,6 +188,7 @@ public static bool LoadConfiguration (string [] arguments, string file)
OpenIdRoles = xml.SelectSingleNode ("MonkeyWrench/Configuration/OpenIdRoles").GetNodeValue (OpenIdRoles);
AutomaticScheduler = Boolean.Parse (xml.SelectSingleNode ("MonkeyWrench/Configuration/AutomaticScheduler").GetNodeValue (AutomaticScheduler.ToString ()));
AutomaticSchedulerInterval = int.Parse (xml.SelectSingleNode ("MonkeyWrench/Configuration/AutomaticSchedulerInterval").GetNodeValue (AutomaticSchedulerInterval.ToString ()));
+ AllowPasswordLogin = bool.Parse (xml.SelectSingleNode ("MonkeyWrench/Configuration/AllowPasswordLogin").GetNodeValue (AllowPasswordLogin.ToString ()));
// override from command line
@@ -219,6 +221,7 @@ public static bool LoadConfiguration (string [] arguments, string file)
{"openidroles=", v => OpenIdRoles = v },
{"automaticscheduler=", v => Boolean.Parse (v.Trim ())},
{"automaticschedulerinterval=", v => int.Parse (v.Trim ())},
+ {"allowpasswordlogin=", v => bool.Parse (v.Trim ())},
// values for the database manager
{"compress-files", v => CompressFiles = true},

0 comments on commit 4da50b1

Please sign in to comment.