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.operations;
21  
22  
23  import javax.security.auth.kerberos.KerberosPrincipal;
24  
25  import org.apache.directory.server.core.CoreSession;
26  import org.apache.directory.server.core.entry.ServerEntry;
27  import org.apache.directory.server.protocol.shared.store.DirectoryServiceOperation;
28  import org.apache.directory.shared.ldap.name.LdapDN;
29  
30  
31  /**
32   * Command for deleting a principal from a JNDI context.
33   *
34   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
35   * @version $Rev: 682235 $, $Date: 2008-08-04 02:43:52 +0200 (Mo, 04 Aug 2008) $
36   */
37  public class DeletePrincipal implements DirectoryServiceOperation
38  {
39      private static final long serialVersionUID = -6970986279811261983L;
40  
41      /** The Kerberos principal who is to be deleted. */
42      protected KerberosPrincipal principal;
43  
44  
45      /**
46       * Creates the action to be used against the embedded ApacheDS DIT.
47       * 
48       * @param principal The principal to delete.
49       */
50      public DeletePrincipal( KerberosPrincipal principal )
51      {
52          this.principal = principal;
53      }
54  
55  
56      public Object execute( CoreSession session, LdapDN searchBaseDn ) throws Exception
57      {
58          if ( principal == null )
59          {
60              return null;
61          }
62  
63          ServerEntry entry = StoreUtils.findPrincipalEntry( session, searchBaseDn, principal.getName() );
64          session.delete( entry.getDn() );
65          return entry.getDn();
66      }
67  }