1 package org.apache.archiva.redback.users.ldap.service;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import org.apache.archiva.redback.common.ldap.user.LdapUser;
23 import org.apache.archiva.redback.components.cache.builder.CacheBuilder;
24 import org.springframework.stereotype.Service;
26 import javax.inject.Inject;
29 * DefaultLdapCacheService
31 * @author: Maria Odea Ching <oching@apache.org>
35 public class DefaultLdapCacheService
36 implements LdapCacheService
39 private CacheBuilder cacheBuilder;
44 * @see LdapCacheService#getUser(String)
46 public LdapUser getUser( String username )
48 return (LdapUser) cacheBuilder.getCache( "ldapUser" ).get( username );
52 * @see LdapCacheService#removeUser(String)
54 public boolean removeUser( String username )
56 return ( cacheBuilder.getCache( "ldapUser" ).remove( username ) == null ? false : true );
60 * @see LdapCacheService#removeAllUsers()
62 public void removeAllUsers()
64 cacheBuilder.getCache( "ldapUser" ).clear();
68 * @see LdapCacheService#addUser(org.apache.archiva.redback.common.ldap.user.LdapUser)
70 public void addUser( LdapUser user )
72 LdapUser existingUser = (LdapUser) cacheBuilder.getCache( "ldapUser" ).get( user.getUsername() );
73 if( existingUser != null )
75 removeUser( user.getUsername() );
78 cacheBuilder.getCache( "ldapUser" ).put( user.getUsername(), user );
84 * @see LdapCacheService#getLdapUserDn(String)
86 public String getLdapUserDn( String username )
88 return (String) cacheBuilder.getCache( "ldapUserDn" ).get( username );
92 * @see LdapCacheService#removeLdapUserDn(String)
94 public boolean removeLdapUserDn( String username )
96 return ( cacheBuilder.getCache( "ldapUserDn" ).remove( username ) == null ? false : true );
100 * @see org.apache.archiva.redback.users.ldap.service.LdapCacheService#removeAllLdapUserDn()
102 public void removeAllLdapUserDn()
104 cacheBuilder.getCache( "ldapUserDn" ).clear();
108 * @see LdapCacheService#addLdapUserDn(String, String)
110 public void addLdapUserDn( String username, String userDn )
112 String existingUserDn = (String) cacheBuilder.getCache( "ldapUserDn" ).get( username );
113 if( existingUserDn != null )
115 removeUser( username );
118 cacheBuilder.getCache( "ldapUserDn" ).put( username, userDn );