ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/catalina/realm/TestGenericPrincipal.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/catalina/realm/TestGenericPrincipal.java
Status
scanned
Type
file
Name
TestGenericPrincipal.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
3561 (3.5 KB)
MD5
3bbba693f24ca3af2de63fc9ce98985b
SHA1
ac0f62e2e40d4dea7708a6965dc13a3717f3204f
SHA256
180f5949169f189d60f0d07946a90b53c4caad0609776dbfafc26fc3b59cc706
SHA512

      
    
SHA1_git
1bee18c8a88fe5d80ccbbc66fb90489c806b7fd7
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestGenericPrincipal.java | 3.5 KB |

/* * 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.catalina.realm; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.Arrays; import java.util.Collections; import java.util.List; import org.junit.Assert; import org.junit.Test; public class TestGenericPrincipal { private static final String USER = "user"; private static final List<String> ROLES = Collections.unmodifiableList( Arrays.asList(new String[] { "ROLE1", "ROLE2" })); private static final TesterPrincipal PRINCIPAL = new TesterPrincipal("Principal"); private static final TesterPrincipalNonSerializable PRINCIPAL_NON_SERIALIZABLE = new TesterPrincipalNonSerializable("PrincipalNonSerializable"); @Test public void testSerialize01() throws ClassNotFoundException, IOException { GenericPrincipal gpIn = new GenericPrincipal(USER, ROLES); doTest(gpIn); } @Test public void testSerialize02() throws ClassNotFoundException, IOException { GenericPrincipal gpIn = new GenericPrincipal(USER, ROLES, PRINCIPAL); doTest(gpIn); } @Test public void testSerialize03() throws ClassNotFoundException, IOException { GenericPrincipal gpIn = new GenericPrincipal(USER, ROLES, PRINCIPAL_NON_SERIALIZABLE); doTest(gpIn); } private void doTest(GenericPrincipal gpIn) throws ClassNotFoundException, IOException { GenericPrincipal gpOut = serializeAndDeserialize(gpIn); Assert.assertNull(gpOut.getGssCredential()); Assert.assertEquals(gpIn.getName(), gpOut.getName()); Assert.assertArrayEquals(gpIn.getRoles(), gpOut.getRoles()); if (gpIn == gpIn.getUserPrincipal()) { Assert.assertEquals(gpOut, gpOut.getUserPrincipal()); } else if (gpIn.getUserPrincipal() instanceof Serializable) { Assert.assertEquals(gpIn.getUserPrincipal(), gpOut.getUserPrincipal()); } else { Assert.assertEquals(gpOut, gpOut.getUserPrincipal()); } } private GenericPrincipal serializeAndDeserialize(GenericPrincipal gpIn) throws IOException, ClassNotFoundException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(gpIn); byte[] data = bos.toByteArray(); ByteArrayInputStream bis = new ByteArrayInputStream(data); ObjectInputStream ois = new ObjectInputStream(bis); return (GenericPrincipal) ois.readObject(); } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
34.0
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9