Package org.apache.geronimo.security.realm.providers

Source Code of org.apache.geronimo.security.realm.providers.GeronimoPropertiesFileMappedPasswordCredentialLoginModuleTest

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*/


package org.apache.geronimo.security.realm.providers;

import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;

import junit.framework.TestCase;
import org.apache.geronimo.security.jaas.NamedUsernamePasswordCredential;

/**
* @version $Rev: 545781 $ $Date: 2007-06-09 13:44:02 -0400 (Sat, 09 Jun 2007) $
*/
public class GeronimoPropertiesFileMappedPasswordCredentialLoginModuleTest extends TestCase {
    private GeronimoPropertiesFileMappedPasswordCredentialLoginModule loginModule;
    private Set<NamedUsernamePasswordCredential> passwordCredentials;

    protected void setUp() {
        loginModule = new GeronimoPropertiesFileMappedPasswordCredentialLoginModule();
        passwordCredentials = new HashSet<NamedUsernamePasswordCredential>();
    }

    public void testParsingOne() throws Exception {
        loginModule.parseCredentials("foo:bar=baz", passwordCredentials);
        assertEquals(1, passwordCredentials.size());
        NamedUsernamePasswordCredential cred = passwordCredentials.iterator().next();
        checkCredential(cred, "foo", "bar", "baz");
    }
    public void testParsingTwo() throws Exception {
        loginModule.parseCredentials("foo:bar=baz,foo2:bar2=baz2", passwordCredentials);
        assertEquals(2, passwordCredentials.size());
        Iterator<NamedUsernamePasswordCredential> iterator = passwordCredentials.iterator();
        NamedUsernamePasswordCredential cred = iterator.next();
        checkCredential(cred, "foo", "bar", "baz");
        cred = iterator.next();
        checkCredential(cred, "foo2", "bar2", "baz2");
    }

    private void checkCredential(NamedUsernamePasswordCredential cred, String name, String user, String pw) {
        assertEquals(name, cred.getName());
        assertEquals(user, cred.getUsername());
        assertEquals(pw, new String(cred.getPassword()));
    }

}
TOP

Related Classes of org.apache.geronimo.security.realm.providers.GeronimoPropertiesFileMappedPasswordCredentialLoginModuleTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.