View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/community/resolver/src/java/org/astrogrid/community/resolver/ant/CommunityPasswordResolverTask.java,v $</cvs:source>
3    * <cvs:author>$Author: dave $</cvs:author>
4    * <cvs:date>$Date: 2004/06/18 13:45:20 $</cvs:date>
5    * <cvs:version>$Revision: 1.4 $</cvs:version>
6    *
7    * <cvs:log>
8    *   $Log: CommunityPasswordResolverTask.java,v $
9    *   Revision 1.4  2004/06/18 13:45:20  dave
10   *   Merged development branch, dave-dev-200406081614, into HEAD
11   *
12   *   Revision 1.3.18.1  2004/06/17 13:38:59  dave
13   *   Tidied up old CVS log entries
14   *
15   * </cvs:log>
16   *
17   *
18   */
19  package org.astrogrid.community.resolver.ant ;
20  
21  import java.net.URL ;
22  
23  import org.apache.tools.ant.Task ;
24  import org.apache.tools.ant.BuildException ;
25  
26  import org.astrogrid.community.resolver.CommunityPasswordResolver ;
27  
28  /***
29   * An Ant task to login to a Community service.
30   * 
31   */
32  public class CommunityPasswordResolverTask
33      extends CommunityResolverTask
34      {
35      /***
36       * Our debug flag.
37       *
38       */
39      private static final boolean DEBUG_FLAG = true ;
40  
41      /***
42       * Public constructor.
43       *
44       */
45      public CommunityPasswordResolverTask()
46          {
47          //
48          // Initialise our base class.
49          super() ;
50          }
51  
52      /***
53       * Public constructor.
54       *
55       */
56      public CommunityPasswordResolverTask(Task parent)
57          {
58          //
59          // Initialise our base class.
60          super() ;
61          //
62          // Set our project.
63          setProject(parent.getProject()) ;
64          }
65  
66      /***
67       * Initialise our Task.
68       *
69       */
70      public void init()
71          throws BuildException
72          {
73          if (DEBUG_FLAG) System.out.println("----\"----");
74          if (DEBUG_FLAG) System.out.println("CommunityPasswordResolverTask.init()");
75          }
76  
77      /***
78       * Our account identifier.
79       *
80       */
81      private String account ;
82  
83      /***
84       * Get our account identifier.
85       *
86       */
87      public String getAccount()
88          {
89          return this.account ;
90          }
91  
92      /***
93       * Set our account identifier.
94       *
95       */
96      public void setAccount(String value)
97          {
98          this.account = value ;
99          }
100 
101     /***
102      * Our account password.
103      *
104      */
105     private String password ;
106 
107     /***
108      * Get our account password.
109      *
110      */
111     public String getPassword()
112         {
113         return this.password ;
114         }
115 
116     /***
117      * Set our account password.
118      *
119      */
120     public void setPassword(String value)
121         {
122         this.password = value ;
123         }
124 
125     /***
126      * Execute our Task.
127      *
128      */
129     public void execute()
130         throws BuildException
131         {
132         if (DEBUG_FLAG) System.out.println("----\"----");
133         if (DEBUG_FLAG) System.out.println("CommunityPasswordResolverTask.execute()");
134         if (DEBUG_FLAG) System.out.println("  Account  : " + this.account);
135         if (DEBUG_FLAG) System.out.println("  Password : " + this.password);
136         //
137         // Load our config properties.
138         this.configure() ;
139         //
140         // Try login to the account.
141         try {
142             //
143             // Create our resolver.
144             CommunityPasswordResolver resolver ;
145             //
146             // Use our registry endpoint, if we have one.
147             if (null != this.getRegistry())
148                 {
149                 resolver = new CommunityPasswordResolver(
150                     new URL(
151                         this.getRegistry()
152                         )
153                     ) ;
154                 }
155             //
156             // Otherwise, just create a default resolver.
157             else {
158                 resolver = new CommunityPasswordResolver() ;
159                 }
160             //
161             // Ask our resolver to check the password
162             this.setToken(
163                 resolver.checkPassword(
164                     this.account,
165                     this.password
166                     )
167                 ) ;
168             }
169         catch (Exception ouch)
170             {
171             throw new BuildException(ouch) ;
172             }
173         if (DEBUG_FLAG) System.out.println("----");
174         if (DEBUG_FLAG) System.out.println("Token : " + this.getToken());
175         if (DEBUG_FLAG) System.out.println("----");
176         }
177     }
178