1 /* 2 * Copyright [2007] [University Corporation for Advanced Internet Development, Inc.] 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.opensaml.saml2.binding.artifact; 18 19 import java.util.Map; 20 21 import org.opensaml.xml.util.Base64; 22 import org.opensaml.xml.util.LazyMap; 23 24 /** 25 * Factory used to construct SAML 2 artifact builders. 26 */ 27 public class SAML2ArtifactBuilderFactory { 28 29 /** Registered artifact builders. */ 30 private Map<String, SAML2ArtifactBuilder> artifactBuilders; 31 32 /** Constructor. */ 33 public SAML2ArtifactBuilderFactory() { 34 artifactBuilders = new LazyMap<String, SAML2ArtifactBuilder>(); 35 artifactBuilders.put(new String(SAML2ArtifactType0004.TYPE_CODE), new SAML2ArtifactType0004Builder()); 36 } 37 38 /** 39 * Gets the currently registered artifact builders. 40 * 41 * @return currently registered artifact builders 42 */ 43 public Map<String, SAML2ArtifactBuilder> getArtifactBuilders() { 44 return artifactBuilders; 45 } 46 47 /** 48 * Gets the artifact builder for the given type. 49 * 50 * @param type type of artifact to be built 51 * 52 * @return artifact builder for the given type 53 */ 54 public SAML2ArtifactBuilder getArtifactBuilder(byte[] type) { 55 return artifactBuilders.get(new String(type)); 56 } 57 58 /** 59 * Convenience method for getting an artifact builder and parsing the given Base64 encoded artifact with it. 60 * 61 * @param base64Artifact Base64 encoded artifact to parse 62 * 63 * @return constructed artifact 64 */ 65 public AbstractSAML2Artifact buildArtifact(String base64Artifact){ 66 return buildArtifact(Base64.decode(base64Artifact)); 67 } 68 69 /** 70 * convenience method for getting an artifact builder and parsing the given artifact with it. 71 * 72 * @param artifact artifact to parse 73 * 74 * @return constructed artifact 75 */ 76 public AbstractSAML2Artifact buildArtifact(byte[] artifact) { 77 if(artifact == null){ 78 return null; 79 } 80 81 byte[] type = new byte[2]; 82 type[0] = artifact[0]; 83 type[1] = artifact[1]; 84 85 SAML2ArtifactBuilder<?> artifactBuilder = getArtifactBuilder(type); 86 return artifactBuilder.buildArtifact(artifact); 87 } 88 }