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

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

      
    
Rootfs path

      
    
Size
4689 (4.6 KB)
MD5
27e3c1510f0e4d94ae8d520aee55ff1d
SHA1
1e92d73bad844ea1c72121e82b46c0daca7414e3
SHA256
f35a52776ec78294a55d48d0d760b6c8de00ccc23e7ce864bd2b6c5892a9f4b9
SHA512

      
    
SHA1_git
4fc3df4bfdd859194076b6496deb5b8aa6eead21
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestJAASRealm.java | 4.6 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 TestJAASRealm extends TomcatBaseTest { private static final String CONFIG = "CustomLogin { " + " org.apache.catalina.realm.TesterLoginModule " + " sufficient; " + "};"; private static final String CONFIG_MEMORY = "MemoryLogin { " + " org.apache.catalina.realm.JAASMemoryLoginModule " + " sufficient pathname=\"tomcat-users-lm.xml\"; " + "};"; @Test public void testRealm() throws Exception { Tomcat tomcat = getTomcatInstance(); // Write login config to the temp path File loginConfFile = new File(getTemporaryDirectory(), "customLoginConfig.conf"); try (PrintWriter writer = new PrintWriter(loginConfFile)) { writer.write(CONFIG); } addDeleteOnTearDown(loginConfFile); JAASRealm jaasRealm = new JAASRealm(); jaasRealm.setAppName("CustomLogin"); jaasRealm.setCredentialHandler(new MessageDigestCredentialHandler()); jaasRealm.setUserClassNames(TesterPrincipal.class.getName()); jaasRealm.setRoleClassNames(TesterRolePrincipal.class.getName()); jaasRealm.setConfigFile(loginConfFile.getAbsolutePath()); Context context = tomcat.addContext("/jaastest", null); context.setRealm(jaasRealm); tomcat.start(); Principal p = jaasRealm.authenticate("foo", "bar"); Assert.assertNull(p); p = jaasRealm.authenticate("tomcatuser", "pass"); Assert.assertNotNull(p); Assert.assertTrue(p instanceof GenericPrincipal); GenericPrincipal gp = (GenericPrincipal) p; Assert.assertTrue(gp.hasRole("role1")); } @Test public void testMemoryLoginModule() throws Exception { Tomcat tomcat = getTomcatInstance(); File tomcatUsersXml = new File(getTemporaryDirectory(), "tomcat-users-lm.xml"); try (PrintWriter writer = new PrintWriter(tomcatUsersXml)) { writer.write(TestMemoryRealm.CONFIG); } addDeleteOnTearDown(tomcatUsersXml); // Write login config to the temp path File loginConfFile = new File(getTemporaryDirectory(), "memoryLoginConfig.conf"); try (PrintWriter writer = new PrintWriter(loginConfFile)) { String path = tomcatUsersXml.getAbsolutePath(); if (File.separatorChar == '\\') { path = path.replace("\\", "\\\\"); } writer.write(CONFIG_MEMORY.replace("tomcat-users-lm.xml", path)); } addDeleteOnTearDown(loginConfFile); JAASRealm jaasRealm = new JAASRealm(); jaasRealm.setAppName("MemoryLogin"); jaasRealm.setCredentialHandler(new MessageDigestCredentialHandler()); jaasRealm.setUserClassNames(GenericPrincipal.class.getName()); jaasRealm.setRoleClassNames(GenericPrincipal.class.getName()); jaasRealm.setConfigFile(loginConfFile.getAbsolutePath()); Context context = tomcat.addContext("/jaastest", null); context.setRealm(jaasRealm); tomcat.start(); Principal p = jaasRealm.authenticate("foo", "bar"); Assert.assertNull(p); p = jaasRealm.authenticate("admin", "sekr3t"); Assert.assertNotNull(p); Assert.assertTrue(p instanceof GenericPrincipal); GenericPrincipal gp = (GenericPrincipal) p; Assert.assertTrue(gp.hasRole("testrole")); } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
28.4
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