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

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

      
    
Rootfs path

      
    
Size
3238 (3.2 KB)
MD5
5b76f9bede9cbecac47011efc7e6d4c6
SHA1
c9eea24114fc90cbd3953075a6ca82e8351de196
SHA256
1c52384785ee19fd6d3affe996206f380d5fd30c13b446b3608bb230a082618b
SHA512

      
    
SHA1_git
e1fbbfe6eb10b9d034ad22b7ebf334a4ef3c5865
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestMemoryRealm.java | 3.2 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.File; import java.io.PrintWriter; import java.security.Principal; import org.junit.Assert; import org.junit.Test; import org.apache.catalina.Context; import org.apache.catalina.startup.Tomcat; import org.apache.catalina.startup.TomcatBaseTest; public class TestMemoryRealm extends TomcatBaseTest { public static final String CONFIG = "<?xml version=\"1.0\" ?>" + "<tomcat-users xmlns=\"http://tomcat.apache.org/xml\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + " xsi:schemaLocation=\"http://tomcat.apache.org/xml/tomcat-users.xsd\"" + " version=\"1.0\">" + "<role rolename=\"testrole\" />" + "<group groupname=\"testgroup\" />" + "<user username=\"admin\" password=\"sekr3t\" roles=\"testrole, otherrole\" groups=\"testgroup, othergroup\" />" + "</tomcat-users>"; @Test public void testRealmWithLockout() throws Exception { File configFile = new File(getTemporaryDirectory(), "tomcat-users-mr.xml"); try (PrintWriter writer = new PrintWriter(configFile)) { writer.write(CONFIG); } addDeleteOnTearDown(configFile); MemoryRealm memoryRealm = new MemoryRealm(); memoryRealm.setCredentialHandler(new MessageDigestCredentialHandler()); memoryRealm.setPathname(configFile.getAbsolutePath()); LockOutRealm lockout = new LockOutRealm(); lockout.addRealm(memoryRealm); // LockOutRealm needs full lifecycle Tomcat tomcat = getTomcatInstance(); Context context = tomcat.addContext("/realmtest", null); context.setRealm(lockout); tomcat.start(); Principal p = lockout.authenticate("foo", "bar"); Assert.assertNull(p); p = lockout.authenticate("admin", "sekr3t"); Assert.assertNotNull(p); p = lockout.authenticate("admin", "bla"); Assert.assertNull(p); p = lockout.authenticate("admin", "bla"); p = lockout.authenticate("admin", "bla"); p = lockout.authenticate("admin", "bla"); p = lockout.authenticate("admin", "bla"); // Verify that lockout is now in place after 5 failures p = lockout.authenticate("admin", "sekr3t"); Assert.assertNull(p); } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
35.31
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
http://tomcat.apache.org/xml 33 33
http://tomcat.apache.org/xml/tomcat-users.xsd 35 35