Revision: 13662
          http://gate.svn.sourceforge.net/gate/?rev=13662&view=rev
Author:   valyt
Date:     2011-04-12 13:51:18 +0000 (Tue, 12 Apr 2011)

Log Message:
-----------
Support for authentication in RemoteIndex (domain object, views, service).

Modified Paths:
--------------
    
mimir/trunk/grails-plugin-mimir/grails-app/domain/gate/mimir/web/RemoteIndex.groovy
    
mimir/trunk/grails-plugin-mimir/grails-app/services/gate/mimir/web/RemoteIndexService.groovy
    mimir/trunk/grails-plugin-mimir/grails-app/views/remoteIndex/create.gsp
    mimir/trunk/grails-plugin-mimir/grails-app/views/remoteIndex/edit.gsp
    mimir/trunk/grails-plugin-mimir/grails-app/views/remoteIndex/show.gsp
    
mimir/trunk/grails-plugin-mimir/src/groovy/gate/mimir/util/WebUtilsManager.groovy

Modified: 
mimir/trunk/grails-plugin-mimir/grails-app/domain/gate/mimir/web/RemoteIndex.groovy
===================================================================
--- 
mimir/trunk/grails-plugin-mimir/grails-app/domain/gate/mimir/web/RemoteIndex.groovy
 2011-04-12 13:08:07 UTC (rev 13661)
+++ 
mimir/trunk/grails-plugin-mimir/grails-app/domain/gate/mimir/web/RemoteIndex.groovy
 2011-04-12 13:51:18 UTC (rev 13662)
@@ -12,6 +12,8 @@
   
   static constraints = {
     remoteUrl(blank:false, nullable:false)
+    remoteUsername(blank:true, nullable:true)
+    remotePassword(blank:true, nullable:true)
   }
   
   /**
@@ -19,6 +21,19 @@
    */
   String remoteUrl
   
