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 021package org.apache.directory.ldap.client.api; 022 023 024import java.util.ArrayList; 025import java.util.Arrays; 026import java.util.List; 027 028import org.apache.directory.shared.ldap.model.constants.SaslQoP; 029import org.apache.directory.shared.ldap.model.constants.SaslSecurityStrength; 030import org.apache.directory.shared.ldap.model.message.Control; 031import org.apache.directory.shared.util.StringConstants; 032import org.apache.directory.shared.util.Strings; 033 034 035/** 036 * Holds the data required to complete the SASL operation 037 * 038 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 039 */ 040public abstract class SaslRequest 041{ 042 /** The mechanism used to decode user identity */ 043 protected String saslMechanism; 044 045 /** The list of controls */ 046 protected List<Control> controls = new ArrayList<Control>(); 047 048 /** The username */ 049 protected String username; 050 051 /** The credentials */ 052 protected byte[] credentials; 053 054 /** The realm name on the server */ 055 protected String realmName; 056 057 /** The authorization ID of the entity */ 058 protected String authorizationId; 059 060 /** The quality of protection */ 061 protected SaslQoP qualityOfProtection; 062 063 /** The security strength */ 064 protected SaslSecurityStrength securityStrength; 065 066 /** Require mutual authentication */ 067 protected boolean mutualAuthentication = false; 068 069 070 /** 071 * Creates a new instance of SaslRequest. 072 * 073 * @param saslMechanism 074 * the SASL mechanism 075 */ 076 protected SaslRequest( String saslMechanism ) 077 { 078 this.saslMechanism = saslMechanism; 079 } 080 081 082 /** 083 * Adds the given controls. 084 * 085 * @param controls the controls 086 */ 087 public void addAllControls( Control[] controls ) 088 { 089 this.controls.addAll( Arrays.asList( controls ) ); 090 } 091 092 093 /** 094 * Adds the given control. 095 * 096 * @param control the control 097 */ 098 public void addControl( Control control ) 099 { 100 this.controls.add( control ); 101 } 102 103 104 /** 105 * Gets the authorization ID. 106 * 107 * @return the authorization ID 108 */ 109 public String getAuthorizationId() 110 { 111 return authorizationId; 112 } 113 114 115 /** 116 * Gets the controls. 117 * 118 * @return the controls 119 */ 120 public Control[] getControls() 121 { 122 return controls.toArray( new Control[0] ); 123 } 124 125 126 /** 127 * Gets the crendentials 128 * 129 * @return the credentials 130 */ 131 public byte[] getCredentials() 132 { 133 if ( credentials != null ) 134 { 135 return credentials; 136 } 137 else 138 { 139 return StringConstants.EMPTY_BYTES; 140 } 141 } 142 143 144 /** 145 * Gets the quality of protection. 146 * 147 * @return the quality of protection 148 */ 149 public SaslQoP getQualityOfProtection() 150 { 151 return qualityOfProtection; 152 } 153 154 155 /** 156 * Gets realm name. 157 * 158 * @return the realm name 159 */ 160 public String getRealmName() 161 { 162 return realmName; 163 } 164 165 166 /** 167 * Gets the SASL mechanism. 168 * 169 * @return the SASL mechanism 170 */ 171 public String getSaslMechanism() 172 { 173 return saslMechanism; 174 } 175 176 177 /** 178 * Gets the security strength. 179 * 180 * @return the security strength 181 */ 182 public SaslSecurityStrength getSecurityStrength() 183 { 184 return securityStrength; 185 } 186 187 188 /** 189 * Gets the username. 190 * 191 * @return the username 192 */ 193 public String getUsername() 194 { 195 return username; 196 } 197 198 199 /** 200 * Indicates if mutual authentication is required. 201 * 202 * @return the flag indicating if mutual authentication is required 203 */ 204 public boolean isMutualAuthentication() 205 { 206 return mutualAuthentication; 207 } 208 209 210 /** 211 * Sets the Authorization ID 212 * 213 * @param authorizationId The authorization ID 214 */ 215 public void setAuthorizationId( String authorizationId ) 216 { 217 this.authorizationId = authorizationId; 218 } 219 220 221 /** 222 * Sets the credentials. 223 * 224 * @param credentials the credentials 225 */ 226 public void setCredentials( byte[] credentials ) 227 { 228 this.credentials = credentials; 229 } 230 231 232 /** 233 * Sets the credentials. 234 * 235 * @param credentials the credentials 236 */ 237 public void setCredentials( String credentials ) 238 { 239 this.credentials = Strings.getBytesUtf8( credentials ); 240 } 241 242 243 /** 244 * Sets the flag indicating if mutual authentication is required. 245 * 246 * @param mutualAuthentication the flag indicating if mutual authentication is required 247 */ 248 public void setMutualAuthentication( boolean mutualAuthentication ) 249 { 250 this.mutualAuthentication = mutualAuthentication; 251 } 252 253 254 /** 255 * Sets the quality of protection. 256 * 257 * @param qualityOfProtection the quality of protection 258 */ 259 public void setQualityOfProtection( SaslQoP qualityOfProtection ) 260 { 261 this.qualityOfProtection = qualityOfProtection; 262 } 263 264 265 /** 266 * Sets the realm name. 267 * 268 * @param realmName The realm name 269 */ 270 protected void setRealmName( String realmName ) 271 { 272 this.realmName = realmName; 273 } 274 275 276 /** 277 * Sets the SASL mechanism 278 * 279 * @param saslMechanism the SASL mechanism 280 */ 281 protected void setSaslMechanism( String saslMechanism ) 282 { 283 this.saslMechanism = saslMechanism; 284 } 285 286 287 /** 288 * Sets the security strength. 289 * 290 * @param securityStrength the security strength 291 */ 292 public void setSecurityStrength( SaslSecurityStrength securityStrength ) 293 { 294 this.securityStrength = securityStrength; 295 } 296 297 298 /** 299 * Sets the username. 300 * 301 * @param username the username 302 */ 303 public void setUsername( String username ) 304 { 305 this.username = username; 306 } 307}