01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19:
20: package org.apache.geronimo.security.deployment;
21:
22: import java.util.Map;
23: import java.util.HashMap;
24: import java.util.Set;
25: import java.util.Iterator;
26: import java.lang.reflect.Constructor;
27: import java.lang.reflect.InvocationTargetException;
28:
29: import org.apache.geronimo.deployment.service.XmlAttributeBuilder;
30: import org.apache.geronimo.deployment.service.XmlReferenceBuilder;
31: import org.apache.geronimo.common.DeploymentException;
32: import org.apache.geronimo.xbeans.geronimo.credentialstore.CredentialStoreDocument;
33: import org.apache.geronimo.xbeans.geronimo.credentialstore.CredentialStoreType;
34: import org.apache.geronimo.xbeans.geronimo.credentialstore.RealmType;
35: import org.apache.geronimo.xbeans.geronimo.credentialstore.SubjectType;
36: import org.apache.geronimo.xbeans.geronimo.credentialstore.CredentialType;
37: import org.apache.geronimo.security.credentialstore.SingleCallbackHandler;
38: import org.apache.geronimo.security.jaas.JaasLoginModuleUse;
39: import org.apache.geronimo.gbean.GBeanInfo;
40: import org.apache.geronimo.gbean.GReferenceInfo;
41: import org.apache.geronimo.gbean.GBeanInfoBuilder;
42: import org.apache.geronimo.kernel.Kernel;
43: import org.apache.xmlbeans.XmlObject;
44:
45: /**
46: * @version $Rev: 545781 $ $Date: 2007-06-09 10:44:02 -0700 (Sat, 09 Jun 2007) $
47: */
48: public class CredentialStoreBuilder implements XmlAttributeBuilder {
49:
50: private static final String NAMESPACE = CredentialStoreDocument.type
51: .getDocumentElementName().getNamespaceURI();
52:
53: public String getNamespace() {
54: return NAMESPACE;
55: }
56:
57: public Object getValue(XmlObject xmlObject, String type,
58: ClassLoader cl) throws DeploymentException {
59: Map<String, Map<String, Map<String, String>>> credentialStore = new HashMap<String, Map<String, Map<String, String>>>();
60: CredentialStoreType cst = (CredentialStoreType) xmlObject
61: .copy().changeType(CredentialStoreType.type);
62: for (RealmType realmType : cst.getRealmArray()) {
63: String realmName = realmType.getName().trim();
64: Map<String, Map<String, String>> realm = new HashMap<String, Map<String, String>>();
65: credentialStore.put(realmName, realm);
66: for (SubjectType subjectType : realmType.getSubjectArray()) {
67: String id = subjectType.getId().trim();
68: Map<String, String> subject = new HashMap<String, String>();
69: realm.put(id, subject);
70: for (CredentialType credentialType : subjectType
71: .getCredentialArray()) {
72: String handlerType = credentialType.getType()
73: .trim();
74: String value = credentialType.getValue().trim();
75: subject.put(handlerType, value);
76: }
77:
78: }
79: }
80: return credentialStore;
81: }
82:
83: public static final GBeanInfo GBEAN_INFO;
84:
85: static {
86: GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(
87: CredentialStoreBuilder.class, "XmlAttributeBuilder");
88: GBEAN_INFO = infoBuilder.getBeanInfo();
89: }
90:
91: public static GBeanInfo getGBeanInfo() {
92: return GBEAN_INFO;
93: }
94: }
|