This project has retired. For details please refer to its Attic page.
DefaultLdapCacheService xref
View Javadoc

1   package org.apache.archiva.redback.users.ldap.service;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.archiva.redback.common.ldap.user.LdapUser;
23  import org.apache.archiva.redback.components.cache.Cache;
24  import org.springframework.stereotype.Service;
25  
26  import javax.inject.Inject;
27  import javax.inject.Named;
28  
29  /**
30   * DefaultLdapCacheService
31   *
32   * @author: Maria Odea Ching <oching@apache.org>
33   * @version
34   */
35  @Service
36  public class DefaultLdapCacheService
37      implements LdapCacheService
38  {
39      @Inject
40      @Named(value = "cache#ldapUser")
41      private Cache<String, LdapUser> usersCache;
42  
43      @Inject
44      @Named(value = "cache#ldapUserDn")
45      private Cache<String, String> ldapCacheDn;
46  
47  
48  
49      // LDAP Users
50  
51      /**
52       * @see LdapCacheService#getUser(String)
53       */
54      public LdapUser getUser( String username )
55      {
56          return usersCache.get( username );
57      }
58  
59      /**
60       * @see LdapCacheService#removeUser(String)
61       */
62      public boolean removeUser( String username )
63      {
64          return ( usersCache.remove( username ) == null ? false : true );
65      }
66  
67      /**
68       * @see LdapCacheService#removeAllUsers()
69       */
70      public void removeAllUsers()
71      {
72          usersCache.clear();
73      }
74  
75      /**
76       * @see LdapCacheService#addUser(org.apache.archiva.redback.common.ldap.user.LdapUser)
77       */
78      public void addUser( LdapUser user )
79      {
80          LdapUser existingUser = usersCache.get( user.getUsername() );
81          if( existingUser != null )
82          {
83              removeUser( user.getUsername() );
84          }
85  
86          usersCache.put( user.getUsername(), user );
87      }
88  
89      // LDAP UserDn
90  
91      /**
92       * @see LdapCacheService#getLdapUserDn(String)
93       */
94      public String getLdapUserDn( String username )
95      {
96          return ldapCacheDn.get( username );
97      }
98  
99      /**
100      * @see LdapCacheService#removeLdapUserDn(String)
101      */
102     public boolean removeLdapUserDn( String username )
103     {
104         return ( ldapCacheDn.remove( username ) == null ? false : true );
105     }
106 
107     /**
108      * @see org.apache.archiva.redback.users.ldap.service.LdapCacheService#removeAllLdapUserDn()
109      */
110     public void removeAllLdapUserDn()
111     {
112         ldapCacheDn.clear();
113     }
114 
115     /**
116      * @see LdapCacheService#addLdapUserDn(String, String) 
117      */
118     public void addLdapUserDn( String username, String userDn )
119     {
120         String existingUserDn = ldapCacheDn.get( username );
121         if( existingUserDn != null )
122         {
123             removeUser( username );
124         }
125 
126         ldapCacheDn.put( username, userDn );
127     }
128     
129 }