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: package org.apache.geronimo.security.deployment;
021:
022: import java.io.File;
023: import java.net.URI;
024: import java.util.Collections;
025:
026: import junit.framework.TestCase;
027: import org.apache.geronimo.common.DeploymentException;
028: import org.apache.geronimo.deployment.DeploymentContext;
029: import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil;
030: import org.apache.geronimo.gbean.AbstractName;
031: import org.apache.geronimo.kernel.Jsr77Naming;
032: import org.apache.geronimo.kernel.config.ConfigurationModuleType;
033: import org.apache.geronimo.kernel.mock.MockConfigurationManager;
034: import org.apache.geronimo.kernel.repository.Artifact;
035: import org.apache.geronimo.kernel.repository.Environment;
036: import org.apache.xmlbeans.XmlCursor;
037: import org.apache.xmlbeans.XmlException;
038: import org.apache.xmlbeans.XmlObject;
039:
040: /**
041: * @version $Rev: 620870 $ $Date: 2008-02-12 09:24:48 -0800 (Tue, 12 Feb 2008) $
042: */
043: public class LoginConfigBuilderTest extends TestCase {
044: //2.0 namespace, with server-side
045: private static final String SAMPLE1 = " <lc:login-config xmlns:lc=\"http://geronimo.apache.org/xml/ns/loginconfig-2.0\">\n"
046: + " <lc:login-module control-flag=\"REQUIRED\" server-side=\"true\" wrap-principals=\"true\">\n"
047: + " <lc:login-domain-name>client-properties-realm</lc:login-domain-name>\n"
048: + " <lc:login-module-class>org.apache.geronimo.security.realm.providers.PropertiesFileLoginModule</lc:login-module-class>\n"
049: + " <lc:option name=\"usersURI\">var/security/users.properties</lc:option>\n"
050: + " <lc:option name=\"groupsURI\">var/security/groups.properties</lc:option>\n"
051: + " </lc:login-module>\n"
052: + " <lc:login-module control-flag=\"REQUIRED\" server-side=\"true\" wrap-principals=\"true\">\n"
053: + " <lc:login-domain-name>default</lc:login-domain-name>\n"
054: + " <lc:login-module-class>org.apache.geronimo.security.realm.providers.NamedUsernamePasswordCredentialLoginModule</lc:login-module-class>\n"
055: + " <lc:option name=\"org.apache.geronimo.jaas.NamedUsernamePasswordCredential.Name\">default</lc:option>\n"
056: + " </lc:login-module>\n"
057: + " </lc:login-config>";
058: //1.2 namespace, with server-side
059: private static final String SAMPLE2 = " <lc:login-config xmlns:lc=\"http://geronimo.apache.org/xml/ns/loginconfig-1.2\">\n"
060: + " <lc:login-module control-flag=\"REQUIRED\" server-side=\"true\" wrap-principals=\"true\">\n"
061: + " <lc:login-domain-name>client-properties-realm</lc:login-domain-name>\n"
062: + " <lc:login-module-class>org.apache.geronimo.security.realm.providers.PropertiesFileLoginModule</lc:login-module-class>\n"
063: + " <lc:option name=\"usersURI\">var/security/users.properties</lc:option>\n"
064: + " <lc:option name=\"groupsURI\">var/security/groups.properties</lc:option>\n"
065: + " </lc:login-module>\n"
066: + " <lc:login-module control-flag=\"REQUIRED\" server-side=\"true\" wrap-principals=\"true\">\n"
067: + " <lc:login-domain-name>default</lc:login-domain-name>\n"
068: + " <lc:login-module-class>org.apache.geronimo.security.realm.providers.NamedUsernamePasswordCredentialLoginModule</lc:login-module-class>\n"
069: + " <lc:option name=\"org.apache.geronimo.jaas.NamedUsernamePasswordCredential.Name\">default</lc:option>\n"
070: + " </lc:login-module>\n"
071: + " </lc:login-config>";
072: //2.0 namespace, without server-side
073: private static final String SAMPLE3 = " <lc:login-config xmlns:lc=\"http://geronimo.apache.org/xml/ns/loginconfig-2.0\">\n"
074: + " <lc:login-module control-flag=\"REQUIRED\" wrap-principals=\"true\">\n"
075: + " <lc:login-domain-name>client-properties-realm</lc:login-domain-name>\n"
076: + " <lc:login-module-class>org.apache.geronimo.security.realm.providers.PropertiesFileLoginModule</lc:login-module-class>\n"
077: + " <lc:option name=\"usersURI\">var/security/users.properties</lc:option>\n"
078: + " <lc:option name=\"groupsURI\">var/security/groups.properties</lc:option>\n"
079: + " </lc:login-module>\n"
080: + " <lc:login-module control-flag=\"REQUIRED\" wrap-principals=\"true\">\n"
081: + " <lc:login-domain-name>default</lc:login-domain-name>\n"
082: + " <lc:login-module-class>org.apache.geronimo.security.realm.providers.NamedUsernamePasswordCredentialLoginModule</lc:login-module-class>\n"
083: + " <lc:option name=\"org.apache.geronimo.jaas.NamedUsernamePasswordCredential.Name\">default</lc:option>\n"
084: + " </lc:login-module>\n"
085: + " </lc:login-config>";
086: //2.0 namespace, without server-side, with login-module-ref
087: private static final String SAMPLE4 = " <lc:login-config xmlns:lc=\"http://geronimo.apache.org/xml/ns/loginconfig-2.0\">\n"
088: + " <lc:login-module-ref control-flag=\"REQUIRED\" wrap-principals=\"true\">\n"
089: + " <lc:pattern><name xmlns='http://geronimo.apache.org/xml/ns/deployment-1.2'>client-properties-lm</name></lc:pattern>\n"
090: + " </lc:login-module-ref>\n"
091: + " <lc:login-module control-flag=\"REQUIRED\" wrap-principals=\"true\">\n"
092: + " <lc:login-domain-name>default</lc:login-domain-name>\n"
093: + " <lc:login-module-class>org.apache.geronimo.security.realm.providers.NamedUsernamePasswordCredentialLoginModule</lc:login-module-class>\n"
094: + " <lc:option name=\"org.apache.geronimo.jaas.NamedUsernamePasswordCredential.Name\">default</lc:option>\n"
095: + " </lc:login-module>\n"
096: + " </lc:login-config>";
097:
098: public void test1() throws Exception {
099: doTest(SAMPLE1);
100: }
101:
102: public void test2() throws Exception {
103: doTest(SAMPLE2);
104: }
105:
106: public void test3() throws Exception {
107: doTest(SAMPLE3);
108: }
109:
110: public void test() throws Exception {
111: doTest(SAMPLE4);
112: }
113:
114: private void doTest(String text) throws XmlException,
115: DeploymentException {
116: GeronimoSecurityBuilderImpl secBuilder = new GeronimoSecurityBuilderImpl(
117: null);
118: secBuilder.doStart();
119: LoginConfigBuilder builder = new LoginConfigBuilder(
120: new Jsr77Naming(), null);
121: XmlObject xmlObject = XmlBeansUtil.parse(text);
122: XmlCursor cursor = xmlObject.newCursor();
123: cursor.toFirstContentToken();
124: xmlObject = cursor.getObject();
125: DeploymentContext context = new DeploymentContext(
126: new File("."), null, new Environment(Artifact
127: .create("test/foo/1.0/car")), null,
128: ConfigurationModuleType.SERVICE, new Jsr77Naming(),
129: new MockConfigurationManager(), Collections.emptySet());
130: AbstractName parentName = new AbstractName(URI
131: .create("test/foo/1.0/car?name=parent,j2eeType=foo"));
132: builder.getReferences(xmlObject, context, parentName,
133: getClass().getClassLoader());
134: secBuilder.doStop();
135: }
136:
137: }
|