Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 10362 invoked from network); 22 Mar 2005 09:32:46 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 22 Mar 2005 09:32:46 -0000 Received: (qmail 59067 invoked by uid 500); 22 Mar 2005 09:32:45 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 59031 invoked by uid 500); 22 Mar 2005 09:32:45 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 59018 invoked by uid 99); 22 Mar 2005 09:32:45 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Tue, 22 Mar 2005 01:32:44 -0800 Received: (qmail 10326 invoked by uid 65534); 22 Mar 2005 09:32:43 -0000 Message-ID: <20050322093243.10325.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: svnmailer-1.0.0-dev Date: Tue, 22 Mar 2005 09:32:43 -0000 Subject: svn commit: r158585 - directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/service directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/store directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/store/operations To: commits@directory.apache.org From: erodriguez@apache.org X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: erodriguez Date: Tue Mar 22 01:32:41 2005 New Revision: 158585 URL: http://svn.apache.org/viewcvs?view=3Drev&rev=3D158585 Log: Refactored the Kerberos store operations to use the Command pattern. Added: directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/sto= re/ContextOperation.java directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/sto= re/PrincipalStoreImpl.java directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/sto= re/operations/ directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/sto= re/operations/GetPrincipal.java Removed: directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/sto= re/ChangePasswordActionImpl.java directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/sto= re/LookupPrincipalActionImpl.java directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/sto= re/PasswordStore.java directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/sto= re/SearchBaseFactory.java Modified: directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/ser= vice/KerberosService.java directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/sto= re/PrincipalStore.java directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/sto= re/SearchBaseNormalizer.java Modified: directory/shared/kerberos/trunk/common/src/java/org/apache/kerber= os/service/KerberosService.java URL: http://svn.apache.org/viewcvs/directory/shared/kerberos/trunk/common/s= rc/java/org/apache/kerberos/service/KerberosService.java?view=3Ddiff&r1=3D1= 58584&r2=3D158585 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/ser= vice/KerberosService.java (original) +++ directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/ser= vice/KerberosService.java Tue Mar 22 01:32:41 2005 @@ -48,6 +48,8 @@ import org.apache.kerberos.replay.InMemoryReplayCache; import org.apache.kerberos.replay.ReplayCache; import org.apache.kerberos.store.PrincipalStore; +import org.apache.kerberos.store.PrincipalStoreEntry; +import org.apache.kerberos.store.operations.GetPrincipal; =20 =20 public class KerberosService @@ -70,20 +72,60 @@ checksumEngines.put( ChecksumType.SHA1, new Sha1Checksum() ); } =20 - public EncryptionKey getKeyForPrincipal( KerberosPrincipal principal ) + public EncryptionKey getClientKey( KerberosPrincipal clientPrincipal ) + throws KerberosException { - EncryptionKey key =3D null; - - try - { - key =3D store.getEntry( principal ).getEncryptionKey(); - } - catch (Exception e) - { - e.printStackTrace(); - } - - return key; + return getKey( clientPrincipal, ErrorType.KDC_ERR_C_PRINCIPAL_UNKN= OWN ); + } + =20 + public EncryptionKey getServerKey( KerberosPrincipal serverPrincipal ) + throws KerberosException + { + return getKey( serverPrincipal, ErrorType.KDC_ERR_S_PRINCIPAL_UNKN= OWN ); + } + =20 + private EncryptionKey getKey( KerberosPrincipal principal, ErrorType e= rrorType ) + throws KerberosException + { + PrincipalStoreEntry entry =3D null; + =09 + try + { + entry =3D (PrincipalStoreEntry)store.execute( new GetPrincipal= ( principal ) ); + } + catch (Exception e) + { + throw new KerberosException( errorType ); + } + =20 + if ( entry =3D=3D null || entry.getEncryptionKey() =3D=3D null ) + { + throw new KerberosException( errorType ); + } + =20 + return entry.getEncryptionKey(); + } + =20 + public PrincipalStoreEntry getEntryForClient( KerberosPrincipal client= Principal ) + throws KerberosException + { + PrincipalStoreEntry entry =3D null; + =09 + try + { + entry =3D (PrincipalStoreEntry)store.execute( new GetPrincipal= ( clientPrincipal ) ); + } + catch (Exception e) + { + throw new KerberosException( ErrorType.KDC_ERR_C_PRINCIPAL_UNK= NOWN ); + } + =20 + if ( entry =3D=3D null ) + { + throw new KerberosException( ErrorType.KDC_ERR_C_PRINCIPAL_UNK= NOWN ); + } + =20 + return entry; } =20 protected EncryptionType getBestEncryptionType( EncryptionType[] reque= stedTypes ) @@ -144,7 +186,7 @@ } else { - serverKey =3D getKeyForPrincipal( serverPrincipal ); + serverKey =3D getServerKey( serverPrincipal ); } =20 if ( serverKey =3D=3D null ) Added: directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/= store/ContextOperation.java URL: http://svn.apache.org/viewcvs/directory/shared/kerberos/trunk/common/s= rc/java/org/apache/kerberos/store/ContextOperation.java?view=3Dauto&rev=3D1= 58585 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/sto= re/ContextOperation.java (added) +++ directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/sto= re/ContextOperation.java Tue Mar 22 01:32:41 2005 @@ -0,0 +1,30 @@ +/* + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli= ed. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.kerberos.store; + +import java.io.Serializable; + +import javax.naming.Name; +import javax.naming.directory.DirContext; + + +public interface ContextOperation extends Serializable +{ + public Object execute( DirContext ctx, Name searchBaseDn ) throws Exce= ption; +} + Modified: directory/shared/kerberos/trunk/common/src/java/org/apache/kerber= os/store/PrincipalStore.java URL: http://svn.apache.org/viewcvs/directory/shared/kerberos/trunk/common/s= rc/java/org/apache/kerberos/store/PrincipalStore.java?view=3Ddiff&r1=3D1585= 84&r2=3D158585 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/sto= re/PrincipalStore.java (original) +++ directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/sto= re/PrincipalStore.java Tue Mar 22 01:32:41 2005 @@ -14,14 +14,12 @@ * limitations under the License. * */ -package org.apache.kerberos.store; =20 -import javax.security.auth.kerberos.KerberosPrincipal; +package org.apache.kerberos.store; =20 -import org.apache.kerberos.exceptions.KerberosException; =20 -public interface PrincipalStore { - public void init(); - public PrincipalStoreEntry getEntry(KerberosPrincipal principal) throws K= erberosException; +public interface PrincipalStore +{ + public Object execute( ContextOperation operation ) throws Exception; } =20 Added: directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/= store/PrincipalStoreImpl.java URL: http://svn.apache.org/viewcvs/directory/shared/kerberos/trunk/common/s= rc/java/org/apache/kerberos/store/PrincipalStoreImpl.java?view=3Dauto&rev= =3D158585 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/sto= re/PrincipalStoreImpl.java (added) +++ directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/sto= re/PrincipalStoreImpl.java Tue Mar 22 01:32:41 2005 @@ -0,0 +1,45 @@ +/* + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli= ed. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.kerberos.store; + +import javax.naming.Name; +import javax.naming.ldap.LdapContext; + + +public class PrincipalStoreImpl implements PrincipalStore +{ + /** a handle on the provider context */ + protected LdapContext ctx; + /** the search base relative to provider URL to use for reading entrie= s */ + protected Name searchBaseDn; + =20 + /** + * Creates the action to be used against the embedded ApacheDS DIT. + */ + public PrincipalStoreImpl( LdapContext ctx, Name searchBaseDn ) + { + this.ctx =3D ctx; + this.searchBaseDn =3D searchBaseDn; + } + =20 + public Object execute( ContextOperation operation ) throws Exception + { + return operation.execute( ctx, searchBaseDn ); + } +} + Modified: directory/shared/kerberos/trunk/common/src/java/org/apache/kerber= os/store/SearchBaseNormalizer.java URL: http://svn.apache.org/viewcvs/directory/shared/kerberos/trunk/common/s= rc/java/org/apache/kerberos/store/SearchBaseNormalizer.java?view=3Ddiff&r1= =3D158584&r2=3D158585 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/sto= re/SearchBaseNormalizer.java (original) +++ directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/sto= re/SearchBaseNormalizer.java Tue Mar 22 01:32:41 2005 @@ -19,7 +19,7 @@ =20 import javax.naming.Name; import javax.naming.NamingException; -import javax.naming.ldap.LdapContext; +import javax.naming.directory.DirContext; =20 import org.apache.ldap.common.name.LdapName; import org.apache.ldap.common.util.NestableRuntimeException; @@ -27,7 +27,7 @@ =20 public class SearchBaseNormalizer { - public static Name getName( String baseDn, LdapContext ctx ) + public static Name getRelativeName( DirContext ctx, String baseDn ) { Name searchBaseDn =3D null; =20 Added: directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/= store/operations/GetPrincipal.java URL: http://svn.apache.org/viewcvs/directory/shared/kerberos/trunk/common/s= rc/java/org/apache/kerberos/store/operations/GetPrincipal.java?view=3Dauto&= rev=3D158585 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/sto= re/operations/GetPrincipal.java (added) +++ directory/shared/kerberos/trunk/common/src/java/org/apache/kerberos/sto= re/operations/GetPrincipal.java Tue Mar 22 01:32:41 2005 @@ -0,0 +1,129 @@ +/* + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impli= ed. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.kerberos.store.operations; + +import javax.naming.Name; +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttribute; +import javax.naming.directory.BasicAttributes; +import javax.naming.directory.DirContext; +import javax.naming.directory.SearchResult; +import javax.security.auth.kerberos.KerberosPrincipal; + +import org.apache.kerberos.messages.value.SamType; +import org.apache.kerberos.store.ContextOperation; +import org.apache.kerberos.store.KerberosAttribute; +import org.apache.kerberos.store.PrincipalStoreEntry; +import org.apache.kerberos.store.PrincipalStoreEntryModifier; + +/** + * Encapsulates the action of looking up a principal in an embedded Apache= DS DIT. + * + * @author Apache Directory Pr= oject + * @version $Rev$ + */ +public class GetPrincipal implements ContextOperation +{ + /** The name of the principal to get. */ + protected KerberosPrincipal principal; + =20 + /** + * Creates the action to be used against the embedded ApacheDS DIT. + */ + public GetPrincipal( KerberosPrincipal principal ) + { + this.principal =3D principal; + } + =20 + public Object execute( DirContext ctx, Name searchBaseDn ) + { + if ( principal =3D=3D null ) + { + return null; + } + =20 + String[] attrIDs =3D { KerberosAttribute.PRINCIPAL, KerberosAttribute.VE= RSION, + KerberosAttribute.TYPE, KerberosAttribute.KEY }; + + Attributes matchAttrs =3D new BasicAttributes( false ); // case-sensitive + matchAttrs.put( new BasicAttribute( KerberosAttribute.PRINCIPAL, princip= al.getName() ) ); + =09 + PrincipalStoreEntry entry =3D null; + =09 + try + { + // Search for objects that have those matching attributes + NamingEnumeration answer =3D ctx.search( searchBaseDn, matchAttrs, a= ttrIDs ); + =20 + if ( answer.hasMore() ) + { + SearchResult result =3D (SearchResult) answer.next(); + Attributes attrs =3D result.getAttributes(); + =20 + if ( attrs =3D=3D null ) + { + return null; + } + =20 + entry =3D getEntry( attrs ); + } + } + catch (NamingException e) + { + e.printStackTrace(); + return null; + } + =09 + return entry; + } + =20 + /** + * Marshals an a PrincipalStoreEntry from an Attributes object. + * + * @param attrs the attributes of the Kerberos principal + * @return the entry for the principal + * @throws NamingException if there are any access problems + */ + private PrincipalStoreEntry getEntry( Attributes attrs ) throws Naming= Exception + { + PrincipalStoreEntryModifier modifier =3D new PrincipalStoreEntryMo= difier(); + + String principal =3D ( String ) attrs.get( KerberosAttribute.PRINC= IPAL ).get(); + String encryptionType =3D ( String ) attrs.get( KerberosAttribute.= TYPE ).get(); + String keyVersionNumber =3D ( String ) attrs.get( KerberosAttribut= e=2EVERSION ).get(); + + if ( attrs.get( "apacheSamType" ) !=3D null ) + { + String samType =3D ( String ) attrs.get( "apacheSamType" ).get= (); + + modifier.setSamType( SamType.getTypeByOrdinal( Integer.parseIn= t( samType ) ) ); + } + + byte[] keyBytes =3D (byte[]) attrs.get( KerberosAttribute.KEY ).ge= t(); + + modifier.setPrincipal( new KerberosPrincipal( principal ) ); + modifier.setEncryptionType( Integer.parseInt( encryptionType ) ); + modifier.setKeyVersionNumber( Integer.parseInt( keyVersionNumber )= ); + modifier.setKey( keyBytes ); + + return modifier.getEntry(); + } +} +