{"id":2316,"date":"2017-03-02T13:00:37","date_gmt":"2017-03-02T11:00:37","guid":{"rendered":"http:\/\/hasselba.ch\/blog\/?p=2316"},"modified":"2017-03-02T13:00:37","modified_gmt":"2017-03-02T11:00:37","slug":"domino-rest-accessing-dominos-environment-check-authentication","status":"publish","type":"post","link":"https:\/\/hasselba.ch\/blog\/?p=2316","title":{"rendered":"Domino &#038; REST: Accessing Domino&#8217;s Environment \/ Check Authentication"},"content":{"rendered":"<p>If we want to access Domino&#8217;s Environment, it is the <em>ContextInfo\u00a0<\/em>class which gives us all we need. Everything you need to do to use the class is described in an <a href=\"https:\/\/hasselba.ch\/blog\/?p=1889\" target=\"_blank\">earlier blog post<\/a>.<\/p>\n<p>The class gives mainly access to the following methods:<\/p>\n<table style=\"width: 639px;\">\n<tbody>\n<tr>\n<td><strong>Method<\/strong><\/td>\n<td><strong>Description<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<tbody>\n<tr>\n<td style=\"width: 302.722px;\">getDataDirectory()<\/td>\n<td style=\"width: 239.278px;\">Path to notes data directory<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 302.722px;\">getEnvironmentString(String envName)<\/td>\n<td style=\"width: 239.278px;\">Returns the environment variable<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 302.722px;\">getServerDatabase()<\/td>\n<td style=\"width: 239.278px;\">The actual database as NAPI object, if any<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 302.722px;\">getServerVariable(String varName)<\/td>\n<td style=\"width: 239.278px;\">Variables from the Request, i.e. &#8222;QUERY_STRING&#8220;<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 302.722px;\">getUserDatabase()<\/td>\n<td style=\"width: 239.278px;\">The actual database as Domino Java object, if any<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 302.722px;\">getUserSession()<\/td>\n<td style=\"width: 239.278px;\">The session of the actual user performing the request (<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 302.722px;\">isAnonymous()<\/td>\n<td style=\"width: 239.278px;\">true if the current user is Anonymous<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Keep in mind that the incoming request is independently of any underlying Notes database. In\u00a0our example, the URI <em>http:\/\/your.server\/dominorestservlet\/helloworld\/\u00a0<\/em>does not run inside of a NSF, that&#8217;s why the <em>getServerDatabase()<\/em> and the <em>getUserDatabase()<\/em> methods returns\u00a0<em>null<\/em>.<\/p>\n<p>As a consequence, our servlet does not have any access restriction and is reachable as anonymous. If you want to access a database programatically, the &#8222;normal&#8220; Domino access control\u00a0is\u00a0intervening again, but we can\u00a0do the access check by ourself.<\/p>\n<p>To prevent the access to the servlet, I have added a &#8222;<em>checkAuthentication<\/em>&#8220; method to the\u00a0<a href=\"https:\/\/github.com\/hasselbach\/domino-rest-servlet\/blob\/master\/domino-rest-servlet.plugin\/src\/ch\/hasselba\/dominorestservlet\/RestApiServlet.java\" target=\"_blank\">RestApiServlet<\/a> class. This method checks if the current user is a) not anonymous and b) a member of the group <em>RESTAPIAccessAllowed<\/em>. The method throws a\u00a0<em>NotAuthenticatedException<\/em>\u00a0which let&#8217;s the servlet return a <a href=\"https:\/\/en.wikipedia.org\/wiki\/HTTP_403\" target=\"_blank\">HTTP 403<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If we want to access Domino&#8217;s Environment, it is the ContextInfo\u00a0class which gives us all we need. Everything you need to do to use the class is described in an earlier blog post. The class gives mainly access to the &hellip; <a href=\"https:\/\/hasselba.ch\/blog\/?p=2316\">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":{"footnotes":""},"categories":[120,114,89,116,61],"tags":[118,7,11,115,31,65,60,12],"class_list":["post-2316","post","type-post","status-publish","format-standard","hentry","category-apache-wink","category-jackson","category-java","category-jee","category-rest","tag-apache-wink","tag-domino","tag-http","tag-jackson","tag-java","tag-osgi","tag-rest","tag-web"],"_links":{"self":[{"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2316","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2316"}],"version-history":[{"count":8,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2316\/revisions"}],"predecessor-version":[{"id":2324,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2316\/revisions\/2324"}],"wp:attachment":[{"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2316"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2316"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hasselba.ch\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2316"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}