1. Added WPAuthenticationModule.cs - WPS specific authentication module.
authorIlya Kharmatsky <ilya@mono-cvs.ximian.com>
Mon, 12 Mar 2007 11:14:22 +0000 (11:14 -0000)
committerIlya Kharmatsky <ilya@mono-cvs.ximian.com>
Mon, 12 Mar 2007 11:14:22 +0000 (11:14 -0000)
2. Added property CurrentUserName to IPumaServicesProvider

svn path=/trunk/mcs/; revision=74110

mcs/class/Mainsoft.Web/Mainsoft.Web.J2EE.WAS/Mainsoft.Web.J2EE.WAS.csproj
mcs/class/Mainsoft.Web/Mainsoft.Web.J2EE.WAS/Mainsoft.Web.Security/ChangeLog
mcs/class/Mainsoft.Web/Mainsoft.Web.J2EE.WAS/Mainsoft.Web.Security/IPumaServicesProvider.cs
mcs/class/Mainsoft.Web/Mainsoft.Web.J2EE.WAS/Mainsoft.Web.Security/PumaServicesProvider.cs
mcs/class/Mainsoft.Web/Mainsoft.Web.J2EE.WAS/Mainsoft.Web.Security/WPAuthenticationModule.cs [new file with mode: 0755]
mcs/class/Mainsoft.Web/Mainsoft.Web.J2EE.WAS/Mainsoft.Web.Security/WPGroupsRoleProvider.cs

index daa49e38107d4ed50fbc82f29d65ac0f4aa650c6..a788d6918010a9e1976766ef20e3cdeae052755b 100644 (file)
@@ -89,6 +89,7 @@
     <Compile Include="Mainsoft.Web.Security\WPGroupsRoleProvider.cs" />\r
     <Compile Include="Properties\AssemblyInfo.cs" />\r
     <Compile Include="Mainsoft.Web.Security\WPMembershipProvider.cs" />\r
+    <Compile Include="Mainsoft.Web.Security\WPAuthenticationModule.cs" />\r
     <Compile Include="Mainsoft.Web.Security\WPMembershipUser.cs" />\r
   </ItemGroup>\r
   <ItemGroup>\r
index 643983833c81e57459fdf7c50659af805059109c..9efe341e9536ff73bb95a2aaa93c1f8895946bc8 100755 (executable)
@@ -1,3 +1,11 @@
+03-12-2007      Ilya Kharmatsky    <ilyak -at- mainsoft.com>\r
+\r
+       * WPAuthenticationModule.cs: added to project. Portal specific\r
+       authentication module (uses PUMA services)\r
+       * IPumaServicesProvider.cs, PumaServicesProvider.cs,\r
+       WPGroupsRoleProvider.cs: added 'CurrentUserName' property and \r
+       internal helpers methods.\r
+\r
 03-01-2007      Ilya Kharmatsky    <ilyak -at- mainsoft.com>\r
 \r
        * PumaServicesProvider.cs: fixed PumaController property (proper\r
index 5fce25c202f53bd6fba16574ae211299e87cf100..dc2808036a7705602ce34f94489b283211054f8f 100644 (file)
@@ -76,6 +76,11 @@ namespace Mainsoft.Web.Security
         /// </summary>\r
         User CurrentUser { get; }\r
 \r
+        /// <summary>\r
+        /// Returns the human readable name of current user.\r
+        /// </summary>\r
+        string CurrentUserName { get;}\r
+\r
 \r
         /// <summary>\r
         /// Adds attribute for given principal (User or Group)\r
index 9f9bf25566bf2a7c0f8226c564625a8d77b08666..fa56b122d31d1a62a4a8086de3fc278bdcf304fe 100644 (file)
@@ -64,6 +64,8 @@ namespace Mainsoft.Web.Security
         \r
         private PumaHomeWrapper _pumaHome;\r
 \r
+        private java.util.List _nameAttributeList;\r
+\r
         #region Initialization \r
         \r
         internal PumaServicesProvider()\r
@@ -80,6 +82,9 @@ namespace Mainsoft.Web.Security
                     throw new ApplicationException("Cannot obtain servlet/portlet request");\r
                 _pumaHome = GetPumaHomeWrapper(httpReq);\r
             }\r
+\r
+            _nameAttributeList = new java.util.ArrayList(1);\r
+            _nameAttributeList.add("uid");\r
         }\r
 \r
         /* Needs HttpServletRequest because ServletRequest doesn't contain getSession method*/\r
@@ -156,6 +161,23 @@ namespace Mainsoft.Web.Security
             get { return _pumaHome.PumaProfile.getCurrentUser(); }\r
         }\r
 \r
