001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 *
019 */
020 package org.apache.directory.server.kerberos.shared.messages.value;
021
022
023 import javax.security.auth.kerberos.KerberosPrincipal;
024
025
026 /**
027 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
028 * @version $Rev: 587146 $, $Date: 2007-10-22 19:28:37 +0300 (Mon, 22 Oct 2007) $
029 */
030 public class KerberosPrincipalModifier
031 {
032 private static final String REALM_SEPARATOR = "@";
033
034 PrincipalName nameComponent;
035 String realm;
036
037
038 /**
039 * Returns the {@link KerberosPrincipal}.
040 *
041 * @return The {@link KerberosPrincipal}.
042 */
043 public KerberosPrincipal getKerberosPrincipal()
044 {
045 if ( nameComponent != null )
046 {
047 StringBuffer sb = new StringBuffer();
048 sb.append( nameComponent.getNameString() );
049
050 if ( realm != null )
051 {
052 sb.append( REALM_SEPARATOR );
053 sb.append( realm );
054 }
055
056 return new KerberosPrincipal( sb.toString(), nameComponent.getNameType().getOrdinal() );
057 }
058
059 return null;
060 }
061
062
063 /**
064 * Sets the {@link PrincipalName}.
065 *
066 * @param principalName
067 */
068 public void setPrincipalName( PrincipalName principalName )
069 {
070 nameComponent = principalName;
071 }
072
073
074 /**
075 * Sets the realm.
076 *
077 * @param realm
078 */
079 public void setRealm( String realm )
080 {
081 this.realm = realm;
082 }
083 }