{"id":3183,"date":"2018-06-01T14:19:22","date_gmt":"2018-06-01T19:19:22","guid":{"rendered":"http:\/\/lisa.rushworth.us\/?p=3183"},"modified":"2018-06-01T14:20:18","modified_gmt":"2018-06-01T19:20:18","slug":"oud-returning-some-directorystring-syntax-values-as-utf-8-encoded-bytes","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=3183","title":{"rendered":"OUD Returning Some DirectoryString Syntax Values As UTF-8 Encoded Bytes"},"content":{"rendered":"<p>We are still in the process of moving the last few applications from DSEE to OUD 11g so the DSEE 6.3 directory can be decommissioned. Just two to go! But the application, when pointed to the OUD servers, gets &#8220;Unable to cast object of type &#8216;System.Byte[]&#8217; to type &#8216;System.String'&#8221; when retrieving values for a few of our DirectoryString syntax custom schema.<\/p>\n<p>This code snippet works fine with DSEE 6.3.<\/p>\n<pre>string strUserGivenName = (String)searchResult.Properties[\"givenName\"][0]; \r\nstring strUserSurame = (String)searchResult.Properties[\"sn\"][0]; \r\nstring strSupervisorFirstName = (String)searchResult.Properties[\"positionmanagernamefirst\"][0];\u00a0\r\nstring strSupervisorLastName = (String)searchResult.Properties[\"positionmanagernamelast\"][0];<\/pre>\n<p>Direct the connection to the OUD 11g servers, and an error is returned.<\/p>\n<p><a href=\"http:\/\/lisa.rushworth.us\/?attachment_id=3184\" rel=\"attachment wp-att-3184\">\u00a0 \u00a0 \u00a0<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3184\" src=\"http:\/\/lisa.rushworth.us\/wp-content\/uploads\/2018\/06\/WithoutWorkaroundForUTF8.png\" alt=\"\" width=\"769\" height=\"314\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2018\/06\/WithoutWorkaroundForUTF8.png 769w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2018\/06\/WithoutWorkaroundForUTF8-300x122.png 300w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2018\/06\/WithoutWorkaroundForUTF8-768x314.png 768w\" sizes=\"auto, (max-width: 769px) 100vw, 769px\" \/><\/a><\/p>\n<p>The attributes use the same syntax &#8211; DirectoryString, OID\u00a01.3.6.1.4.1.1466.115.121.1.15.<\/p>\n<p><small>00-core.ldif:attributeTypes: ( 2.5.4.41 NAME &#8216;name&#8217; EQUALITY caseIgnoreMatch SUBSTR caseIgnoreSubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} X-ORIGIN &#8216;RFC 4519&#8217; )\u00a0<\/small><br \/>\n<small>00-core.ldif:attributeTypes: ( 2.5.4.4 NAME ( &#8216;sn&#8217; &#8216;surname&#8217; ) SUP name X-ORIGIN &#8216;RFC 4519&#8217; )\u00a0<\/small><br \/>\n<small>00-core.ldif:attributeTypes: ( 2.5.4.42 NAME &#8216;givenName&#8217; SUP name X-ORIGIN &#8216;RFC 4519&#8217; )\u00a0<\/small><\/p>\n<p><small>99-user.ldif:attributeTypes: ( positionManagerNameMI-oid NAME &#8216;positionmanagernamemi&#8217; DESC &#8216;User Defined Attribute&#8217; SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE X-ORIGIN &#8216;user defined&#8217; )\u00a0<\/small><br \/>\n<small>99-user.ldif:attributeTypes: ( positionManagerNameFirst-oid NAME &#8216;positionmanagernamefirst&#8217; DESC &#8216;User Defined Attribute&#8217; SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE X-ORIGIN &#8216;user defined&#8217; )\u00a0<\/small><br \/>\n<small>99-user.ldif:attributeTypes: ( positionManagerNameLast-oid NAME &#8216;positionmanagernamelast&#8217; DESC &#8216;User Defined Attribute&#8217; SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE X-ORIGIN &#8216;user defined&#8217; )\u00a0<\/small><\/p>\n<p>I&#8217;ve put together a quick check to see if the returned value is an array, and\u00a0<em>if it is<\/em> then get a string from the decoded byte array.<\/p>\n<pre>string strUserGivenName = (String)searchResult.Properties[\"givenName\"][0];\u00a0\r\nstring strUserSurame = (String)searchResult.Properties[\"sn\"][0];\u00a0\r\n\r\nstring strSupervisorFirstName = \"\";\r\nstring strSupervisorLastName = \"\";\r\nif (searchResult.Properties[\"positionmanagernamefirst\"][0].GetType().IsArray){\r\n    strSupervisorFirstName = System.Text.Encoding.UTF8.GetString((byte[])searchResult.Properties[\"positionmanagernamefirst\"][0]);\r\n}\r\nelse{\r\n    strSupervisorFirstName = searchResult.Properties[\"positionmanagernamefirst\"][0].ToString();\r\n}\r\n\r\nif (searchResult.Properties[\"positionmanagernamelast\"][0].GetType().IsArray){\r\n    strSupervisorLastName = System.Text.Encoding.UTF8.GetString((byte[])searchResult.Properties[\"positionmanagernamelast\"][0]);\r\n}\r\nelse{\r\n    strSupervisorLastName = searchResult.Properties[\"positionmanagernamelast\"][0].ToString();\r\n}<\/pre>\n<p>Voila<\/p>\n<p><a href=\"http:\/\/lisa.rushworth.us\/?attachment_id=3185\" rel=\"attachment wp-att-3185\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3185\" src=\"http:\/\/lisa.rushworth.us\/wp-content\/uploads\/2018\/06\/WithWorkaroundForUTF8.png\" alt=\"\" width=\"718\" height=\"328\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2018\/06\/WithWorkaroundForUTF8.png 718w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2018\/06\/WithWorkaroundForUTF8-300x137.png 300w\" sizes=\"auto, (max-width: 718px) 100vw, 718px\" \/><\/a><\/p>\n<p>The outstanding question is if we need to wrap *all* DirectoryString syntax attributes in this check to be safe or if there&#8217;s a\u00a0<em>reason<\/em>\u00a0core schema attributes like givenName and sn are being returned as strings whilst our add-on schema attributes have been encoded.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We are still in the process of moving the last few applications from DSEE to OUD 11g so the DSEE 6.3 directory can be decommissioned. Just two to go! But the application, when pointed to the OUD servers, gets &#8220;Unable to cast object of type &#8216;System.Byte[]&#8217; to type &#8216;System.String&#8217;&#8221; when retrieving values for a few &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33,30],"tags":[593,550,591],"class_list":["post-3183","post","type-post","status-publish","format-standard","hentry","category-coding","category-system-administration","tag-dsee","tag-oracle-unified-directory","tag-oud"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/3183","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3183"}],"version-history":[{"count":3,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/3183\/revisions"}],"predecessor-version":[{"id":3188,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/3183\/revisions\/3188"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}