\r
private PumaHomeWrapper _pumaHome;\r
\r
+ private java.util.List _nameAttributeList;\r
+\r
#region Initialization \r
\r
internal PumaServicesProvider()\r
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
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
--- /dev/null
+//\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