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.kerberos.client; 021 022 023import java.net.InetAddress; 024import java.net.UnknownHostException; 025import java.util.ArrayList; 026import java.util.List; 027import java.util.Set; 028 029import org.apache.directory.shared.kerberos.codec.options.KdcOptions; 030import org.apache.directory.shared.kerberos.codec.types.EncryptionType; 031import org.apache.directory.shared.kerberos.components.HostAddress; 032 033 034public class TgtRequest 035{ 036 private String clientPrincipal;// cname 037 private String password; 038 private String realm; // realm 039 private String serverPrincipal;// sname, optional 040 041 private long startTime;// from 042 043 private long expiryTime;// till 044 045 private long renewTill;// rtime 046 047 private List<HostAddress> hostAddresses = new ArrayList<>(); 048 049 private KdcOptions options = new KdcOptions(); 050 051 private boolean preAuthEnabled = false; 052 053 /** the set of encryption types that the server replied */ 054 private Set<EncryptionType> eTypes; 055 056 057 public TgtRequest() 058 { 059 startTime = System.currentTimeMillis(); 060 expiryTime = startTime + ( 8 * 60 * 60 * 1000 ); 061 } 062 063 064 public void addHost( String hostNameOrIpAddress ) throws UnknownHostException 065 { 066 InetAddress address = InetAddress.getByName( hostNameOrIpAddress ); 067 hostAddresses.add( new HostAddress( address ) ); 068 } 069 070 071 public String getPassword() 072 { 073 return password; 074 } 075 076 077 public void setPassword( String password ) 078 { 079 this.password = password; 080 } 081 082 083 public String getClientPrincipal() 084 { 085 return clientPrincipal; 086 } 087 088 089 public void setClientPrincipal( String clientPrincipal ) 090 { 091 this.clientPrincipal = clientPrincipal; 092 realm = KdcClientUtil.extractRealm( clientPrincipal ); 093 } 094 095 096 public String getRealm() 097 { 098 return realm; 099 } 100 101 102 public String getServerPrincipal() 103 { 104 return serverPrincipal; 105 } 106 107 108 public void setServerPrincipal( String serverPrincipal ) 109 { 110 this.serverPrincipal = serverPrincipal; 111 } 112 113 114 public long getStartTime() 115 { 116 return startTime; 117 } 118 119 120 public void setStartTime( long startTime ) 121 { 122 this.startTime = startTime; 123 } 124 125 126 public long getExpiryTime() 127 { 128 return expiryTime; 129 } 130 131 132 public void setExpiryTime( long expiryTime ) 133 { 134 this.expiryTime = expiryTime; 135 } 136 137 138 public long getRenewTill() 139 { 140 return renewTill; 141 } 142 143 144 public void setRenewTill( long renewTill ) 145 { 146 this.renewTill = renewTill; 147 } 148 149 150 public List<HostAddress> getHostAddresses() 151 { 152 return hostAddresses; 153 } 154 155 156 public void setForwardable( boolean forwardable ) 157 { 158 setOrClear( KdcOptions.FORWARDABLE, forwardable ); 159 } 160 161 162 public void setProxiable( boolean proxiable ) 163 { 164 setOrClear( KdcOptions.PROXIABLE, proxiable ); 165 } 166 167 168 public void setAllowPostdate( boolean allowPostdate ) 169 { 170 setOrClear( KdcOptions.ALLOW_POSTDATE, allowPostdate ); 171 } 172 173 174 public void setPostdated( boolean postdated ) 175 { 176 setOrClear( KdcOptions.POSTDATED, postdated ); 177 } 178 179 180 public void setRenewableOk( boolean renewableOk ) 181 { 182 setOrClear( KdcOptions.RENEWABLE_OK, renewableOk ); 183 } 184 185 186 public void setRenewable( boolean renewable ) 187 { 188 setOrClear( KdcOptions.RENEWABLE, renewable ); 189 } 190 191 192 public KdcOptions getOptions() 193 { 194 return options; 195 } 196 197 198 public boolean isPreAuthEnabled() 199 { 200 return preAuthEnabled; 201 } 202 203 204 public void setPreAuthEnabled( boolean preAuthEnabled ) 205 { 206 this.preAuthEnabled = preAuthEnabled; 207 } 208 209 210 public String getSName() 211 { 212 return KdcClientUtil.extractName( serverPrincipal ); 213 } 214 215 216 public String getCName() 217 { 218 return KdcClientUtil.extractName( clientPrincipal ); 219 } 220 221 222 public Set<EncryptionType> getETypes() 223 { 224 return eTypes; 225 } 226 227 228 public void setETypes( Set<EncryptionType> eTypes ) 229 { 230 this.eTypes = eTypes; 231 } 232 233 234 private void setOrClear( int pos, boolean set ) 235 { 236 if ( set ) 237 { 238 options.setBit( pos ); 239 } 240 else 241 { 242 options.clearBit( pos ); 243 } 244 } 245}