mirror of
https://github.com/token2/pgina.git
synced 2026-03-13 11:14:19 -07:00
for the change password scenario. - Only tested on OpenLDAP, needs testing on other servers. - Also includes updated sample plugin with change password. - Adds a dependency on the BouncyCastle library. - Closes #26
124 lines
4.7 KiB
C#
124 lines
4.7 KiB
C#
/*
|
|
Copyright (c) 2011, pGina Team
|
|
All rights reserved.
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
modification, are permitted provided that the following conditions are met:
|
|
* Redistributions of source code must retain the above copyright
|
|
notice, this list of conditions and the following disclaimer.
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
notice, this list of conditions and the following disclaimer in the
|
|
documentation and/or other materials provided with the distribution.
|
|
* Neither the name of the pGina Team nor the names of its contributors
|
|
may be used to endorse or promote products derived from this software without
|
|
specific prior written permission.
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Diagnostics;
|
|
|
|
using log4net;
|
|
|
|
using pGina.Shared.Interfaces;
|
|
using pGina.Shared.Types;
|
|
using pGina.Shared.Settings;
|
|
|
|
namespace pGina.Plugin.Sample
|
|
{
|
|
public class SimplePlugin : IPluginConfiguration, IPluginAuthentication, IPluginChangePassword
|
|
{
|
|
private ILog m_logger = LogManager.GetLogger("SimplePlugin");
|
|
public static Guid SimpleUuid = new Guid("{16FC47C0-F17B-4D99-A820-EDBF0B0C764A}");
|
|
private string m_defaultDescription = "A demonstration plugin that allows all usernames that begin with the letter \"p\" to succeed.";
|
|
private dynamic m_settings = null;
|
|
|
|
public SimplePlugin()
|
|
{
|
|
using(Process me = Process.GetCurrentProcess())
|
|
{
|
|
m_settings = new pGinaDynamicSettings(SimpleUuid);
|
|
m_settings.SetDefault("ShowDescription", true);
|
|
m_settings.SetDefault("Description", m_defaultDescription);
|
|
|
|
m_logger.DebugFormat("Plugin initialized on {0} in PID: {1} Session: {2}", Environment.MachineName, me.Id, me.SessionId);
|
|
}
|
|
}
|
|
|
|
public string Name
|
|
{
|
|
get { return "Simple Demonstration"; }
|
|
}
|
|
|
|
public string Description
|
|
{
|
|
get { return m_settings.Description; }
|
|
}
|
|
|
|
public string Version
|
|
{
|
|
get
|
|
{
|
|
return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
|
}
|
|
}
|
|
|
|
public Guid Uuid
|
|
{
|
|
get { return SimpleUuid; }
|
|
}
|
|
|
|
BooleanResult IPluginAuthentication.AuthenticateUser(SessionProperties properties)
|
|
{
|
|
try
|
|
{
|
|
m_logger.DebugFormat("AuthenticateUser({0})", properties.Id.ToString());
|
|
|
|
// Get user info
|
|
UserInformation userInfo = properties.GetTrackedSingle<UserInformation>();
|
|
|
|
m_logger.DebugFormat("Found username: {0}", userInfo.Username);
|
|
if (userInfo.Username.StartsWith("p"))
|
|
{
|
|
m_logger.InfoFormat("Authenticated user: {0}", userInfo.Username);
|
|
return new BooleanResult() { Success = true };
|
|
}
|
|
|
|
m_logger.ErrorFormat("Failed to authenticate user: {0}", userInfo.Username);
|
|
return new BooleanResult() { Success = false, Message = string.Format("Your username does not start with a 'p'") };
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
m_logger.ErrorFormat("AuthenticateUser exception: {0}", e);
|
|
throw; // Allow pGina service to catch and handle exception
|
|
}
|
|
}
|
|
|
|
public void Configure()
|
|
{
|
|
Configuration conf = new Configuration();
|
|
conf.ShowDialog();
|
|
}
|
|
|
|
public void Starting() { }
|
|
public void Stopping() { }
|
|
|
|
public BooleanResult ChangePassword(ChangePasswordInfo cpInfo, ChangePasswordPluginActivityInfo pluginInfo)
|
|
{
|
|
return new BooleanResult() { Success = true, Message = "Success from the sample plugin" };
|
|
}
|
|
}
|
|
}
|