+  
+  /**
+   * If the remote server uses authentication, the username to be used when 
+   * connecting.
+   */
+  String remoteUsername
+  
+  /**
+   * If the remote server uses authentication, the password to be used when 
+   * connecting
+   */
+  String remotePassword
+  
   // behaviour
   
   /**
@@ -46,7 +61,7 @@
     
     //create a local RemoteQueryRunner and store the service URL, index ID, 
     //and query ID in it.
-    return new RemoteQueryRunner(remoteUrl, query, searchThreadPool, 
webUtilsManager.currentWebUtils(remoteUrl))
+    return new RemoteQueryRunner(remoteUrl, query, searchThreadPool, 
webUtilsManager.currentWebUtils(this))
   }
 
   /**
@@ -57,7 +72,7 @@
     String urlStr = (remoteUrl.endsWith("/") ? remoteUrl : (remoteUrl + "/")) 
+ 
         "search/annotationsConfigBin";
     try{
-      return webUtilsManager.currentWebUtils(remoteUrl).getObject(urlStr)
+      return webUtilsManager.currentWebUtils(this).getObject(urlStr)
     }catch(Exception e){
       return new String[0][0]
     }
@@ -72,7 +87,7 @@
     String urlStr = (remoteUrl.endsWith("/") ? remoteUrl : (remoteUrl + "/")) 
+ 
         "manage/indexUrl";
     try{
-      webUtilsManager.currentWebUtils(remoteUrl).getText(responseString, 
urlStr)
+      webUtilsManager.currentWebUtils(this).getText(responseString, urlStr)
     }catch(IOException e){
       log.error("Problem communicating with the remote server!", e)
       RemoteIndex.withTransaction{
@@ -90,7 +105,7 @@
     String urlStr = (remoteUrl.endsWith("/") ? remoteUrl : (remoteUrl + "/")) 
+ 
     "manage/close";
     try{
-      webUtilsManager.currentWebUtils(remoteUrl).getVoid(urlStr)
+      webUtilsManager.currentWebUtils(this).getVoid(urlStr)
     }catch(IOException e){
       log.error("Problem communicating with the remote server!", e)
       RemoteIndex.withTransaction{

Modified: 
mimir/trunk/grails-plugin-mimir/grails-app/services/gate/mimir/web/RemoteIndexService.groovy
===================================================================
--- 
mimir/trunk/grails-plugin-mimir/grails-app/services/gate/mimir/web/RemoteIndexService.groovy
        2011-04-12 13:08:07 UTC (rev 13661)
+++ 
mimir/trunk/grails-plugin-mimir/grails-app/services/gate/mimir/web/RemoteIndexService.groovy
        2011-04-12 13:51:18 UTC (rev 13662)
@@ -89,7 +89,7 @@
   private fetchRemoteState(RemoteIndex index) {
     StringBuilder sb = new StringBuilder()
     try {
-      webUtilsManager.currentWebUtils(index.remoteUrl).getText(sb, 
"${index.remoteUrl}/manage/stateBin")
+      webUtilsManager.currentWebUtils(index).getText(sb, 
"${index.remoteUrl}/manage/stateBin")
       index.state = sb.toString()
     }
     catch(IOException e) {
@@ -100,7 +100,7 @@
   
   private fetchClosingProgress(RemoteIndex index) {
     try {
-      closingProgress = 
webUtilsManager.currentWebUtils(index.remoteUrl).getDouble(
+      closingProgress = webUtilsManager.currentWebUtils(index).getDouble(
           "${index.remoteUrl}/manage/closingProgressBin")
     }
     catch(IOException e) {

Modified: 
mimir/trunk/grails-plugin-mimir/grails-app/views/remoteIndex/create.gsp
===================================================================
--- mimir/trunk/grails-plugin-mimir/grails-app/views/remoteIndex/create.gsp     
2011-04-12 13:08:07 UTC (rev 13661)
+++ mimir/trunk/grails-plugin-mimir/grails-app/views/remoteIndex/create.gsp     
2011-04-12 13:51:18 UTC (rev 13662)
@@ -34,7 +34,7 @@
                        </tr>
 
                        <tr class="prop">
-                               <td valign="top" class="name"><label 
for="serverUrl">Remote
+                               <td valign="top" class="name"><label 
for="remoteUrl">Remote
                                URL:</label></td>
                                <td valign="top"
                                        class="value 
${hasErrors(bean:remoteIndexInstance,field:'remoteUrl','errors')}">
@@ -46,6 +46,32 @@
                          <td colspan="2">This should be the "Index URL" from 
the target index's management page.</td>
                        </tr>
 
+                       <tr class="prop">
+                               <td valign="top" class="name"><label 
for="remoteUsername">Remote Username:</label></td>
+                               <td valign="top"
+                                       class="value 
${hasErrors(bean:remoteIndexInstance,field:'remoteUsername','errors')}">
+                               <input type="text" id="remoteUsername" 
name="remoteUsername"
+                                       
value="${fieldValue(bean:remoteIndexInstance,field:'remoteUsername')}" />
+                               </td>
+                       </tr>
+                       <tr>
+                         <td colspan="2">If the remote server requires 
authentication, enter here
+                         the username that should be used when connecting.</td>
+                       </tr>
+                       
+                       <tr class="prop">
+                               <td valign="top" class="name"><label 
for="remotePassword">Remote Password:</label></td>
+                               <td valign="top"
+                                       class="value 
${hasErrors(bean:remoteIndexInstance,field:'remotePassword','errors')}">
+                               <input type="password" id="remotePassword" 
name="remotePassword"
+                                       
value="${fieldValue(bean:remoteIndexInstance,field:'remotePassword')}" />
+                               </td>
+                       </tr>
+                       <tr>
+                         <td colspan="2">If the remote server requires 
authentication, enter here
+                         the password that should be used when connecting.</td>
+                       </tr>
+
       <tr class="prop">
         <td valign="top" class="name"><label for="uriIsExternalLink">Document
       URIs are external links:</label></td>

Modified: mimir/trunk/grails-plugin-mimir/grails-app/views/remoteIndex/edit.gsp
===================================================================
--- mimir/trunk/grails-plugin-mimir/grails-app/views/remoteIndex/edit.gsp       
2011-04-12 13:08:07 UTC (rev 13661)
+++ mimir/trunk/grails-plugin-mimir/grails-app/views/remoteIndex/edit.gsp       
2011-04-12 13:51:18 UTC (rev 13662)
@@ -63,7 +63,36 @@
                                        
value="${fieldValue(bean:remoteIndexInstance,field:'remoteUrl')}" />
                                </td>
                        </tr>
+                       <tr>
+                         <td colspan="2">This should be the "Index URL" from 
the target index's management page.</td>
+                       </tr>
 
+                       <tr class="prop">
+                               <td valign="top" class="name"><label 
for="remoteUsername">Remote Username:</label></td>
+                               <td valign="top"
+                                       class="value 
${hasErrors(bean:remoteIndexInstance,field:'remoteUsername','errors')}">
+                               <input type="text" id="remoteUsername" 
name="remoteUsername"
+                                       
value="${fieldValue(bean:remoteIndexInstance,field:'remoteUsername')}" />
+                               </td>
+                       </tr>
+                       <tr>
+                         <td colspan="2">If the remote server requires 
authentication, enter here
+                         the username that should be used when connecting.</td>
+                       </tr>
+                       
+                       <tr class="prop">
+                               <td valign="top" class="name"><label 
for="remotePassword">Remote Password:</label></td>
+                               <td valign="top"
+                                       class="value 
${hasErrors(bean:remoteIndexInstance,field:'remotePassword','errors')}">
+                               <input type="password" id="remotePassword" 
name="remotePassword"
+                                       
value="${fieldValue(bean:remoteIndexInstance,field:'remotePassword')}" />
+                               </td>
+                       </tr>
+                       <tr>
+                         <td colspan="2">If the remote server requires 
authentication, enter here
+                         the password that should be used when connecting.</td>
+                       </tr>
+
       <tr class="prop">
         <td valign="top" class="name"><label for="uriIsExternalLink">Document
       URIs are external links:</label></td>

Modified: mimir/trunk/grails-plugin-mimir/grails-app/views/remoteIndex/show.gsp
===================================================================
--- mimir/trunk/grails-plugin-mimir/grails-app/views/remoteIndex/show.gsp       
2011-04-12 13:08:07 UTC (rev 13661)
+++ mimir/trunk/grails-plugin-mimir/grails-app/views/remoteIndex/show.gsp       
2011-04-12 13:51:18 UTC (rev 13662)
@@ -76,6 +76,15 @@
                        </td>
                </tr>
 
+               <tr class="prop">
+                       <td valign="top" class="name"><label 
style="margin-left: 20px">Remote
+                       Username:</label></td>
+                       <td valign="top" class="value">
+                       ${fieldValue(bean:remoteIndexInstance,
+                                                               
field:'remoteUsername')}
+                       </td>
+               </tr>
+               
     <tr class="prop">
       <td valign="top" class="name"><label for="uriIsExternalLink">Document
       URIs are external links:</label></td>

Modified: 
mimir/trunk/grails-plugin-mimir/src/groovy/gate/mimir/util/WebUtilsManager.groovy
===================================================================
--- 
mimir/trunk/grails-plugin-mimir/src/groovy/gate/mimir/util/WebUtilsManager.groovy
   2011-04-12 13:08:07 UTC (rev 13661)
+++ 
mimir/trunk/grails-plugin-mimir/src/groovy/gate/mimir/util/WebUtilsManager.groovy
   2011-04-12 13:51:18 UTC (rev 13662)
@@ -3,19 +3,27 @@
 import org.springframework.web.context.request.RequestContextHolder as RCH
 
 import gate.mimir.tool.WebUtils
+import gate.mimir.web.RemoteIndex;
 
 class WebUtilsManager {
-  public WebUtils currentWebUtils(String remoteUrl) {
+  public WebUtils currentWebUtils(RemoteIndex remoteIndex) {
     if(RCH.requestAttributes) {
       WebUtils utils = RCH.requestAttributes.session.webUtilsInstance
       if(!utils) {
-        utils = new WebUtils()
+        utils = new WebUtils(remoteIndex.remoteUsername, 
+          remoteIndex.remotePassword)
         RCH.requestAttributes.session.webUtilsInstance = utils
       }
       return utils
     } else {
-      // no thread-bound request, use the static instance
-      return WebUtils.staticWebUtils()
+      // no thread-bound request, use the static instance (if no authentication
+      // required), or a fresh one every time
+      if(remoteIndex.remoteUsername) {
+        return new WebUtils(remoteIndex.remoteUsername, 
+            remoteIndex.remotePassword)   
+      } else {
+        return WebUtils.staticWebUtils()
+      }
     }
   }
 }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Forrester Wave Report - Recovery time is now measured in hours and minutes
not days. Key insights are discussed in the 2010 Forrester Wave Report as
part of an in-depth evaluation of disaster recovery service providers.
Forrester found the best-in-class provider in terms of services and vision.
Read this report now!  http://p.sf.net/sfu/ibm-webcastpromo
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to