{"id":201,"date":"2011-01-13T10:20:05","date_gmt":"2011-01-13T09:20:05","guid":{"rendered":"http:\/\/www.capri-soft.de\/blog\/?p=201"},"modified":"2011-04-12T09:16:55","modified_gmt":"2011-04-12T07:16:55","slug":"fluorinefx-standard-authentifizierung-uber-die-sesseion","status":"publish","type":"post","link":"https:\/\/www.capri-soft.de\/blog\/?p=201","title":{"rendered":"FluorineFX: Standard Authentifizierung \u00fcber die Session"},"content":{"rendered":"<h1>Aufgabenstellung<\/h1>\n<p>Im Internet sollen sich Benutzer an einer Anmeldemaske einer Flex-Anwendung anmelden. Die Berechtigungen sollen anhand des Benutzernamens festgelegt werden.<\/p>\n<h1>Ansatz<\/h1>\n<p>1.) FLEX: Erstellen der Anmeldemaske mit User\/Passwort<br \/>\n2.) C#: \u00dcberpr\u00fcfung ob die User\/Passwort-Kombination in der Datenbank vorhanden ist<br \/>\n3.) C#: Falls JA: Benutzer in die sessionvariable USERNAME schreiben \/ Falls NEIN: Tue nichts<br \/>\n4.) C#: \u00dcberpr\u00fcfung der Backend-Services: Ist USERNAME leer?<br \/>\nNEIN: Darf der User die Daten aufrufen?? (Dem Benutzer kann eine ROLLE zugewiesen sein, siehe Artikel &#8222;FluorineFX: Windows Authentifierung&#8230; Single Sign On&#8220;, und anhand der Rolle kann ermittelt werden ob sie berechtigt ist die Daten abzurufen).<br \/>\nJA: Keine Daten ausliefern!!!<br \/>\n5.) FLEX: Falls user authentifziert: Maskenaufbau in der Flexanwendung entsprechend Rolle <\/p>\n<h1>L\u00f6sung<\/h1>\n<p>Hier die wichtigsten Ausz\u00fcge aus meiner L\u00f6sung:<\/p>\n<p>FLEX: <\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n...\r\n&lt;mx:Script&gt;\r\npublic function getAuthenticationHandler(event:ResultEvent):void\r\n{\r\n   if( (event.result as Boolean) )\r\n   {\r\n     \/\/ Schalte ViewStack um (keine Loginmaske mehr)\r\n     loginStack.selectedChild=tarzanScreen;\r\n\r\n     \/\/ Speichere Username in Modellocator (evtl. auch Rolle holen)\r\n     ModelLocator.getInstance().myUser=txtUsername.text;\r\n   }\r\n   else\r\n   {\r\n      Alert.show(&#039;Wrong username or password!&#039;);\r\n    }\t\t\t\t\t\t\r\n}\r\n&lt;\/mx:Script&gt;\r\n...\r\n&lt;mx:TextInput id=&quot;txtUsername&quot; \/&gt;\r\n&lt;mx:TextInput id=&quot;txtPasswort&quot; displayAsPassword=&quot;true&quot;\/&gt;\r\n...\r\n&lt;mx:RemoteObject id=&quot;authenticationService&quot; destination=&quot;GenericDestination&quot;  \r\n                                          source=&quot;TarzanServices.AuthenticationService&quot; \r\n                                          showBusyCursor=&quot;true&quot; \r\n                                          fault=&quot;faultHandler(event)&quot; &gt;\r\n    &lt;mx:method name=&quot;getAuthentication&quot; result=&quot;getAuthenticationHandler(event)&quot;\/&gt;\r\n&lt;\/mx:RemoteObject&gt;\r\n<\/pre>\n<p>C#: Benutzername ermitteln: Falls &#8222;none&#8220; einfach nix in Maske\/Service machen: <\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.Text;\r\nusing System.Collections;\r\nusing System.Data.SqlClient;\r\nusing System.Web;\r\nusing FluorineFx;\r\nusing System.Security.Principal;\r\n...\r\npublic string getSessionUser()\r\n{\r\n    if (FluorineFx.Context.FluorineContext.Current.Session&#x5B;&quot;username&quot;]==null) \r\n    return &quot;none&quot;;\r\n\r\n    return FluorineFx.Context.FluorineContext.Current.Session&#x5B;&quot;username&quot;].ToString();\r\n}\r\n<\/pre>\n<p>C#: \u00dcberpr\u00fcfe ob User\/Kennwort-Kombination in der Datenbank vorhanden ist, falls JA, schreibe USERNAME in Sesseion und liefere TRUE zur\u00fcck, damit Flex wei\u00df das es von der Login-Maske weg darf.. (REAKTION IN FLEX). <\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\npublic bool getAuthentication(string username, string password)\r\n{\r\n   SqlConnection conn = new SqlConnection(MyConfigurationManager.msSqlServerString);\r\n\r\n   try\r\n   {\r\n      conn.Open();\r\n      SqlCommand comm = new SqlCommand();\r\n      comm.Connection = conn;\r\n      comm.CommandText = &quot;SELECT * FROM &#x5B;users] WHERE &#x5B;username]=@username &quot;+\r\n                                     &quot;AND &#x5B;password]=@passwort&quot;;\r\n      comm.Parameters.AddWithValue(&quot;username&quot;, username);\r\n      comm.Parameters.AddWithValue(&quot;passwort&quot;, password);\r\n\r\n      int i = 0;\r\n      SqlDataReader reader = comm.ExecuteReader();\r\n\r\n       while (reader.Read())\r\n       {\r\n              i++;\r\n       }\r\n\r\n       if (i &gt; 0)\r\n       {\r\n           \/\/ Schreibe USER in die Datenbank\r\n           FluorineFx.Context.FluorineContext.\r\n           Current.Session&#x5B;&quot;username&quot;] = username;\r\n       }\r\n\r\n       return i &gt; 0;\r\n   }\r\n   catch (Exception e)\r\n   {\r\n        return false;\r\n   }\r\n\r\n   return false;\r\n}\r\n<\/pre>\n<iframe src=\"http:\/\/www.facebook.com\/plugins\/like.php?href=https%3A%2F%2Fwww.capri-soft.de%2Fblog%2F%3Fp%3D201&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light\" scrolling=\"no\" frameborder=\"0\" allowTransparency=\"true\" style=\"border:none; overflow:hidden; width:450px;margin-top:5px;\"><\/iframe>","protected":false},"excerpt":{"rendered":"<p>Aufgabenstellung Im Internet sollen sich Benutzer an einer Anmeldemaske einer Flex-Anwendung anmelden. Die Berechtigungen sollen anhand des Benutzernamens festgelegt werden. Ansatz 1.) FLEX: Erstellen der Anmeldemaske mit User\/Passwort 2.) C#: \u00dcberpr\u00fcfung ob die User\/Passwort-Kombination in der Datenbank vorhanden ist 3.) C#: Falls JA: Benutzer in die sessionvariable USERNAME schreiben \/ Falls NEIN: Tue nichts 4.) &hellip; <a href=\"https:\/\/www.capri-soft.de\/blog\/?p=201\" class=\"more-link\"><span class=\"screen-reader-text\">FluorineFX: Standard Authentifizierung \u00fcber die Session<\/span> weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,5],"tags":[],"class_list":["post-201","post","type-post","status-publish","format-standard","hentry","category-net","category-adobe-flex"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4yGeN-3f","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/201","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=201"}],"version-history":[{"count":8,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/201\/revisions"}],"predecessor-version":[{"id":363,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/201\/revisions\/363"}],"wp:attachment":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=201"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=201"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=201"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}