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 */ 020package org.apache.directory.server.kerberos.kdc; 021 022 023import java.net.InetAddress; 024 025import org.apache.directory.server.kerberos.KerberosConfig; 026import org.apache.directory.server.kerberos.shared.crypto.encryption.CipherTextHandler; 027import org.apache.directory.server.kerberos.shared.replay.ReplayCache; 028import org.apache.directory.server.kerberos.shared.store.PrincipalStore; 029import org.apache.directory.shared.kerberos.codec.types.EncryptionType; 030import org.apache.directory.shared.kerberos.components.KdcReq; 031import org.apache.directory.shared.kerberos.messages.KerberosMessage; 032 033 034/** 035 * The context used to store the collected and computed data while processing a 036 * kerberos message. 037 * 038 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 039 */ 040public abstract class KdcContext 041{ 042 private static final long serialVersionUID = 6490030984626825108L; 043 044 /** The KDC server configuration */ 045 private KerberosConfig config; 046 private PrincipalStore store; 047 048 /** The request being processed */ 049 private KdcReq request; 050 051 /** The kerberos response */ 052 private KerberosMessage reply; 053 054 /** The client IP address */ 055 private InetAddress clientAddress; 056 private CipherTextHandler cipherTextHandler; 057 058 /** The encryption type */ 059 private EncryptionType encryptionType; 060 061 /** the replay cache */ 062 private ReplayCache replayCache; 063 064 /** 065 * @return Returns the config. 066 */ 067 public KerberosConfig getConfig() 068 { 069 return config; 070 } 071 072 073 /** 074 * @param config The config to set. 075 */ 076 public void setConfig( KerberosConfig config ) 077 { 078 this.config = config; 079 } 080 081 082 /** 083 * @return Returns the store. 084 */ 085 public PrincipalStore getStore() 086 { 087 return store; 088 } 089 090 091 /** 092 * @param store The store to set. 093 */ 094 public void setStore( PrincipalStore store ) 095 { 096 this.store = store; 097 } 098 099 100 /** 101 * @return Returns the request. 102 */ 103 public KdcReq getRequest() 104 { 105 return request; 106 } 107 108 109 /** 110 * @param request The request to set. 111 */ 112 public void setRequest( KdcReq request ) 113 { 114 this.request = request; 115 } 116 117 118 /** 119 * @return Returns the reply. 120 */ 121 public KerberosMessage getReply() 122 { 123 return reply; 124 } 125 126 127 /** 128 * @param reply The reply to set. 129 */ 130 public void setReply( KerberosMessage reply ) 131 { 132 this.reply = reply; 133 } 134 135 136 /** 137 * @return Returns the clientAddress. 138 */ 139 public InetAddress getClientAddress() 140 { 141 return clientAddress; 142 } 143 144 145 /** 146 * @param clientAddress The clientAddress to set. 147 */ 148 public void setClientAddress( InetAddress clientAddress ) 149 { 150 this.clientAddress = clientAddress; 151 } 152 153 154 /** 155 * @return Returns the {@link CipherTextHandler}. 156 */ 157 public CipherTextHandler getCipherTextHandler() 158 { 159 return cipherTextHandler; 160 } 161 162 163 /** 164 * @param cipherTextHandler The {@link CipherTextHandler} to set. 165 */ 166 public void setCipherTextHandler( CipherTextHandler cipherTextHandler ) 167 { 168 this.cipherTextHandler = cipherTextHandler; 169 } 170 171 172 /** 173 * Returns the encryption type to use for this session. 174 * 175 * @return The encryption type. 176 */ 177 public EncryptionType getEncryptionType() 178 { 179 return encryptionType; 180 } 181 182 183 /** 184 * Sets the encryption type to use for this session. 185 * 186 * @param encryptionType The encryption type to set. 187 */ 188 public void setEncryptionType( EncryptionType encryptionType ) 189 { 190 this.encryptionType = encryptionType; 191 } 192 193 194 /** 195 * @see Object#toString() 196 */ 197 public String toString() 198 { 199 StringBuilder sb = new StringBuilder(); 200 201 sb.append( "Req : " ).append( request.toString( " " ) ); 202 sb.append( "Client address : " ).append( clientAddress ); 203 204 if ( encryptionType != null ) 205 { 206 sb.append( '\n' ); 207 sb.append( "EncryptionType : " ).append( encryptionType ); 208 } 209 210 return sb.toString(); 211 } 212 213 214 /** 215 * sets the replay cache 216 * 217 * @param replayCache The Replay cache instance 218 */ 219 public void setReplayCache( ReplayCache replayCache ) 220 { 221 this.replayCache = replayCache; 222 } 223 224 225 /** 226 * @return the replay cache 227 */ 228 public ReplayCache getReplayCache() 229 { 230 return replayCache; 231 } 232}