Path: blob/master/test/jdk/com/sun/security/auth/CreateLdapPrincipals.java
41152 views
/*1* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @author Vincent Ryan26* @bug 639377027* @summary Check that an LdapPrincipal can be initialized using various forms28* of string distinguished names.29*/3031import java.util.*;32import java.security.Principal;33import javax.security.auth.Subject;34import com.sun.security.auth.LdapPrincipal;3536/*37* Create principals using string distinguished names containing non-standard38* attribute names. A non-standard attribute name is one that is not listed in39* Section 2.3 of RFC 2253. Typically, such distinguished names are valid in40* LDAP but are not valid in X.500 as they cannot be encoded using ASN.1 BER41* (because the object identifier corresponding to the attribute name is42* unknown).43*/44public class CreateLdapPrincipals {4546public static void main(String[] args) throws Exception {4748Set<Principal> principals = new Subject().getPrincipals();4950principals.add(new LdapPrincipal("x=y"));51principals.add(new LdapPrincipal("x=#04024869"));52principals.add(new LdapPrincipal("1.2.3=x"));53principals.add(new LdapPrincipal("A=B"));54principals.add(new LdapPrincipal("a=b+c=d"));55principals.add(new LdapPrincipal("a=b,c=d,e=f"));56principals.add(new LdapPrincipal("f=g, h=i, j=k"));5758System.out.println("Successfully created " + principals.size() +59" LDAP principals:");60System.out.println(principals);61}62}636465