1 /* 2 * Copyright 2004,2005 The Apache Software Foundation. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package org.apache.rampart.policy.model; 18 19 import org.apache.neethi.Assertion; 20 import org.apache.neethi.Constants; 21 import org.apache.neethi.PolicyComponent; 22 23 import javax.xml.namespace.QName; 24 import javax.xml.stream.XMLStreamException; 25 import javax.xml.stream.XMLStreamWriter; 26 27 /** 28 * Rampart policy model bean to capture Rampart configuration assertion info. 29 * 30 * Example: 31 * 32 * <pre> 33 * <ramp:RampartConfig xmlns:ramp="http://ws.apache.org/rampart/policy"> 34 * <ramp:user>alice</ramp:user> 35 * <ramp:encryptionUser>bob</ramp:encryptionUser> 36 * <ramp:passwordCallbackClass>org.apache.axis2.security.PWCallback</ramp:passwordCallbackClass> 37 * <ramp:policyValidatorCbClass>org.apache.axis2.security.ramp:PolicyValidatorCallbackHandler</ramp:policyValidatorCbClass> 38 * <ramp:timestampPrecisionInMilliseconds>true</timestampPrecisionInMilliseconds> 39 * <ramp:timestampTTL>300</ramp:timestampTTL> 40 * <ramp:timestampMaxSkew>0</ramp:timestampMaxSkew> 41 * <ramp:tokenStoreClass>org.apache.rahas.StorageImpl</ramp:tokenStoreClass> 42 * 43 * <ramp:signatureCrypto> 44 * <ramp:crypto provider="org.apache.ws.security.components.crypto.Merlin"> 45 * <ramp:property name="keystoreType">JKS</ramp:property> 46 * <ramp:property name="keystoreFile">/path/to/file.jks</ramp:property> 47 * <ramp:property name="keystorePassword">password</ramp:property> 48 * </ramp:crypto> 49 * </ramp:signatureCrypto> 50 * 51 * <ramp:tokenIssuerPolicy> 52 * <wsp:Policy> 53 * .... 54 * .... 55 * </wsp:Policy> 56 * </ramp:tokenIssuerPolicy> 57 * </ramp:RampartConfig> 58 * 59 * </pre> 60 * 61 */ 62 public class RampartConfig implements Assertion { 63 64 public static final boolean DEFAULT_TIMESTAMP_PRECISION_IN_MS = true; 65 66 public static final int DEFAULT_TIMESTAMP_TTL = 300; 67 68 public static final int DEFAULT_TIMESTAMP_MAX_SKEW = 300; 69 70 public final static String NS = "http://ws.apache.org/rampart/policy"; 71 72 public final static String PREFIX = "rampart"; 73 74 public final static String RAMPART_CONFIG_LN = "RampartConfig"; 75 76 public final static String USER_LN = "user"; 77 78 public final static String USER_CERT_ALIAS_LN = "userCertAlias"; 79 80 public final static String ENCRYPTION_USER_LN = "encryptionUser"; 81 82 public final static String STS_ALIAS_LN = "stsAlias"; 83 84 public final static String PW_CB_CLASS_LN = "passwordCallbackClass"; 85 86 public final static String POLICY_VALIDATOR_CB_CLASS_LN = "policyValidatorCbClass"; 87 88 public final static String SIG_CRYPTO_LN = "signatureCrypto"; 89 90 public final static String ENCR_CRYPTO_LN = "encryptionCrypto"; 91 92 public final static String DEC_CRYPTO_LN = "decryptionCrypto"; 93 94 public final static String STS_CRYPTO_LN = "stsCrypto"; 95 96 public final static String TS_PRECISION_IN_MS_LN = "timestampPrecisionInMilliseconds"; 97 98 public final static String TS_TTL_LN = "timestampTTL"; 99 100 public final static String TS_MAX_SKEW_LN = "timestampMaxSkew"; 101 102 public final static String TOKEN_STORE_CLASS_LN = "tokenStoreClass"; 103 104 public final static String OPTIMISE_PARTS = "optimizeParts"; 105 106 public final static String SSL_CONFIG = "sslConfig"; 107 108 private String user; 109 110 private String userCertAlias; 111 112 private String encryptionUser; 113 114 private String stsAlias; 115 116 private String pwCbClass; 117 118 private String policyValidatorCbClass; 119 120 private CryptoConfig sigCryptoConfig; 121 122 private CryptoConfig encrCryptoConfig; 123 124 private CryptoConfig decCryptoConfig; 125 126 private CryptoConfig stsCryptoConfig; 127 128 private String timestampPrecisionInMilliseconds = Boolean.toString(DEFAULT_TIMESTAMP_PRECISION_IN_MS); 129 130 private String timestampTTL = Integer.toString(DEFAULT_TIMESTAMP_TTL); 131 132 private String timestampMaxSkew = Integer.toString(DEFAULT_TIMESTAMP_MAX_SKEW); 133 134 private OptimizePartsConfig optimizeParts; 135 136 private String tokenStoreClass; 137 138 private SSLConfig sslConfig; 139 140 public SSLConfig getSSLConfig() { 141 return sslConfig; 142 } 143 144 public void setSSLConfig(SSLConfig sslConfig) { 145 this.sslConfig = sslConfig; 146 } 147 148 149 /** 150 * @return Returns the tokenStoreClass. 151 */ 152 public String getTokenStoreClass() { 153 return tokenStoreClass; 154 } 155 156 /** 157 * @param tokenStoreClass 158 * The tokenStoreClass to set. 159 */ 160 public void setTokenStoreClass(String tokenStoreClass) { 161 this.tokenStoreClass = tokenStoreClass; 162 } 163 164 public CryptoConfig getDecCryptoConfig() { 165 return decCryptoConfig; 166 } 167 168 public void setDecCryptoConfig(CryptoConfig decCrypto) { 169 this.decCryptoConfig = decCrypto; 170 } 171 172 public CryptoConfig getEncrCryptoConfig() { 173 return encrCryptoConfig; 174 } 175 176 public void setEncrCryptoConfig(CryptoConfig encrCrypto) { 177 this.encrCryptoConfig = encrCrypto; 178 } 179 180 public String getEncryptionUser() { 181 return encryptionUser; 182 } 183 184 public void setEncryptionUser(String encryptionUser) { 185 this.encryptionUser = encryptionUser; 186 } 187 188 public String getPwCbClass() { 189 return pwCbClass; 190 } 191 192 public void setPwCbClass(String pwCbClass) { 193 this.pwCbClass = pwCbClass; 194 } 195 196 public String getPolicyValidatorCbClass() { 197 return this.policyValidatorCbClass; 198 } 199 200 public void setPolicyValidatorCbClass(String policyValidatorCbClass) { 201 this.policyValidatorCbClass = policyValidatorCbClass; 202 } 203 204 public CryptoConfig getSigCryptoConfig() { 205 return sigCryptoConfig; 206 } 207 208 public void setSigCryptoConfig(CryptoConfig sigCryptoConfig) { 209 this.sigCryptoConfig = sigCryptoConfig; 210 } 211 212 public String getUser() { 213 return user; 214 } 215 216 public void setUser(String user) { 217 this.user = user; 218 } 219 220 public String getUserCertAlias() { 221 return userCertAlias; 222 } 223 224 public void setUserCertAlias(String userCertAlias) { 225 this.userCertAlias = userCertAlias; 226 } 227 228 public QName getName() { 229 return new QName(NS, RAMPART_CONFIG_LN); 230 } 231 232 public boolean isOptional() { 233 // TODO TODO 234 throw new UnsupportedOperationException("TODO"); 235 } 236 237 public PolicyComponent normalize() { 238 // TODO TODO 239 throw new UnsupportedOperationException("TODO"); 240 } 241 242 public void serialize(XMLStreamWriter writer) throws XMLStreamException { 243 String prefix = writer.getPrefix(NS); 244 245 if (prefix == null) { 246 prefix = PREFIX; 247 writer.setPrefix(PREFIX, NS); 248 } 249 250 writer.writeStartElement(PREFIX, RAMPART_CONFIG_LN, NS); 251 writer.writeNamespace(prefix, NS); 252 253 if (getUser() != null) { 254 writer.writeStartElement(NS, USER_LN); 255 writer.writeCharacters(getUser()); 256 writer.writeEndElement(); 257 } 258 259 if (getUserCertAlias() != null) { 260 writer.writeStartElement(NS, USER_CERT_ALIAS_LN); 261 writer.writeCharacters(getUserCertAlias()); 262 writer.writeEndElement(); 263 } 264 265 if (getEncryptionUser() != null) { 266 writer.writeStartElement(NS, ENCRYPTION_USER_LN); 267 writer.writeCharacters(getEncryptionUser()); 268 writer.writeEndElement(); 269 } 270 271 if (getStsAlias() != null ) { 272 writer.writeStartElement(NS, STS_ALIAS_LN); 273 writer.writeCharacters(getStsAlias()); 274 writer.writeEndElement(); 275 } 276 277 if (getPwCbClass() != null) { 278 writer.writeStartElement(NS, PW_CB_CLASS_LN); 279 writer.writeCharacters(getPwCbClass()); 280 writer.writeEndElement(); 281 } 282 283 if (getPolicyValidatorCbClass() != null) { 284 writer.writeStartElement(NS, POLICY_VALIDATOR_CB_CLASS_LN); 285 writer.writeCharacters(getPolicyValidatorCbClass()); 286 writer.writeEndElement(); 287 } 288 289 if (getTimestampPrecisionInMilliseconds() != null) { 290 writer.writeStartElement(NS, TS_PRECISION_IN_MS_LN); 291 writer.writeCharacters(getTimestampPrecisionInMilliseconds()); 292 writer.writeEndElement(); 293 } 294 295 if (getTimestampTTL() != null) { 296 writer.writeStartElement(NS, TS_TTL_LN); 297 writer.writeCharacters(getTimestampTTL()); 298 writer.writeEndElement(); 299 } 300 301 if (getTimestampMaxSkew() != null) { 302 writer.writeStartElement(NS, TS_MAX_SKEW_LN); 303 writer.writeCharacters(getTimestampMaxSkew()); 304 writer.writeEndElement(); 305 } 306 307 if (getTokenStoreClass() != null) { 308 writer.writeStartElement(NS, TOKEN_STORE_CLASS_LN); 309 writer.writeCharacters(getTokenStoreClass()); 310 writer.writeEndElement(); 311 } 312 313 if (encrCryptoConfig != null) { 314 writer.writeStartElement(NS, ENCR_CRYPTO_LN); 315 encrCryptoConfig.serialize(writer); 316 writer.writeEndElement(); 317 318 } 319 320 if (decCryptoConfig != null) { 321 writer.writeStartElement(NS, DEC_CRYPTO_LN); 322 decCryptoConfig.serialize(writer); 323 writer.writeEndElement(); 324 } 325 326 if(stsCryptoConfig != null) { 327 writer.writeStartElement(NS, STS_CRYPTO_LN); 328 stsCryptoConfig.serialize(writer); 329 writer.writeEndElement(); 330 } 331 332 if (sigCryptoConfig != null) { 333 writer.writeStartElement(NS, SIG_CRYPTO_LN); 334 sigCryptoConfig.serialize(writer); 335 writer.writeEndElement(); 336 } 337 338 writer.writeEndElement(); 339 340 } 341 342 public boolean equal(PolicyComponent policyComponent) { 343 throw new UnsupportedOperationException("TODO"); 344 } 345 346 public short getType() { 347 return Constants.TYPE_ASSERTION; 348 } 349 350 public String getTimestampPrecisionInMilliseconds() { 351 return timestampPrecisionInMilliseconds; 352 } 353 354 public void setTimestampPrecisionInMilliseconds(String timestampPrecisionInMilliseconds) { 355 this.timestampPrecisionInMilliseconds = timestampPrecisionInMilliseconds; 356 } 357 358 /** 359 * @return Returns the timestampTTL. 360 */ 361 public String getTimestampTTL() { 362 return timestampTTL; 363 } 364 365 /** 366 * @param timestampTTL 367 * The timestampTTL to set. 368 */ 369 public void setTimestampTTL(String timestampTTL) { 370 this.timestampTTL = timestampTTL; 371 } 372 373 /** 374 * @return Returns the timestampMaxSkew. 375 */ 376 public String getTimestampMaxSkew() { 377 return timestampMaxSkew; 378 } 379 380 /** 381 * @param timestampMaxSkew 382 * The timestampMaxSkew to set. 383 */ 384 public void setTimestampMaxSkew(String timestampMaxSkew) { 385 this.timestampMaxSkew = timestampMaxSkew; 386 } 387 388 public OptimizePartsConfig getOptimizeParts() { 389 return optimizeParts; 390 } 391 392 public void setOptimizeParts(OptimizePartsConfig optimizeParts) { 393 this.optimizeParts = optimizeParts; 394 } 395 396 public String getStsAlias() { 397 return stsAlias; 398 } 399 400 public void setStsAlias(String stsAlias) { 401 this.stsAlias = stsAlias; 402 } 403 404 public CryptoConfig getStsCryptoConfig() { 405 return stsCryptoConfig; 406 } 407 408 public void setStsCryptoConfig(CryptoConfig stsCryptoConfig) { 409 this.stsCryptoConfig = stsCryptoConfig; 410 } 411 412 }