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 org.springframework.extensions.config.ConfigService;
22  import org.springframework.extensions.config.RemoteConfigElement;
23  import org.springframework.extensions.config.RemoteConfigElement.EndpointDescriptor;
24  
25  /**
26   * An abstract implementation of a persistent credential vault
27   * where crednetials can be stored from a persistent location.
28   *  
29   * @author muzquiano
30   */
31  public abstract class AbstractPersistentCredentialVault extends SimpleCredentialVault
32  {
33      protected ConfigService configService;
34      
35      /**
36       * Instantiates a new persistentcredential vault.
37       * 
38       * @param id the id
39       */    
40      public AbstractPersistentCredentialVault(String id)
41      {
42          super(id);
43      }
44      
45      /**
46       * Sets the config service.
47       * 
48       * @param configService
49       */
50      public void setConfigService(ConfigService configService)
51      {
52          this.configService = configService;
53      }
54      
55      /* (non-Javadoc)
56       * @see org.alfresco.connector.CredentialVault#store(java.lang.String, java.lang.String, org.alfresco.connector.Credentials)
57       */
58      public void store(Credentials credentials)
59      {
60          // check whether the given credentials should be flagged
61          // as persistent
62          String endpointId = credentials.getEndpointId();
63          EndpointDescriptor descriptor = getRemoteConfig().getEndpointDescriptor(endpointId);
64          if(descriptor != null)
65          {
66              // mark the persistence attribute onto the credentials
67              ((CredentialsImpl)credentials).persistent = descriptor.getPersistent();
68          }
69          
70          super.store(credentials);
71      }
72      
73      /**
74       * @return RemoteConfigElement
75       */
76      protected RemoteConfigElement getRemoteConfig()
77      {
78          RemoteConfigElement remoteConfig = (RemoteConfigElement)configService.getConfig(
79                  "Remote").getConfigElement("remote");
80          return remoteConfig;
81      }    
82  
83      /* (non-Javadoc)
84       * @see java.lang.Object#toString()
85       */
86      @Override
87      public String toString()
88      {
89          return "PersistentCredentialVault - " + this.id;
90      }    
91  }