View Javadoc

1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  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,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.server.kerberos.shared.store;
21  
22  
23  import org.apache.directory.server.core.CoreSession;
24  import org.apache.directory.server.core.DirectoryService;
25  import org.apache.directory.server.kerberos.shared.store.operations.AddPrincipal;
26  import org.apache.directory.server.kerberos.shared.store.operations.ChangePassword;
27  import org.apache.directory.server.kerberos.shared.store.operations.DeletePrincipal;
28  import org.apache.directory.server.kerberos.shared.store.operations.GetAllPrincipals;
29  import org.apache.directory.server.kerberos.shared.store.operations.GetPrincipal;
30  import org.apache.directory.server.protocol.shared.ServiceConfigurationException;
31  
32  import javax.security.auth.kerberos.KerberosPrincipal;
33  
34  
35  /**
36   * A JNDI-backed search strategy implementation. This search strategy searches 
37   * for Kerberos principals.
38   * 
39   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
40   * @version $Rev: 681578 $, $Date: 2008-08-01 03:20:21 +0200 (Fr, 01 Aug 2008) $
41   */
42  class SingleBaseSearch implements PrincipalStore
43  {
44      private final CoreSession session;
45  
46  
47      SingleBaseSearch( DirectoryService directoryService )
48      {
49          try
50          {
51              session = directoryService.getSession();
52          } 
53          catch ( Exception e )
54          {
55              throw new ServiceConfigurationException("Can't get a session", e);
56          }
57  
58      }
59  
60  
61      public String addPrincipal( PrincipalStoreEntry entry ) throws Exception
62      {
63          return ( String ) new AddPrincipal( entry ).execute( session, null );
64      }
65  
66  
67      public String deletePrincipal( KerberosPrincipal principal ) throws Exception
68      {
69          return ( String ) new DeletePrincipal( principal ).execute( session, null );
70      }
71  
72  
73      public PrincipalStoreEntry[] getAllPrincipals( String realm ) throws Exception
74      {
75          return ( PrincipalStoreEntry[] ) new GetAllPrincipals().execute( session, null );
76      }
77  
78  
79      public PrincipalStoreEntry getPrincipal( KerberosPrincipal principal ) throws Exception
80      {
81          return ( PrincipalStoreEntry ) new GetPrincipal( principal ).execute( session, null );
82      }
83  
84  
85      public String changePassword( KerberosPrincipal principal, String newPassword ) throws Exception
86      {
87          return ( String ) new ChangePassword( principal, newPassword ).execute( session, null );
88      }
89  }