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    
021    package org.apache.geronimo.security.deployment;
022    
023    import java.util.Map;
024    import java.util.HashMap;
025    import java.util.Set;
026    import java.util.Iterator;
027    import java.lang.reflect.Constructor;
028    import java.lang.reflect.InvocationTargetException;
029    
030    import org.apache.geronimo.deployment.service.XmlAttributeBuilder;
031    import org.apache.geronimo.deployment.service.XmlReferenceBuilder;
032    import org.apache.geronimo.common.DeploymentException;
033    import org.apache.geronimo.xbeans.geronimo.credentialstore.CredentialStoreDocument;
034    import org.apache.geronimo.xbeans.geronimo.credentialstore.CredentialStoreType;
035    import org.apache.geronimo.xbeans.geronimo.credentialstore.RealmType;
036    import org.apache.geronimo.xbeans.geronimo.credentialstore.SubjectType;
037    import org.apache.geronimo.xbeans.geronimo.credentialstore.CredentialType;
038    import org.apache.geronimo.security.credentialstore.SingleCallbackHandler;
039    import org.apache.geronimo.security.jaas.JaasLoginModuleUse;
040    import org.apache.geronimo.gbean.GBeanInfo;
041    import org.apache.geronimo.gbean.GReferenceInfo;
042    import org.apache.geronimo.gbean.GBeanInfoBuilder;
043    import org.apache.geronimo.kernel.Kernel;
044    import org.apache.xmlbeans.XmlObject;
045    
046    /**
047     * @version $Rev: 545781 $ $Date: 2007-06-09 13:44:02 -0400 (Sat, 09 Jun 2007) $
048     */
049    public class CredentialStoreBuilder implements XmlAttributeBuilder {
050    
051        private static final String NAMESPACE = CredentialStoreDocument.type.getDocumentElementName().getNamespaceURI();
052    
053        public String getNamespace() {
054            return NAMESPACE;
055        }
056    
057        public Object getValue(XmlObject xmlObject, String type, ClassLoader cl) throws DeploymentException {
058            Map<String, Map<String, Map<String, String>>> credentialStore = new HashMap<String, Map<String, Map<String, String>>>();
059            CredentialStoreType cst = (CredentialStoreType) xmlObject.copy().changeType(CredentialStoreType.type);
060            for (RealmType realmType: cst.getRealmArray()) {
061                String realmName = realmType.getName().trim();
062                Map<String, Map<String, String>> realm = new HashMap<String, Map<String, String>>();
063                credentialStore.put(realmName, realm);
064                for (SubjectType subjectType: realmType.getSubjectArray()) {
065                    String id = subjectType.getId().trim();
066                    Map<String, String> subject = new HashMap<String, String>();
067                    realm.put(id, subject);
068                    for (CredentialType credentialType: subjectType.getCredentialArray()) {
069                        String handlerType = credentialType.getType().trim();
070                        String value = credentialType.getValue().trim();
071                        subject.put(handlerType, value);
072                    }
073    
074                }
075            }
076            return credentialStore;
077        }
078    
079    
080        public static final GBeanInfo GBEAN_INFO;
081    
082        static {
083            GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(CredentialStoreBuilder.class, "XmlAttributeBuilder");
084            GBEAN_INFO = infoBuilder.getBeanInfo();
085        }
086    
087        public static GBeanInfo getGBeanInfo() {
088            return GBEAN_INFO;
089        }
090    }