This is an automated email from the ASF dual-hosted git repository. lprimak pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/shiro.git
commit 43cedf2e14700c6c7ea649705f7e31f545d5d798 Author: Rui Ventura <[email protected]> AuthorDate: Wed Jan 21 15:48:56 2026 +0000 [#1585] Migrate to Jakarta EE 10 (3.x) (#2018) * Update to 3.0.0 Includes version bumps: - Java: 11 -> 17 - Ehcache: 2.6 -> 3.10 - Guice: 6 -> 7 - Jetty: 9.4.56.v2024.. -> 12.0 - `org.eclipse.jetty` -> `org.eclipse.jetty.ee10` - Jakarta EE: 8 -> 10 - Activation: 1.2 -> 2.1 - Annotation: 1.3 -> 2.1 - Enterprise CDI API: 2.0 -> 4.0 - JSON API: 1.1 -> 2.1 - JSON Bind: 1.0 -> 3.0 - Servlet: 4.0 -> 6.0 - Servlet JSP API: 2.2 -> 3.1 - Validation API: 2.0 -> 3.0 - WS RS API: 2.1 -> 3.1 - XML Bind: 2.3 -> 4.0 - Omnifaces: 4.6.1 - CXF RT Client: 3.6 -> 4.0 - Glassfish JAXB RT: 2.3 -> 4.0 - Spring: 5.3 -> 6.2 - Spring Boot: 2.7 -> 3.4 - Hibernate: 5.6 -> 6.6 (sample project) Concerns: - Ehcache migration most certainly needs revision - CI untested (specially Jenkins CD) - `flowlogix`, `omnifaces`, and a few other libs I have no knowledge of, certainly need attention - Spring remoting seems to have been dropped from Spring Context, not sure if replaceable Known issues: - No immediate suitable replacement for `org.eclipse.jetty:apache-jstl` - Ehcache 3.10 is pulling earlier version of jaxb runtime -> conflicting - Added exclusion to circumvent woes - Some web integration tests aren't up to speed - Embedded jetty-based ITs fail, server reports 503 - Arquillian IT fails - Meecrowave support missing (solved in unreleased 2.0.0?) * Remove lingering guice3 IT pom.xml * Suppress unchecked cast warning * Revert ill merge in test case * Properly disable meecrowave-based IT * Remove Shiro Spring remoting test * Remove lingering jetty injection argument from IT test case * Restore dependency details lost in translation * Remove stray type for runtime type inference / reification attempt Shouldn't have included this 🤦 This was a miserable attempt to obtain the concrete `Class<?>` instance for the request key and value types for caches. Please excuse my desperation. * fix(lang): Fix resource retrieval as URL instead of stream * fix: Fix typos in schema locations Co-authored-by: Copilot <[email protected]> * fix(javadoc): Fix jakarta servlet javadoc reference * jakarta-related cleanup * fixed ehcache.xml --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: lprimak <[email protected]> --- .../samples/guice/SampleShiroGuiceBootstrap.java | 43 -------- .../samples/guice/SampleShiroServletModule.java | 89 ----------------- .../guice3/src/main/resources/log4j2.xml | 68 ------------- .../guice3/src/main/webapp/WEB-INF/shiro.ini | 53 ---------- .../guice3/src/main/webapp/WEB-INF/web.xml | 43 -------- .../guice3/src/main/webapp/account/index.jsp | 36 ------- integration-tests/guice3/src/main/webapp/home.jsp | 69 ------------- .../guice3/src/main/webapp/include.jsp | 22 ----- integration-tests/guice3/src/main/webapp/index.jsp | 21 ---- integration-tests/guice3/src/main/webapp/login.jsp | 110 --------------------- integration-tests/guice3/src/main/webapp/style.css | 47 --------- .../samples/guice/ContainerIntegrationIT.java | 79 --------------- .../samples/guice/SampleShiroGuiceBootstrap.java | 43 -------- .../samples/guice/SampleShiroServletModule.java | 91 ----------------- .../guice4/src/main/resources/log4j2.xml | 68 ------------- .../guice4/src/main/webapp/WEB-INF/shiro.ini | 53 ---------- .../guice4/src/main/webapp/WEB-INF/web.xml | 43 -------- .../guice4/src/main/webapp/account/index.jsp | 36 ------- integration-tests/guice4/src/main/webapp/home.jsp | 69 ------------- .../guice4/src/main/webapp/include.jsp | 22 ----- integration-tests/guice4/src/main/webapp/index.jsp | 21 ---- integration-tests/guice4/src/main/webapp/login.jsp | 110 --------------------- integration-tests/guice4/src/main/webapp/style.css | 47 --------- .../samples/guice/ContainerIntegrationIT.java | 79 --------------- .../spring/config/RemotingServletConfig.java | 46 --------- samples/web-jakarta/src/main/resources/log4j2.xml | 2 +- samples/web-jakarta/src/test/resources/log4j2.xml | 2 +- .../org/apache/shiro/cache/ehcache/EhCache.java | 74 +++++++------- .../apache/shiro/cache/ehcache/EhCacheManager.java | 86 ++++++++++------ .../org/apache/shiro/cache/ehcache/ehcache.xml | 57 ++++++----- .../shiro/cache/ehcache/EhCacheManagerTest.java | 12 +-- support/ehcache/src/test/resources/log4j2-test.xml | 2 +- .../apache/shiro/ee/util/JakartaTransformer.java | 38 ------- .../apache/shiro/spring/remoting/package-info.java | 23 ----- 34 files changed, 130 insertions(+), 1574 deletions(-) diff --git a/integration-tests/guice3/src/main/java/org/apache/shiro/samples/guice/SampleShiroGuiceBootstrap.java b/integration-tests/guice3/src/main/java/org/apache/shiro/samples/guice/SampleShiroGuiceBootstrap.java deleted file mode 100644 index f884aefc0..000000000 --- a/integration-tests/guice3/src/main/java/org/apache/shiro/samples/guice/SampleShiroGuiceBootstrap.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.shiro.samples.guice; - -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.servlet.GuiceServletContextListener; -import org.apache.shiro.guice.web.ShiroWebModule; - -import jakarta.servlet.ServletContext; -import jakarta.servlet.ServletContextEvent; - -public class SampleShiroGuiceBootstrap extends GuiceServletContextListener { - - private ServletContext servletContext; - - @Override - public void contextInitialized(final ServletContextEvent servletContextEvent) { - this.servletContext = servletContextEvent.getServletContext(); - super.contextInitialized(servletContextEvent); - } - - @Override - protected Injector getInjector() { - return Guice.createInjector(new SampleShiroServletModule(servletContext), ShiroWebModule.guiceFilterModule()); - } -} diff --git a/integration-tests/guice3/src/main/java/org/apache/shiro/samples/guice/SampleShiroServletModule.java b/integration-tests/guice3/src/main/java/org/apache/shiro/samples/guice/SampleShiroServletModule.java deleted file mode 100644 index 007f9e472..000000000 --- a/integration-tests/guice3/src/main/java/org/apache/shiro/samples/guice/SampleShiroServletModule.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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.shiro.samples.guice; - -import com.google.inject.Provides; -import com.google.inject.binder.AnnotatedBindingBuilder; -import com.google.inject.name.Names; -import org.apache.shiro.lang.codec.Base64; -import org.apache.shiro.config.ConfigurationException; -import org.apache.shiro.config.Ini; -import org.apache.shiro.guice.web.ShiroWebModule; -import org.apache.shiro.realm.text.IniRealm; -import org.apache.shiro.web.mgt.CookieRememberMeManager; -import org.apache.shiro.web.mgt.DefaultWebSecurityManager; -import org.apache.shiro.web.mgt.WebSecurityManager; - -import jakarta.inject.Singleton; -import jakarta.servlet.ServletContext; -import java.net.MalformedURLException; -import java.net.URL; - -public class SampleShiroServletModule extends ShiroWebModule { - private final ServletContext servletContext; - - public SampleShiroServletModule(ServletContext servletContext) { - super(servletContext); - - this.servletContext = servletContext; - } - - @Override - @SuppressWarnings({"unchecked", "deprecation"}) - protected void configureShiroWeb() { - bindConstant().annotatedWith(Names.named("shiro.loginUrl")).to("/login.jsp"); - try { - this.bindRealm().toConstructor(IniRealm.class.getConstructor(Ini.class)); - } catch (NoSuchMethodException e) { - addError("Could not locate proper constructor for IniRealm.", e); - } - - this.addFilterChain("/login.jsp", AUTHC); - this.addFilterChain("/logout", LOGOUT); - this.addFilterChain("/account/**", AUTHC); - - this.addFilterChain("/remoting/**", AUTHC, config(ROLES, "b2bClient"), config(PERMS, "remote:invoke:lan,wan")); - } - - @Provides - @Singleton - Ini loadShiroIni() throws MalformedURLException { - URL iniUrl = servletContext.getResource("/WEB-INF/shiro.ini"); - return Ini.fromResourcePath("url:" + iniUrl.toExternalForm()); - } - - @Override - protected void bindWebSecurityManager(AnnotatedBindingBuilder<? super WebSecurityManager> bind) { - try { - String cipherKey = loadShiroIni().getSectionProperty("main", "securityManager.rememberMeManager.cipherKey"); - - DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager(); - CookieRememberMeManager rememberMeManager = new CookieRememberMeManager(); - rememberMeManager.setCipherKey(Base64.decode(cipherKey)); - securityManager.setRememberMeManager(rememberMeManager); - bind.toInstance(securityManager); - } catch (MalformedURLException e) { - // for now just throw, you could just call - // super.bindWebSecurityManager(bind) if you do not need rememberMe functionality - throw new ConfigurationException("securityManager.rememberMeManager.cipherKey must be set in shiro.ini."); - } - - - } -} diff --git a/integration-tests/guice3/src/main/resources/log4j2.xml b/integration-tests/guice3/src/main/resources/log4j2.xml deleted file mode 100644 index 46fb635c9..000000000 --- a/integration-tests/guice3/src/main/resources/log4j2.xml +++ /dev/null @@ -1,68 +0,0 @@ -<!-- - ~ 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. - --> - -<Configuration name="ConfigTest" status="ERROR" monitorInterval="5"> - <!-- - ~ 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. - --> - - <Appenders> - <Console name="Console" target="SYSTEM_OUT"> - <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> - </Console> - </Appenders> - <Loggers> - <Logger name="org.quartz" level="warn" additivity="false"> - <AppenderRef ref="Console"/> - </Logger> - <Logger name="org.apache" level="warn" additivity="false"> - <AppenderRef ref="Console"/> - </Logger> - <Logger name="net.sf.ehcache" level="warn" additivity="false"> - <AppenderRef ref="Console"/> - </Logger> - <Logger name="org.apache.shiro" level="info" additivity="false"> - <AppenderRef ref="Console"/> - </Logger> - <Logger name="org.apache.shiro.util.ThreadContext" level="info" additivity="false"> - <AppenderRef ref="Console"/> - </Logger> - <Logger name="org.eclipse.jetty.annotations.AnnotationParser" level="error" additivity="false"> - <AppenderRef ref="Console"/> - </Logger> - <Root level="error"> - <AppenderRef ref="Console"/> - </Root> - </Loggers> -</Configuration> diff --git a/integration-tests/guice3/src/main/webapp/WEB-INF/shiro.ini b/integration-tests/guice3/src/main/webapp/WEB-INF/shiro.ini deleted file mode 100644 index 18bb0dff7..000000000 --- a/integration-tests/guice3/src/main/webapp/WEB-INF/shiro.ini +++ /dev/null @@ -1,53 +0,0 @@ -# -# 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. -# - -# INI configuration is very powerful and flexible, while still remaining succinct. -# Please https://shiro.apache.org/configuration.html and -# https://shiro.apache.org/web.html for more. - -[main] -shiro.loginUrl = /login.jsp - -# We need to set the cipherKey, if you want the rememberMe cookie to work after restarting or on multiple nodes. -# YOU MUST SET THIS TO A UNIQUE STRING -securityManager.rememberMeManager.cipherKey = kPH+bIxk5D2deZiIxcaaaA== - -[users] -# format: username = password, role1, role2, ..., roleN -root = secret,admin -guest = guest,guest -presidentskroob = 12345,president -darkhelmet = ludicrousspeed,darklord,schwartz -lonestarr = vespa,goodguy,schwartz - -[roles] -# format: roleName = permission1, permission2, ..., permissionN -admin = * -schwartz = lightsaber:* -goodguy = winnebago:drive:eagle5 - -[urls] -# The /login.jsp is not restricted to authenticated users (otherwise no one could log in!), but -# the 'authc' filter must still be specified for it so it can process that url's -# login submissions. It is 'smart' enough to allow those requests through as specified by the -# shiro.loginUrl above. -/login.jsp = authc -/logout = logout -/account/** = authc -/remoting/** = authc, roles[b2bClient], perms["remote:invoke:lan,wan"] diff --git a/integration-tests/guice3/src/main/webapp/WEB-INF/web.xml b/integration-tests/guice3/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 64681aec7..000000000 --- a/integration-tests/guice3/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,43 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ 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. - --> -<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd" - version="6.0"> - - <listener> - <listener-class>org.apache.shiro.samples.guice.SampleShiroGuiceBootstrap</listener-class> - </listener> - - <filter> - <filter-name>GuiceFilter</filter-name> - <filter-class>com.google.inject.servlet.GuiceFilter</filter-class> - </filter> - - <filter-mapping> - <filter-name>GuiceFilter</filter-name> - <url-pattern>/*</url-pattern> - </filter-mapping> - - <welcome-file-list> - <welcome-file>index.jsp</welcome-file> - </welcome-file-list> - -</web-app> diff --git a/integration-tests/guice3/src/main/webapp/account/index.jsp b/integration-tests/guice3/src/main/webapp/account/index.jsp deleted file mode 100644 index 013b21a8b..000000000 --- a/integration-tests/guice3/src/main/webapp/account/index.jsp +++ /dev/null @@ -1,36 +0,0 @@ -<%-- - ~ 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. - --%> -<%@ include file="../include.jsp" %> - -<html> -<head> - <link type="text/css" rel="stylesheet" href="<c:url value="/style.css"/>"/> -</head> -<body> - -<h2>Users only</h2> - -<p>You are currently logged in.</p> - -<p><a href="<c:url value="/home.jsp"/>">Return to the home page.</a></p> - -<p><a href="<c:url value="/logout"/>">Log out.</a></p> - -</body> -</html> diff --git a/integration-tests/guice3/src/main/webapp/home.jsp b/integration-tests/guice3/src/main/webapp/home.jsp deleted file mode 100644 index 61dee2552..000000000 --- a/integration-tests/guice3/src/main/webapp/home.jsp +++ /dev/null @@ -1,69 +0,0 @@ -<%-- - ~ 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. - --%> -<%@ include file="include.jsp" %> - -<html> -<head> - <link type="text/css" rel="stylesheet" href="<c:url value="/style.css"/>"/> - <title>Apache Shiro Quickstart</title> -</head> -<body> - -<h1>Apache Shiro Quickstart</h1> - -<p>Hi <shiro:guest>Guest</shiro:guest><shiro:user><shiro:principal/></shiro:user>! - ( <shiro:user><a href="<c:url value="/logout"/>">Log out</a></shiro:user> - <shiro:guest><a href="<c:url value="/login.jsp"/>">Log in</a> (sample accounts provided)</shiro:guest> ) -</p> - -<p>Welcome to the Apache Shiro Quickstart sample application. - This page represents the home page of any web application.</p> - -<shiro:user><p>Visit your <a href="<c:url value="/account"/>">account page</a>.</p></shiro:user> -<shiro:guest><p>If you want to access the user-only <a href="<c:url value="/account"/>">account page</a>, - you will need to log-in first.</p></shiro:guest> - -<h2>Roles</h2> - -<p>To show some taglibs, here are the roles you have and don't have. Log out and log back in under different user - accounts to see different roles.</p> - -<h3>Roles you have</h3> - -<p> - <shiro:hasRole name="admin">admin<br/></shiro:hasRole> - <shiro:hasRole name="president">president<br/></shiro:hasRole> - <shiro:hasRole name="darklord">darklord<br/></shiro:hasRole> - <shiro:hasRole name="goodguy">goodguy<br/></shiro:hasRole> - <shiro:hasRole name="schwartz">schwartz<br/></shiro:hasRole> -</p> - -<h3>Roles you DON'T have</h3> - -<p> - <shiro:lacksRole name="admin">admin<br/></shiro:lacksRole> - <shiro:lacksRole name="president">president<br/></shiro:lacksRole> - <shiro:lacksRole name="darklord">darklord<br/></shiro:lacksRole> - <shiro:lacksRole name="goodguy">goodguy<br/></shiro:lacksRole> - <shiro:lacksRole name="schwartz">schwartz<br/></shiro:lacksRole> -</p> - - -</body> -</html> diff --git a/integration-tests/guice3/src/main/webapp/include.jsp b/integration-tests/guice3/src/main/webapp/include.jsp deleted file mode 100644 index 8472daca1..000000000 --- a/integration-tests/guice3/src/main/webapp/include.jsp +++ /dev/null @@ -1,22 +0,0 @@ -<%-- - ~ 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. - --%> -<%@ page import="org.apache.shiro.SecurityUtils" %> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> -<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> -<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %> diff --git a/integration-tests/guice3/src/main/webapp/index.jsp b/integration-tests/guice3/src/main/webapp/index.jsp deleted file mode 100644 index ec60ad16c..000000000 --- a/integration-tests/guice3/src/main/webapp/index.jsp +++ /dev/null @@ -1,21 +0,0 @@ -<%-- - ~ 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. - --%> - -<%-- Forward the user to the home page --%> -<jsp:forward page="home.jsp"/> diff --git a/integration-tests/guice3/src/main/webapp/login.jsp b/integration-tests/guice3/src/main/webapp/login.jsp deleted file mode 100644 index c80ee54c8..000000000 --- a/integration-tests/guice3/src/main/webapp/login.jsp +++ /dev/null @@ -1,110 +0,0 @@ -<%-- - ~ 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. - --%> -<%@ include file="include.jsp" %> - -<html> -<head> - <link type="text/css" rel="stylesheet" href="<c:url value="/style.css"/>"/> -</head> -<body> - -<h2>Please Log in</h2> - -<shiro:guest> - <p>Here are a few sample accounts to play with in the default text-based Realm (used for this - demo and test installs only). Do you remember the movie these names came from? ;)</p> - - - <style type="text/css"> - table.sample { - border-width: 1px; - border-style: outset; - border-color: blue; - border-collapse: separate; - background-color: rgb(255, 255, 240); - } - - table.sample th { - border-width: 1px; - padding: 1px; - border-style: none; - border-color: blue; - background-color: rgb(255, 255, 240); - } - - table.sample td { - border-width: 1px; - padding: 1px; - border-style: none; - border-color: blue; - background-color: rgb(255, 255, 240); - } - </style> - - - <table class="sample"> - <thead> - <tr> - <th>Username</th> - <th>Password</th> - </tr> - </thead> - <tbody> - <tr> - <td>root</td> - <td>secret</td> - </tr> - <tr> - <td>presidentskroob</td> - <td>12345</td> - </tr> - <tr> - <td>darkhelmet</td> - <td>ludicrousspeed</td> - </tr> - <tr> - <td>lonestarr</td> - <td>vespa</td> - </tr> - </tbody> - </table> - <br/><br/> -</shiro:guest> - -<form name="loginform" action="" method="post"> - <table align="left" border="0" cellspacing="0" cellpadding="3"> - <tr> - <td>Username:</td> - <td><input type="text" name="username" maxlength="30"></td> - </tr> - <tr> - <td>Password:</td> - <td><input type="password" name="password" maxlength="30"></td> - </tr> - <tr> - <td colspan="2" align="left"><input type="checkbox" name="rememberMe"><font size="2">Remember Me</font></td> - </tr> - <tr> - <td colspan="2" align="right"><input type="submit" name="submit" value="Login"></td> - </tr> - </table> -</form> - -</body> -</html> diff --git a/integration-tests/guice3/src/main/webapp/style.css b/integration-tests/guice3/src/main/webapp/style.css deleted file mode 100644 index c3e3944cf..000000000 --- a/integration-tests/guice3/src/main/webapp/style.css +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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. - */ -body { - margin: 15px 0 0 15px; - padding: 1px; /*background: #2370cf;*/ - font: 12px 'Lucida Grande', Geneva, Verdana, Arial, sans-serif; - color: #000; -} - -table, td { - font: 12px 'Lucida Grande', Geneva, Verdana, Arial, sans-serif; - color: #000; -} - -h1 { - font: 24px; -} - -img { - border: thin black solid; -} - -#contentBox { - text-align: center; - width: 50%; - margin: auto; - margin-top: 50px; - color: black; - background: #eee; - border: thick black solid; -} diff --git a/integration-tests/guice3/src/test/java/org/apache/shiro/samples/guice/ContainerIntegrationIT.java b/integration-tests/guice3/src/test/java/org/apache/shiro/samples/guice/ContainerIntegrationIT.java deleted file mode 100644 index 550b9e229..000000000 --- a/integration-tests/guice3/src/test/java/org/apache/shiro/samples/guice/ContainerIntegrationIT.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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.shiro.samples.guice; - -import org.apache.shiro.testing.web.AbstractContainerIT; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.htmlunit.ElementNotFoundException; -import org.htmlunit.FailingHttpStatusCodeException; -import org.htmlunit.WebAssert; -import org.htmlunit.html.HtmlCheckBoxInput; -import org.htmlunit.html.HtmlForm; -import org.htmlunit.html.HtmlPage; - -import java.io.IOException; -import java.net.MalformedURLException; - -public class ContainerIntegrationIT extends AbstractContainerIT { - - @BeforeEach - public void logOut() throws IOException { - // Make sure we are logged out - final HtmlPage homePage = webClient.getPage(getBaseUri()); - try { - homePage.getAnchorByHref("/logout").click(); - } catch (ElementNotFoundException e) { - //Ignore - } - } - - @Test - void logIn() throws FailingHttpStatusCodeException, MalformedURLException, IOException, InterruptedException { - - HtmlPage page = webClient.getPage(getBaseUri() + "login.jsp"); - HtmlForm form = page.getFormByName("loginform"); - form.getInputByName("username").setValueAttribute("root"); - form.getInputByName("password").setValueAttribute("secret"); - page = form.getInputByName("submit").click(); - // This'll throw an exception if not logged in - page.getAnchorByHref("/logout"); - } - - @Test - void logInAndRememberMe() throws Exception { - HtmlPage page = webClient.getPage(getBaseUri() + "login.jsp"); - HtmlForm form = page.getFormByName("loginform"); - form.getInputByName("username").setValueAttribute("root"); - form.getInputByName("password").setValueAttribute("secret"); - HtmlCheckBoxInput checkbox = form.getInputByName("rememberMe"); - checkbox.setChecked(true); - page = form.getInputByName("submit").click(); - jetty.stop(); - jetty.start(); - page = webClient.getPage(getBaseUri()); - // page.getAnchorByHref("/logout"); - WebAssert.assertLinkPresentWithText(page, "Log out"); - page = page.getAnchorByHref("/account").click(); - // login page should be shown again - user remembered but not authenticated - WebAssert.assertFormPresent(page, "loginform"); - } - -} diff --git a/integration-tests/guice4/src/main/java/org/apache/shiro/samples/guice/SampleShiroGuiceBootstrap.java b/integration-tests/guice4/src/main/java/org/apache/shiro/samples/guice/SampleShiroGuiceBootstrap.java deleted file mode 100644 index f884aefc0..000000000 --- a/integration-tests/guice4/src/main/java/org/apache/shiro/samples/guice/SampleShiroGuiceBootstrap.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.shiro.samples.guice; - -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.servlet.GuiceServletContextListener; -import org.apache.shiro.guice.web.ShiroWebModule; - -import jakarta.servlet.ServletContext; -import jakarta.servlet.ServletContextEvent; - -public class SampleShiroGuiceBootstrap extends GuiceServletContextListener { - - private ServletContext servletContext; - - @Override - public void contextInitialized(final ServletContextEvent servletContextEvent) { - this.servletContext = servletContextEvent.getServletContext(); - super.contextInitialized(servletContextEvent); - } - - @Override - protected Injector getInjector() { - return Guice.createInjector(new SampleShiroServletModule(servletContext), ShiroWebModule.guiceFilterModule()); - } -} diff --git a/integration-tests/guice4/src/main/java/org/apache/shiro/samples/guice/SampleShiroServletModule.java b/integration-tests/guice4/src/main/java/org/apache/shiro/samples/guice/SampleShiroServletModule.java deleted file mode 100644 index 5b6dca73f..000000000 --- a/integration-tests/guice4/src/main/java/org/apache/shiro/samples/guice/SampleShiroServletModule.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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.shiro.samples.guice; - -import com.google.inject.Provides; -import com.google.inject.binder.AnnotatedBindingBuilder; -import com.google.inject.name.Names; -import org.apache.shiro.lang.codec.Base64; -import org.apache.shiro.config.ConfigurationException; -import org.apache.shiro.config.Ini; -import org.apache.shiro.guice.web.ShiroWebModule; -import org.apache.shiro.realm.text.IniRealm; -import org.apache.shiro.web.mgt.CookieRememberMeManager; -import org.apache.shiro.web.mgt.DefaultWebSecurityManager; -import org.apache.shiro.web.mgt.WebSecurityManager; - -import jakarta.inject.Singleton; -import jakarta.servlet.ServletContext; -import java.net.MalformedURLException; -import java.net.URL; - -public class SampleShiroServletModule extends ShiroWebModule { - private final ServletContext servletContext; - - public SampleShiroServletModule(ServletContext servletContext) { - super(servletContext); - - this.servletContext = servletContext; - } - - @Override - protected void configureShiroWeb() { - bindConstant().annotatedWith(Names.named("shiro.loginUrl")).to("/login.jsp"); - try { - this.bindRealm().toConstructor(IniRealm.class.getConstructor(Ini.class)); - } catch (NoSuchMethodException e) { - addError("Could not locate proper constructor for IniRealm.", e); - } - - this.addFilterChain("/login.jsp", AUTHC); - this.addFilterChain("/logout", LOGOUT); - this.addFilterChain("/account/**", AUTHC); - - this.addFilterChain("/remoting/**", - filterConfig(AUTHC), - filterConfig(ROLES, "b2bClient"), - filterConfig(PERMS, "remote:invoke:lan,wan")); - } - - @Provides - @Singleton - Ini loadShiroIni() throws MalformedURLException { - URL iniUrl = servletContext.getResource("/WEB-INF/shiro.ini"); - return Ini.fromResourcePath("url:" + iniUrl.toExternalForm()); - } - - @Override - protected void bindWebSecurityManager(AnnotatedBindingBuilder<? super WebSecurityManager> bind) { - try { - String cipherKey = loadShiroIni().getSectionProperty("main", "securityManager.rememberMeManager.cipherKey"); - - DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager(); - CookieRememberMeManager rememberMeManager = new CookieRememberMeManager(); - rememberMeManager.setCipherKey(Base64.decode(cipherKey)); - securityManager.setRememberMeManager(rememberMeManager); - bind.toInstance(securityManager); - } catch (MalformedURLException e) { - // for now just throw, you could just call - // super.bindWebSecurityManager(bind) if you do not need rememberMe functionality - throw new ConfigurationException("securityManager.rememberMeManager.cipherKey must be set in shiro.ini."); - } - - - } -} diff --git a/integration-tests/guice4/src/main/resources/log4j2.xml b/integration-tests/guice4/src/main/resources/log4j2.xml deleted file mode 100644 index e0b3288f5..000000000 --- a/integration-tests/guice4/src/main/resources/log4j2.xml +++ /dev/null @@ -1,68 +0,0 @@ -<!-- - ~ 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. - --> - -<Configuration name="ConfigTest" status="ERROR" monitorInterval="5"> - <!-- - ~ 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. - --> - - <Appenders> - <Console name="Console" target="SYSTEM_OUT"> - <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> - </Console> - </Appenders> - <Loggers> - <Logger name="org.quartz" level="warn" additivity="false"> - <AppenderRef ref="Console"/> - </Logger> - <Logger name="org.apache" level="warn" additivity="false"> - <AppenderRef ref="Console"/> - </Logger> - <Logger name="net.sf.ehcache" level="warn" additivity="false"> - <AppenderRef ref="Console"/> - </Logger> - <Logger name="org.apache.shiro" level="info" additivity="false"> - <AppenderRef ref="Console"/> - </Logger> - <Logger name="org.apache.shiro.util.ThreadContext" level="info" additivity="false"> - <AppenderRef ref="Console"/> - </Logger> - <Logger name="org.eclipse.jetty.annotations.AnnotationParser" level="error" additivity="false"> - <AppenderRef ref="Console"/> - </Logger> - <Root level="info"> - <AppenderRef ref="Console"/> - </Root> - </Loggers> -</Configuration> diff --git a/integration-tests/guice4/src/main/webapp/WEB-INF/shiro.ini b/integration-tests/guice4/src/main/webapp/WEB-INF/shiro.ini deleted file mode 100644 index 18bb0dff7..000000000 --- a/integration-tests/guice4/src/main/webapp/WEB-INF/shiro.ini +++ /dev/null @@ -1,53 +0,0 @@ -# -# 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. -# - -# INI configuration is very powerful and flexible, while still remaining succinct. -# Please https://shiro.apache.org/configuration.html and -# https://shiro.apache.org/web.html for more. - -[main] -shiro.loginUrl = /login.jsp - -# We need to set the cipherKey, if you want the rememberMe cookie to work after restarting or on multiple nodes. -# YOU MUST SET THIS TO A UNIQUE STRING -securityManager.rememberMeManager.cipherKey = kPH+bIxk5D2deZiIxcaaaA== - -[users] -# format: username = password, role1, role2, ..., roleN -root = secret,admin -guest = guest,guest -presidentskroob = 12345,president -darkhelmet = ludicrousspeed,darklord,schwartz -lonestarr = vespa,goodguy,schwartz - -[roles] -# format: roleName = permission1, permission2, ..., permissionN -admin = * -schwartz = lightsaber:* -goodguy = winnebago:drive:eagle5 - -[urls] -# The /login.jsp is not restricted to authenticated users (otherwise no one could log in!), but -# the 'authc' filter must still be specified for it so it can process that url's -# login submissions. It is 'smart' enough to allow those requests through as specified by the -# shiro.loginUrl above. -/login.jsp = authc -/logout = logout -/account/** = authc -/remoting/** = authc, roles[b2bClient], perms["remote:invoke:lan,wan"] diff --git a/integration-tests/guice4/src/main/webapp/WEB-INF/web.xml b/integration-tests/guice4/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 64681aec7..000000000 --- a/integration-tests/guice4/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,43 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ 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. - --> -<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd" - version="6.0"> - - <listener> - <listener-class>org.apache.shiro.samples.guice.SampleShiroGuiceBootstrap</listener-class> - </listener> - - <filter> - <filter-name>GuiceFilter</filter-name> - <filter-class>com.google.inject.servlet.GuiceFilter</filter-class> - </filter> - - <filter-mapping> - <filter-name>GuiceFilter</filter-name> - <url-pattern>/*</url-pattern> - </filter-mapping> - - <welcome-file-list> - <welcome-file>index.jsp</welcome-file> - </welcome-file-list> - -</web-app> diff --git a/integration-tests/guice4/src/main/webapp/account/index.jsp b/integration-tests/guice4/src/main/webapp/account/index.jsp deleted file mode 100644 index 013b21a8b..000000000 --- a/integration-tests/guice4/src/main/webapp/account/index.jsp +++ /dev/null @@ -1,36 +0,0 @@ -<%-- - ~ 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. - --%> -<%@ include file="../include.jsp" %> - -<html> -<head> - <link type="text/css" rel="stylesheet" href="<c:url value="/style.css"/>"/> -</head> -<body> - -<h2>Users only</h2> - -<p>You are currently logged in.</p> - -<p><a href="<c:url value="/home.jsp"/>">Return to the home page.</a></p> - -<p><a href="<c:url value="/logout"/>">Log out.</a></p> - -</body> -</html> diff --git a/integration-tests/guice4/src/main/webapp/home.jsp b/integration-tests/guice4/src/main/webapp/home.jsp deleted file mode 100644 index 61dee2552..000000000 --- a/integration-tests/guice4/src/main/webapp/home.jsp +++ /dev/null @@ -1,69 +0,0 @@ -<%-- - ~ 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. - --%> -<%@ include file="include.jsp" %> - -<html> -<head> - <link type="text/css" rel="stylesheet" href="<c:url value="/style.css"/>"/> - <title>Apache Shiro Quickstart</title> -</head> -<body> - -<h1>Apache Shiro Quickstart</h1> - -<p>Hi <shiro:guest>Guest</shiro:guest><shiro:user><shiro:principal/></shiro:user>! - ( <shiro:user><a href="<c:url value="/logout"/>">Log out</a></shiro:user> - <shiro:guest><a href="<c:url value="/login.jsp"/>">Log in</a> (sample accounts provided)</shiro:guest> ) -</p> - -<p>Welcome to the Apache Shiro Quickstart sample application. - This page represents the home page of any web application.</p> - -<shiro:user><p>Visit your <a href="<c:url value="/account"/>">account page</a>.</p></shiro:user> -<shiro:guest><p>If you want to access the user-only <a href="<c:url value="/account"/>">account page</a>, - you will need to log-in first.</p></shiro:guest> - -<h2>Roles</h2> - -<p>To show some taglibs, here are the roles you have and don't have. Log out and log back in under different user - accounts to see different roles.</p> - -<h3>Roles you have</h3> - -<p> - <shiro:hasRole name="admin">admin<br/></shiro:hasRole> - <shiro:hasRole name="president">president<br/></shiro:hasRole> - <shiro:hasRole name="darklord">darklord<br/></shiro:hasRole> - <shiro:hasRole name="goodguy">goodguy<br/></shiro:hasRole> - <shiro:hasRole name="schwartz">schwartz<br/></shiro:hasRole> -</p> - -<h3>Roles you DON'T have</h3> - -<p> - <shiro:lacksRole name="admin">admin<br/></shiro:lacksRole> - <shiro:lacksRole name="president">president<br/></shiro:lacksRole> - <shiro:lacksRole name="darklord">darklord<br/></shiro:lacksRole> - <shiro:lacksRole name="goodguy">goodguy<br/></shiro:lacksRole> - <shiro:lacksRole name="schwartz">schwartz<br/></shiro:lacksRole> -</p> - - -</body> -</html> diff --git a/integration-tests/guice4/src/main/webapp/include.jsp b/integration-tests/guice4/src/main/webapp/include.jsp deleted file mode 100644 index 8472daca1..000000000 --- a/integration-tests/guice4/src/main/webapp/include.jsp +++ /dev/null @@ -1,22 +0,0 @@ -<%-- - ~ 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. - --%> -<%@ page import="org.apache.shiro.SecurityUtils" %> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> -<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> -<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %> diff --git a/integration-tests/guice4/src/main/webapp/index.jsp b/integration-tests/guice4/src/main/webapp/index.jsp deleted file mode 100644 index ec60ad16c..000000000 --- a/integration-tests/guice4/src/main/webapp/index.jsp +++ /dev/null @@ -1,21 +0,0 @@ -<%-- - ~ 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. - --%> - -<%-- Forward the user to the home page --%> -<jsp:forward page="home.jsp"/> diff --git a/integration-tests/guice4/src/main/webapp/login.jsp b/integration-tests/guice4/src/main/webapp/login.jsp deleted file mode 100644 index c80ee54c8..000000000 --- a/integration-tests/guice4/src/main/webapp/login.jsp +++ /dev/null @@ -1,110 +0,0 @@ -<%-- - ~ 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. - --%> -<%@ include file="include.jsp" %> - -<html> -<head> - <link type="text/css" rel="stylesheet" href="<c:url value="/style.css"/>"/> -</head> -<body> - -<h2>Please Log in</h2> - -<shiro:guest> - <p>Here are a few sample accounts to play with in the default text-based Realm (used for this - demo and test installs only). Do you remember the movie these names came from? ;)</p> - - - <style type="text/css"> - table.sample { - border-width: 1px; - border-style: outset; - border-color: blue; - border-collapse: separate; - background-color: rgb(255, 255, 240); - } - - table.sample th { - border-width: 1px; - padding: 1px; - border-style: none; - border-color: blue; - background-color: rgb(255, 255, 240); - } - - table.sample td { - border-width: 1px; - padding: 1px; - border-style: none; - border-color: blue; - background-color: rgb(255, 255, 240); - } - </style> - - - <table class="sample"> - <thead> - <tr> - <th>Username</th> - <th>Password</th> - </tr> - </thead> - <tbody> - <tr> - <td>root</td> - <td>secret</td> - </tr> - <tr> - <td>presidentskroob</td> - <td>12345</td> - </tr> - <tr> - <td>darkhelmet</td> - <td>ludicrousspeed</td> - </tr> - <tr> - <td>lonestarr</td> - <td>vespa</td> - </tr> - </tbody> - </table> - <br/><br/> -</shiro:guest> - -<form name="loginform" action="" method="post"> - <table align="left" border="0" cellspacing="0" cellpadding="3"> - <tr> - <td>Username:</td> - <td><input type="text" name="username" maxlength="30"></td> - </tr> - <tr> - <td>Password:</td> - <td><input type="password" name="password" maxlength="30"></td> - </tr> - <tr> - <td colspan="2" align="left"><input type="checkbox" name="rememberMe"><font size="2">Remember Me</font></td> - </tr> - <tr> - <td colspan="2" align="right"><input type="submit" name="submit" value="Login"></td> - </tr> - </table> -</form> - -</body> -</html> diff --git a/integration-tests/guice4/src/main/webapp/style.css b/integration-tests/guice4/src/main/webapp/style.css deleted file mode 100644 index c3e3944cf..000000000 --- a/integration-tests/guice4/src/main/webapp/style.css +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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. - */ -body { - margin: 15px 0 0 15px; - padding: 1px; /*background: #2370cf;*/ - font: 12px 'Lucida Grande', Geneva, Verdana, Arial, sans-serif; - color: #000; -} - -table, td { - font: 12px 'Lucida Grande', Geneva, Verdana, Arial, sans-serif; - color: #000; -} - -h1 { - font: 24px; -} - -img { - border: thin black solid; -} - -#contentBox { - text-align: center; - width: 50%; - margin: auto; - margin-top: 50px; - color: black; - background: #eee; - border: thick black solid; -} diff --git a/integration-tests/guice4/src/test/java/org/apache/shiro/samples/guice/ContainerIntegrationIT.java b/integration-tests/guice4/src/test/java/org/apache/shiro/samples/guice/ContainerIntegrationIT.java deleted file mode 100644 index 550b9e229..000000000 --- a/integration-tests/guice4/src/test/java/org/apache/shiro/samples/guice/ContainerIntegrationIT.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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.shiro.samples.guice; - -import org.apache.shiro.testing.web.AbstractContainerIT; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.htmlunit.ElementNotFoundException; -import org.htmlunit.FailingHttpStatusCodeException; -import org.htmlunit.WebAssert; -import org.htmlunit.html.HtmlCheckBoxInput; -import org.htmlunit.html.HtmlForm; -import org.htmlunit.html.HtmlPage; - -import java.io.IOException; -import java.net.MalformedURLException; - -public class ContainerIntegrationIT extends AbstractContainerIT { - - @BeforeEach - public void logOut() throws IOException { - // Make sure we are logged out - final HtmlPage homePage = webClient.getPage(getBaseUri()); - try { - homePage.getAnchorByHref("/logout").click(); - } catch (ElementNotFoundException e) { - //Ignore - } - } - - @Test - void logIn() throws FailingHttpStatusCodeException, MalformedURLException, IOException, InterruptedException { - - HtmlPage page = webClient.getPage(getBaseUri() + "login.jsp"); - HtmlForm form = page.getFormByName("loginform"); - form.getInputByName("username").setValueAttribute("root"); - form.getInputByName("password").setValueAttribute("secret"); - page = form.getInputByName("submit").click(); - // This'll throw an exception if not logged in - page.getAnchorByHref("/logout"); - } - - @Test - void logInAndRememberMe() throws Exception { - HtmlPage page = webClient.getPage(getBaseUri() + "login.jsp"); - HtmlForm form = page.getFormByName("loginform"); - form.getInputByName("username").setValueAttribute("root"); - form.getInputByName("password").setValueAttribute("secret"); - HtmlCheckBoxInput checkbox = form.getInputByName("rememberMe"); - checkbox.setChecked(true); - page = form.getInputByName("submit").click(); - jetty.stop(); - jetty.start(); - page = webClient.getPage(getBaseUri()); - // page.getAnchorByHref("/logout"); - WebAssert.assertLinkPresentWithText(page, "Log out"); - page = page.getAnchorByHref("/account").click(); - // login page should be shown again - user remembered but not authenticated - WebAssert.assertFormPresent(page, "loginform"); - } - -} diff --git a/samples/spring-mvc/src/main/java/org/apache/shiro/samples/spring/config/RemotingServletConfig.java b/samples/spring-mvc/src/main/java/org/apache/shiro/samples/spring/config/RemotingServletConfig.java deleted file mode 100644 index 403f0761b..000000000 --- a/samples/spring-mvc/src/main/java/org/apache/shiro/samples/spring/config/RemotingServletConfig.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.shiro.samples.spring.config; - -import org.apache.shiro.samples.spring.SampleManager; -import org.apache.shiro.spring.remoting.SecureRemoteInvocationExecutor; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter; - -/** - * Remoting bean definitions. - */ -@Configuration -@ComponentScan("org.apache.shiro.samples.spring") -public class RemotingServletConfig { - - @Bean(name = "/sampleManager") - @SuppressWarnings("deprecation") - public HttpInvokerServiceExporter accountServiceExporter(SampleManager sampleManager, - SecureRemoteInvocationExecutor secureRemoteInvocationExecutor) { - - HttpInvokerServiceExporter httpInvokerServiceExporter = new HttpInvokerServiceExporter(); - httpInvokerServiceExporter.setService(sampleManager); - httpInvokerServiceExporter.setServiceInterface(SampleManager.class); - httpInvokerServiceExporter.setRemoteInvocationExecutor(secureRemoteInvocationExecutor); - return httpInvokerServiceExporter; - } -} diff --git a/samples/web-jakarta/src/main/resources/log4j2.xml b/samples/web-jakarta/src/main/resources/log4j2.xml index a91b7f33e..4dea7a8b6 100644 --- a/samples/web-jakarta/src/main/resources/log4j2.xml +++ b/samples/web-jakarta/src/main/resources/log4j2.xml @@ -49,7 +49,7 @@ <Logger name="org.apache" level="warn" additivity="false"> <AppenderRef ref="Console"/> </Logger> - <Logger name="net.sf.ehcache" level="warn" additivity="false"> + <Logger name="org.ehcache" level="warn" additivity="false"> <AppenderRef ref="Console"/> </Logger> <Logger name="org.quartz" level="warn" additivity="false"> diff --git a/samples/web-jakarta/src/test/resources/log4j2.xml b/samples/web-jakarta/src/test/resources/log4j2.xml index 6fa211e03..2dde25ba4 100644 --- a/samples/web-jakarta/src/test/resources/log4j2.xml +++ b/samples/web-jakarta/src/test/resources/log4j2.xml @@ -30,7 +30,7 @@ <Logger name="org.apache" level="warn" additivity="false"> <AppenderRef ref="Console"/> </Logger> - <Logger name="net.sf.ehcache" level="warn" additivity="false"> + <Logger name="org.ehcache" level="warn" additivity="false"> <AppenderRef ref="Console"/> </Logger> <Logger name="org.quartz" level="warn" additivity="false"> diff --git a/support/ehcache/src/main/java/org/apache/shiro/cache/ehcache/EhCache.java b/support/ehcache/src/main/java/org/apache/shiro/cache/ehcache/EhCache.java index a13888777..358eb3923 100644 --- a/support/ehcache/src/main/java/org/apache/shiro/cache/ehcache/EhCache.java +++ b/support/ehcache/src/main/java/org/apache/shiro/cache/ehcache/EhCache.java @@ -18,7 +18,7 @@ */ package org.apache.shiro.cache.ehcache; -import net.sf.ehcache.Element; +import java.util.LinkedList; import org.apache.shiro.cache.Cache; import org.apache.shiro.cache.CacheException; import org.slf4j.Logger; @@ -33,7 +33,7 @@ import java.util.Set; /** - * Shiro {@link org.apache.shiro.cache.Cache} implementation that wraps an {@link net.sf.ehcache.Ehcache} instance. + * Shiro {@link org.apache.shiro.cache.Cache} implementation that wraps an {@link org.ehcache.core.Ehcache} instance. * * @param <K> K * @param <V> V @@ -49,14 +49,14 @@ public class EhCache<K, V> implements Cache<K, V> { /** * The wrapped Ehcache instance. */ - private net.sf.ehcache.Ehcache cache; + private org.ehcache.Cache<K, V> cache; /** * Constructs a new EhCache instance with the given cache. * * @param cache - delegate EhCache instance this Shiro cache instance will wrap. */ - public EhCache(net.sf.ehcache.Ehcache cache) { + public EhCache(org.ehcache.Cache<K, V> cache) { if (cache == null) { throw new IllegalArgumentException("Cache argument cannot be null."); } @@ -69,23 +69,22 @@ public class EhCache<K, V> implements Cache<K, V> { * @param key the key of the element to return. * @return The value placed into the cache with an earlier put, or null if not found or expired */ - @SuppressWarnings("unchecked") public V get(K key) throws CacheException { try { if (LOGGER.isTraceEnabled()) { - LOGGER.trace("Getting object from cache [" + cache.getName() + "] for key [" + key + "]"); + LOGGER.trace("Getting object from cache [{}] for key [{}]", cache, key); } if (key == null) { return null; } else { - Element element = cache.get(key); + V element = cache.get(key); if (element == null) { if (LOGGER.isTraceEnabled()) { - LOGGER.trace("Element for [" + key + "] is null."); + LOGGER.trace("Element for [{}] is null.", key); } return null; } else { - return (V) element.getObjectValue(); + return element; } } } catch (Throwable t) { @@ -101,12 +100,11 @@ public class EhCache<K, V> implements Cache<K, V> { */ public V put(K key, V value) throws CacheException { if (LOGGER.isTraceEnabled()) { - LOGGER.trace("Putting object in cache [" + cache.getName() + "] for key [" + key + "]"); + LOGGER.trace("Putting object in cache [{}] for key [{}]", cache, key); } try { V previous = get(key); - Element element = new Element(key, value); - cache.put(element); + cache.put(key, value); return previous; } catch (Throwable t) { throw new CacheException(t); @@ -122,7 +120,7 @@ public class EhCache<K, V> implements Cache<K, V> { */ public V remove(K key) throws CacheException { if (LOGGER.isTraceEnabled()) { - LOGGER.trace("Removing object from cache [" + cache.getName() + "] for key [" + key + "]"); + LOGGER.trace("Removing object from cache [{}] for key [{}]", cache, key); } try { V previous = get(key); @@ -138,10 +136,10 @@ public class EhCache<K, V> implements Cache<K, V> { */ public void clear() throws CacheException { if (LOGGER.isTraceEnabled()) { - LOGGER.trace("Clearing all objects from cache [" + cache.getName() + "]"); + LOGGER.trace("Clearing all objects from cache [{}]", cache); } try { - cache.removeAll(); + cache.removeAll(keys()); } catch (Throwable t) { throw new CacheException(t); } @@ -149,7 +147,11 @@ public class EhCache<K, V> implements Cache<K, V> { public int size() { try { - return cache.getSize(); + int size = 0; + for (org.ehcache.Cache.Entry<K, V> ignored : cache) { + size++; + } + return size; } catch (Throwable t) { throw new CacheException(t); } @@ -157,10 +159,13 @@ public class EhCache<K, V> implements Cache<K, V> { public Set<K> keys() { try { - @SuppressWarnings({"unchecked"}) - List<K> keys = cache.getKeys(); + List<K> keys = new LinkedList<>(); + for (org.ehcache.Cache.Entry<K, V> entry : cache) { + keys.add(entry.getKey()); + } + if (!isEmpty(keys)) { - return Collections.unmodifiableSet(new LinkedHashSet<K>(keys)); + return Collections.unmodifiableSet(new LinkedHashSet<>(keys)); } else { return Collections.emptySet(); } @@ -171,10 +176,9 @@ public class EhCache<K, V> implements Cache<K, V> { public Collection<V> values() { try { - @SuppressWarnings({"unchecked"}) - List<K> keys = cache.getKeys(); + Set<K> keys = keys(); if (!isEmpty(keys)) { - List<V> values = new ArrayList<V>(keys.size()); + List<V> values = new ArrayList<>(keys.size()); for (K key : keys) { V value = get(key); if (value != null) { @@ -198,11 +202,7 @@ public class EhCache<K, V> implements Cache<K, V> { * number is unknown or cannot be calculated. */ public long getMemoryUsage() { - try { - return cache.calculateInMemorySize(); - } catch (Throwable t) { - return -1; - } + return -1; } /** @@ -213,11 +213,7 @@ public class EhCache<K, V> implements Cache<K, V> { * that number is unknown or cannot be calculated. */ public long getMemoryStoreSize() { - try { - return cache.getMemoryStoreSize(); - } catch (Throwable t) { - throw new CacheException(t); - } + return -1; } /** @@ -228,20 +224,16 @@ public class EhCache<K, V> implements Cache<K, V> { * that number is unknown or cannot be calculated. */ public long getDiskStoreSize() { - try { - return cache.getDiskStoreSize(); - } catch (Throwable t) { - throw new CacheException(t); - } + return -1; } /** - * Returns "EhCache [" + cache.getName() + "]" + * Returns "EhCache [" + cache + "]" * - * @return "EhCache [" + cache.getName() + "]" + * @return "EhCache [" + cache + "]" */ public String toString() { - return "EhCache [" + cache.getName() + "]"; + return "EhCache [" + cache + "]"; } ////////////////////////// @@ -249,7 +241,7 @@ public class EhCache<K, V> implements Cache<K, V> { ////////////////////////// // CollectionUtils cannot be removed from shiro-core until 2.0 as it has a dependency on PrincipalCollection - private static boolean isEmpty(Collection c) { + private static boolean isEmpty(Collection<?> c) { return c == null || c.isEmpty(); } } diff --git a/support/ehcache/src/main/java/org/apache/shiro/cache/ehcache/EhCacheManager.java b/support/ehcache/src/main/java/org/apache/shiro/cache/ehcache/EhCacheManager.java index eb4518878..985276bea 100644 --- a/support/ehcache/src/main/java/org/apache/shiro/cache/ehcache/EhCacheManager.java +++ b/support/ehcache/src/main/java/org/apache/shiro/cache/ehcache/EhCacheManager.java @@ -18,12 +18,17 @@ */ package org.apache.shiro.cache.ehcache; +import java.io.Serializable; +import java.net.URL; import org.apache.shiro.cache.Cache; import org.apache.shiro.cache.CacheException; import org.apache.shiro.cache.CacheManager; import org.apache.shiro.lang.io.ResourceUtils; import org.apache.shiro.lang.util.Destroyable; import org.apache.shiro.lang.util.Initializable; +import org.ehcache.config.CacheConfiguration; +import org.ehcache.config.builders.CacheManagerBuilder; +import org.ehcache.xml.XmlConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,17 +38,17 @@ import java.io.InputStream; /** * Shiro {@code CacheManager} implementation utilizing the Ehcache framework for all cache functionality. * <p/> - * This class can {@link #setCacheManager(net.sf.ehcache.CacheManager) accept} a manually configured - * {@link net.sf.ehcache.CacheManager net.sf.ehcache.CacheManager} instance, + * This class can {@link #setCacheManager(org.ehcache.CacheManager) accept} a manually configured + * {@link org.ehcache.CacheManager org.ehcache.CacheManager} instance, * or an {@code ehcache.xml} path location can be specified instead and one will be constructed. If neither are * specified, Shiro's failsafe <code><a href="./ehcache.xml">ehcache.xml</a></code> file will be used by default. * <p/> * This implementation requires EhCache 1.2 and above. Make sure EhCache 1.1 or earlier * is not in the classpath or it will not work. * <p/> - * Please see the <a href="http://ehcache.sf.net" target="_top">Ehcache website</a> for their documentation. + * Please see the <a href="http://ehcache.org" target="_top">Ehcache website</a> for their documentation. * - * @see <a href="http://ehcache.sf.net" target="_top">The Ehcache website</a> + * @see <a href="http://ehcache.org" target="_top">The Ehcache website</a> * @since 0.2 */ public class EhCacheManager implements CacheManager, Initializable, Destroyable { @@ -56,7 +61,7 @@ public class EhCacheManager implements CacheManager, Initializable, Destroyable /** * The EhCache cache manager used by this implementation to create caches. */ - protected net.sf.ehcache.CacheManager manager; + protected org.ehcache.CacheManager manager; /** * Indicates if the CacheManager instance was implicitly/automatically created by this instance, indicating that @@ -76,20 +81,20 @@ public class EhCacheManager implements CacheManager, Initializable, Destroyable } /** - * Returns the wrapped Ehcache {@link net.sf.ehcache.CacheManager CacheManager} instance. + * Returns the wrapped Ehcache {@link org.ehcache.CacheManager CacheManager} instance. * - * @return the wrapped Ehcache {@link net.sf.ehcache.CacheManager CacheManager} instance. + * @return the wrapped Ehcache {@link org.ehcache.CacheManager CacheManager} instance. */ - public net.sf.ehcache.CacheManager getCacheManager() { + public org.ehcache.CacheManager getCacheManager() { return manager; } /** - * Sets the wrapped Ehcache {@link net.sf.ehcache.CacheManager CacheManager} instance. + * Sets the wrapped Ehcache {@link org.ehcache.CacheManager CacheManager} instance. * - * @param manager the wrapped Ehcache {@link net.sf.ehcache.CacheManager CacheManager} instance. + * @param manager the wrapped Ehcache {@link org.ehcache.CacheManager CacheManager} instance. */ - public void setCacheManager(net.sf.ehcache.CacheManager manager) { + public void setCacheManager(org.ehcache.CacheManager manager) { this.manager = manager; } @@ -140,37 +145,58 @@ public class EhCacheManager implements CacheManager, Initializable, Destroyable } } + /** + * Acquires the URL for the ehcache configuration file using + * {@link ResourceUtils#getURLForPath(String) ResourceUtils.getURLForPath} with the + * path returned from {@link #getCacheManagerConfigFile() getCacheManagerConfigFile()}. + * + * @return the URL for the ehcache configuration file. + */ + protected URL getCacheManagerConfigFileUrl() { + final var configFile = getCacheManagerConfigFile(); + try { + return ResourceUtils.getURLForPath(configFile); + } catch (IOException e) { + throw new IllegalStateException("Unable to parse cacheManagerConfigFile [" + + configFile + "]", e); + } + } + /** * Loads an existing EhCache from the cache manager, or starts a new cache if one is not found. * * @param name the name of the cache to load/create. */ - public final <K, V> Cache<K, V> getCache(String name) throws CacheException { + @Override + public final <K, V> Cache<K, V> getCache(String name) + throws CacheException { if (LOGGER.isTraceEnabled()) { - LOGGER.trace("Acquiring EhCache instance named [" + name + "]"); + LOGGER.trace("Acquiring EhCache instance named [{}]", name); } try { - net.sf.ehcache.Ehcache cache = ensureCacheManager().getEhcache(name); + org.ehcache.Cache<K, V> cache = (org.ehcache.Cache<K, V>) ensureCacheManager() + .getCache(name, Serializable.class, Serializable.class); if (cache == null) { if (LOGGER.isInfoEnabled()) { LOGGER.info("Cache with name '{}' does not yet exist. Creating now.", name); } - this.manager.addCache(name); - - cache = manager.getCache(name); + CacheConfiguration<K, V> config = (CacheConfiguration<K, V>) new XmlConfiguration(getCacheManagerConfigFileUrl()) + .newCacheConfigurationBuilderFromTemplate("default", Serializable.class, Serializable.class) + .build(); + cache = manager.createCache(name, config); if (LOGGER.isInfoEnabled()) { - LOGGER.info("Added EhCache named [" + name + "]"); + LOGGER.info("Added EhCache named [{}]", name); } } else { if (LOGGER.isInfoEnabled()) { - LOGGER.info("Using existing EHCache named [" + cache.getName() + "]"); + LOGGER.info("Using existing EHCache named [{}]", name); } } - return new EhCache<K, V>(cache); - } catch (net.sf.ehcache.CacheException e) { + return new EhCache<>(cache); + } catch (IllegalArgumentException | IllegalStateException | ReflectiveOperationException e) { throw new CacheException(e); } } @@ -191,24 +217,21 @@ public class EhCacheManager implements CacheManager, Initializable, Destroyable * this case. * * @throws org.apache.shiro.cache.CacheException if there are any CacheExceptions thrown by EhCache. - * @see net.sf.ehcache.CacheManager#create + * @see org.ehcache.CacheManager#createCache(String, org.ehcache.config.CacheConfiguration) */ public final void init() throws CacheException { ensureCacheManager(); } - private net.sf.ehcache.CacheManager ensureCacheManager() { + private org.ehcache.CacheManager ensureCacheManager() { try { if (this.manager == null) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("cacheManager property not set. Constructing CacheManager instance... "); } - //using the CacheManager constructor, the resulting instance is _not_ a VM singleton - //(as would be the case by calling CacheManager.getInstance(). We do not use the getInstance here - //because we need to know if we need to destroy the CacheManager instance - using the static call, - //we don't know which component is responsible for shutting it down. By using a single EhCacheManager, - //it will always know to shut down the instance if it was responsible for creating it. - this.manager = new net.sf.ehcache.CacheManager(getCacheManagerConfigFileInputStream()); + final XmlConfiguration xmlConfig = new XmlConfiguration(getCacheManagerConfigFileUrl()); + this.manager = CacheManagerBuilder.newCacheManager(xmlConfig); + this.manager.init(); if (LOGGER.isTraceEnabled()) { LOGGER.trace("instantiated Ehcache CacheManager instance."); } @@ -233,8 +256,8 @@ public class EhCacheManager implements CacheManager, Initializable, Destroyable public void destroy() { if (cacheManagerImplicitlyCreated) { try { - net.sf.ehcache.CacheManager cacheMgr = getCacheManager(); - cacheMgr.shutdown(); + org.ehcache.CacheManager cacheMgr = getCacheManager(); + cacheMgr.close(); } catch (Throwable t) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("Unable to cleanly shutdown implicitly created CacheManager instance. " @@ -246,4 +269,5 @@ public class EhCacheManager implements CacheManager, Initializable, Destroyable } } } + } diff --git a/support/ehcache/src/main/resources/org/apache/shiro/cache/ehcache/ehcache.xml b/support/ehcache/src/main/resources/org/apache/shiro/cache/ehcache/ehcache.xml index dc310543c..e232e922f 100644 --- a/support/ehcache/src/main/resources/org/apache/shiro/cache/ehcache/ehcache.xml +++ b/support/ehcache/src/main/resources/org/apache/shiro/cache/ehcache/ehcache.xml @@ -16,7 +16,9 @@ ~ specific language governing permissions and limitations ~ under the License. --> -<ehcache> +<config xmlns="http://www.ehcache.org/v3" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.ehcache.org/v3 https://www.ehcache.org/schema/ehcache-core-3.3.xsd"> <!-- Sets the path to the directory where cache .data files are created. @@ -27,7 +29,7 @@ user.dir - User's current working directory java.io.tmpdir - Default temp file path --> - <diskStore path="java.io.tmpdir/shiro-ehcache"/> + <persistence directory="${java.io.tmpdir}/shiro-ehcache"/> <!--Default Cache configuration. These will applied to caches programmatically created through @@ -62,15 +64,12 @@ (specified as LFU) --> - <defaultCache - maxElementsInMemory="10000" - eternal="false" - timeToIdleSeconds="120" - timeToLiveSeconds="120" - overflowToDisk="false" - diskPersistent="false" - diskExpiryThreadIntervalSeconds="120" - /> + <cache-template name="default"> + <expiry> + <ttl>120</ttl> + </expiry> + <heap>10000</heap> + </cache-template> <!-- We want eternal="true" and no timeToIdle or timeToLive settings because Shiro manages session expirations explicitly. If we set it to false and then set corresponding timeToIdle and timeToLive properties, @@ -80,18 +79,28 @@ diskPersistent=true since we want an enterprise session management feature - ability to use sessions after even after a JVM restart. --> - <cache name="shiro-activeSessionCache" - maxElementsInMemory="10000" - overflowToDisk="true" - eternal="true" - timeToLiveSeconds="0" - timeToIdleSeconds="0" - diskPersistent="true" - diskExpiryThreadIntervalSeconds="600"/> + <cache alias="shiro-activeSessionCache"> + <key-type>java.io.Serializable</key-type> + <value-type>java.io.Serializable</value-type> + <expiry> + <none/> + </expiry> + <resources> + <heap>10000</heap> + <disk persistent="true" unit="MB">50</disk> + </resources> + </cache> - <cache name="org.apache.shiro.realm.text.PropertiesRealm-0-accounts" - maxElementsInMemory="1000" - eternal="true" - overflowToDisk="true"/> + <cache alias="org.apache.shiro.realm.text.PropertiesRealm-0-accounts"> + <key-type>java.io.Serializable</key-type> + <value-type>java.io.Serializable</value-type> + <expiry> + <none/> + </expiry> + <resources> + <heap>10000</heap> + <disk persistent="true" unit="MB">50</disk> + </resources> + </cache> -</ehcache> +</config> diff --git a/support/ehcache/src/test/java/org/apache/shiro/cache/ehcache/EhCacheManagerTest.java b/support/ehcache/src/test/java/org/apache/shiro/cache/ehcache/EhCacheManagerTest.java index 8bbef1272..1efcb201f 100644 --- a/support/ehcache/src/test/java/org/apache/shiro/cache/ehcache/EhCacheManagerTest.java +++ b/support/ehcache/src/test/java/org/apache/shiro/cache/ehcache/EhCacheManagerTest.java @@ -52,7 +52,7 @@ public class EhCacheManagerTest { @Test void testCacheManagerCreationDuringInit() { - net.sf.ehcache.CacheManager ehCacheManager = cacheManager.getCacheManager(); + org.ehcache.CacheManager ehCacheManager = cacheManager.getCacheManager(); assertThat(ehCacheManager).isNull(); cacheManager.init(); //now assert that an internal CacheManager has been created: @@ -62,7 +62,7 @@ public class EhCacheManagerTest { @Test void testLazyCacheManagerCreationWithoutCallingInit() { - net.sf.ehcache.CacheManager ehCacheManager = cacheManager.getCacheManager(); + org.ehcache.CacheManager ehCacheManager = cacheManager.getCacheManager(); assertThat(ehCacheManager).isNull(); //don't call init here - the ehcache CacheManager should be lazily created @@ -82,7 +82,7 @@ public class EhCacheManagerTest { @Test void testRemove() { - net.sf.ehcache.CacheManager ehCacheManager = cacheManager.getCacheManager(); + org.ehcache.CacheManager ehCacheManager = cacheManager.getCacheManager(); assertThat(ehCacheManager).isNull(); Cache<String, String> cache = cacheManager.getCache("test"); @@ -109,7 +109,7 @@ public class EhCacheManagerTest { @Test void testClear() { - net.sf.ehcache.CacheManager ehCacheManager = cacheManager.getCacheManager(); + org.ehcache.CacheManager ehCacheManager = cacheManager.getCacheManager(); assertThat(ehCacheManager).isNull(); Cache<String, String> cache = cacheManager.getCache("test"); @@ -134,7 +134,7 @@ public class EhCacheManagerTest { @Test void testKeys() { - net.sf.ehcache.CacheManager ehCacheManager = cacheManager.getCacheManager(); + org.ehcache.CacheManager ehCacheManager = cacheManager.getCacheManager(); assertThat(ehCacheManager).isNull(); Cache<String, String> cache = cacheManager.getCache("test"); @@ -168,7 +168,7 @@ public class EhCacheManagerTest { @Test void testValues() { - net.sf.ehcache.CacheManager ehCacheManager = cacheManager.getCacheManager(); + org.ehcache.CacheManager ehCacheManager = cacheManager.getCacheManager(); assertThat(ehCacheManager).isNull(); Cache<String, String> cache = cacheManager.getCache("test"); diff --git a/support/ehcache/src/test/resources/log4j2-test.xml b/support/ehcache/src/test/resources/log4j2-test.xml index f8c691e63..bd8c3cb39 100644 --- a/support/ehcache/src/test/resources/log4j2-test.xml +++ b/support/ehcache/src/test/resources/log4j2-test.xml @@ -46,7 +46,7 @@ <Logger name="org.apache" level="warn" additivity="false"> <AppenderRef ref="Console"/> </Logger> - <Logger name="net.sf.ehcache" level="warn" additivity="false"> + <Logger name="org.ehcache" level="warn" additivity="false"> <AppenderRef ref="Console"/> </Logger> <Logger name="org.apache.shiro" level="info" additivity="false"> diff --git a/support/jakarta-ee/src/main/java/org/apache/shiro/ee/util/JakartaTransformer.java b/support/jakarta-ee/src/main/java/org/apache/shiro/ee/util/JakartaTransformer.java deleted file mode 100644 index 8e7a0a6f9..000000000 --- a/support/jakarta-ee/src/main/java/org/apache/shiro/ee/util/JakartaTransformer.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed 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.shiro.ee.util; - -import java.util.regex.Pattern; -import jakarta.servlet.http.HttpServletRequest; - -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; - -/** - * transforms Java to Jakarta namespace - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -@SuppressWarnings("HideUtilityClassConstructor") -public class JakartaTransformer { - @Getter - @SuppressWarnings("ConstantName") - private static final boolean jakarta = HttpServletRequest.class.getPackageName().startsWith("jakarta"); - private static final Pattern REPLACE_JAVA_WITH_JAKARTA_PATTERN = Pattern.compile("javax\\.(\\w+)\\."); - - public static String jakartify(String className) { - return REPLACE_JAVA_WITH_JAKARTA_PATTERN.matcher(className).replaceAll( - isJakarta() ? "jakarta.$1." : "javax.$1."); - } -} diff --git a/support/spring/src/main/java/org/apache/shiro/spring/remoting/package-info.java b/support/spring/src/main/java/org/apache/shiro/spring/remoting/package-info.java deleted file mode 100644 index c6762a222..000000000 --- a/support/spring/src/main/java/org/apache/shiro/spring/remoting/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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. - */ -/** - * Support to enable Spring-based remote method invocations to carry a Shiro session ID as part of the - * invocation payload, allowing remote clients to perform security operations. - */ -package org.apache.shiro.spring.remoting;