+        public string CurrentUserName\r
+        {\r
+            get\r
+            {\r
+                com.ibm.portal.um.User user = CurrentUser;\r
+                string username = null;\r
+                \r
+                if (user != null)\r
+                {\r
+                    java.util.Map m = PumaProfile.getAttributes(user, _nameAttributeList);\r
+                    username = (string)m.get("uid");\r
+                }\r
+\r
+                return username;\r
+            }\r
+        }\r
+\r
         public void AddAttribute(com.ibm.portal.um.Principal p, string attributeName, string attributeValue)\r
         {\r
             HashMap map = new HashMap();\r
diff --git a/mcs/class/Mainsoft.Web/Mainsoft.Web.J2EE.WAS/Mainsoft.Web.Security/WPAuthenticationModule.cs b/mcs/class/Mainsoft.Web/Mainsoft.Web.J2EE.WAS/Mainsoft.Web.Security/WPAuthenticationModule.cs
new file mode 100755 (executable)
index 0000000..d253e79
--- /dev/null
@@ -0,0 +1,106 @@
+//\r
+// Mainsoft.Web.Security.WPAuthenticationModule\r
+//\r
+// Authors:\r
+//     Ilya Kharmatsky (ilyak@mainsoft.com)\r
+//\r
+// (C) 2007 Mainsoft Co. (http://www.mainsoft.com)\r
+//\r
+\r
+//\r
+// Permission is hereby granted, free of charge, to any person obtaining\r
+// a copy of this software and associated documentation files (the\r
+// "Software"), to deal in the Software without restriction, including\r
+// without limitation the rights to use, copy, modify, merge, publish,\r
+// distribute, sublicense, and/or sell copies of the Software, and to\r
+// permit persons to whom the Software is furnished to do so, subject to\r
+// the following conditions:\r
+// \r
+// The above copyright notice and this permission notice shall be\r
+// included in all copies or substantial portions of the Software.\r
+// \r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
+\r
+using System;\r
+using System.Security.Principal;\r
+using System.Text;\r
+using System.Web;\r
+using System.Web.Configuration;\r
+using System.Web.Util;\r
+using System.Web.Security;\r
+\r
+\r
+using javax.portlet;\r
+\r
+using vmw.portlet;\r
+\r
+namespace Mainsoft.Web.Security\r
+{\r
+    public sealed class WPAuthenticationModule : IHttpModule\r
+    {\r
+        public void Dispose()\r
+        {\r
+        }\r
+\r
+        public void Init(HttpApplication app)\r
+        {\r
+            app.AuthenticateRequest += new EventHandler(OnAuthenticateRequest);\r
+        }\r
+\r
+        void OnAuthenticateRequest(object sender, EventArgs args)\r
+        {\r
+            HttpApplication app = (HttpApplication)sender;\r
+            PortletRequest req = vmw.portlet.PortletUtils.getPortletRequest();\r
+            if (req != null)\r
+                app.Context.User = new WPPrincipal(req);\r
+        }\r
+    }\r
+\r
+    internal class WPPrincipal : IPrincipal\r
+    {\r
+        private IIdentity _identity;\r
+        private string _username;\r
+\r
+        public WPPrincipal(PortletRequest req)\r
+        {\r
+            string authType = req.getAuthType();\r
+            if (authType == null)\r
+                authType = "";\r
+            IPumaServicesProvider provider = PumaServicesProviderFactory.CreateProvider();\r
+            _username = provider.CurrentUserName;\r
+            _identity = new GenericIdentity(_username, authType);\r
+        }\r
+\r
+        public bool IsInRole(string role)\r
+        {\r
+            if (role == null)\r
+                return false;\r
+\r
+            if (_username == null)\r
+                return false;\r
+\r
+            try\r
+            {\r
+                return Roles.IsUserInRole(_username, role);\r
+            }\r
+            catch (Exception e)\r
+            {\r
+#if DEBUG\r
+                Console.WriteLine(e);\r
+#endif\r
+                return false;\r
+            }\r
+\r
+        }\r
+\r
+        public IIdentity Identity { get { return _identity; } }\r
+    }\r
+}\r
+\r
index 026d75a3e234b0f7712dfc6de95d2be23ae277ff..91ef10326c5097f7aa481d0919999f2015b5117d 100755 (executable)
@@ -173,6 +173,26 @@ namespace Mainsoft.Web.Security
 \r
         }\r
 \r
+        internal protected static string[] GetRolesForUser(com.ibm.portal.um.User user)\r
+        {\r
+            if (user == null)\r
+                return new string[0];\r
+\r
+            try\r
+            {\r
+                IPumaServicesProvider provider = PumaServicesProviderFactory.CreateProvider();\r
+                java.util.List groups = provider.PumaLocator.findGroupsByPrincipal(user, true);\r
+                return GroupsToStringArray(provider, groups);\r
+            }\r
+            catch (Exception e)\r
+            {\r
+#if DEBUG\r
+                Console.WriteLine(e);\r
+#endif\r
+                return new string[0];\r
+            }\r
+        }\r
+\r
         public override string[] GetUsersInRole(string roleName)\r
         {\r
             if(roleName == null || roleName == String.Empty) \r