View Javadoc

1   /**
2    * Copyright (C) 2005-2009 Alfresco Software Limited.
3    *
4    * This file is part of the Spring Surf Extension project.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *  http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.springframework.extensions.webscripts.connector;
20  
21  import java.io.Serializable;
22  import java.util.HashMap;
23  import java.util.Iterator;
24  
25  /**
26   * Credentials for a given user. This stores credentials that are to be passed
27   * to a back-end service in order to authenticate. Once these credentials are
28   * used to authenticate, they may no longer be necessary as the service may hand
29   * back "endpoint credentials" which are to be used on subsequent calls.
30   * 
31   * An example of a user credential might be username/password.
32   * 
33   * An example of an endpoint credential might be an Alfresco ticket.
34   * 
35   * @author muzquiano
36   */
37  public class CredentialsImpl implements Credentials, Serializable
38  {
39      protected boolean persistent;
40      protected String endpointId;
41      protected HashMap<String, Object> properties = new HashMap<String, Object>();
42  
43      /**
44       * Instantiates a new user credential.
45       * 
46       * @param endpointId the endpoint id
47       */
48      public CredentialsImpl(String endpointId)
49      {
50          this.endpointId = endpointId;
51      }
52  
53      /* (non-Javadoc)
54       * @see org.alfresco.connector.Credentials#getEndpointId()
55       */
56      public String getEndpointId()
57      {
58          return this.endpointId;
59      }
60  
61      /* (non-Javadoc)
62       * @see org.alfresco.connector.Credentials#getProperty(java.lang.String)
63       */
64      public Object getProperty(String key)
65      {
66          return this.properties.get(key);
67      }
68  
69      /* (non-Javadoc)
70       * @see org.alfresco.connector.Credentials#setProperty(java.lang.String, java.lang.Object)
71       */
72      public void setProperty(String key, Object value)
73      {
74          this.properties.put(key, value);
75      }
76  
77      /* (non-Javadoc)
78       * @see org.alfresco.connector.Credentials#removeProperty(java.lang.String)
79       */
80      public void removeProperty(String key)
81      {
82          this.properties.remove(key);
83      }
84      
85      /* (non-Javadoc)
86       * @see org.alfresco.connector.Credentials#removeAllProperties(java.lang.String)
87       */
88      public void removeAllProperties(String key)
89      {
90          this.properties.clear();
91      }
92      
93      /* (non-Javadoc)
94       * @see org.alfresco.connector.Credentials#getPropertyKeys()
95       */
96      public String[] getPropertyKeys()
97      {
98          String[] keys = new String[this.properties.keySet().size()];
99          
100         int count = 0;
101         Iterator it = this.properties.keySet().iterator();
102         while(it.hasNext())
103         {
104             keys[count] = (String) it.next();
105             count++;
106         }
107         
108         return keys;
109     }
110 
111     /* (non-Javadoc)
112      * @see org.alfresco.connector.Credentials#isPersistent()
113      */    
114     public boolean isPersistent()
115     {
116         return this.persistent;       
117     }
118 
119     /* (non-Javadoc)
120      * @see java.lang.Object#toString()
121      */
122     @Override
123     public String toString()
124     {
125         return this.properties.toString();
126     }
127 }