-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat/SessionReplicationAop #633
Open
mgillian
wants to merge
6
commits into
uPortal-Project:master
Choose a base branch
from
mgillian:feat/SessionReplicationAop
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e97fc9d
feat/SessionReplicationAop
f9c809f
Merge branch 'master' into feat/SessionReplicationAop
mgillian 213231b
feat/SessionReplicationAop refer to correct uPortal version
e7aeb5a
feat/SessionReplicationAop working version, everything located within…
mgillian ff3ca80
feat/SessionReplicationAop relocated property check to tomcatConfig t…
mgillian c136f21
feat/SessionReplicationAop fix bug in aop.gradle
mgillian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
|
||
buildscript { | ||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
} | ||
dependencies { | ||
} | ||
} | ||
|
||
plugins { | ||
id "io.freefair.aspectj.post-compile-weaving" version "5.3.3.3" | ||
} | ||
|
||
apply plugin: 'java' | ||
|
||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
} | ||
|
||
// Needed by aspectjweaver to prevent lint dependency failure | ||
configurations.testImplementation { | ||
exclude(group: "org.aspectj", module: "aspectjrt") | ||
} | ||
|
||
// Needed by aspectjweaver to prevent lint dependency failure | ||
configurations.runtimeOnly { | ||
exclude(group: "org.aspectj", module: "aspectjrt") | ||
} | ||
|
||
dependencies { | ||
// needs javax.mail.Authenticator for tomcat-embed-core | ||
compile("javax.mail:mail:1.4.7") | ||
|
||
// needed for the post-compile weaving of HttpSessionAspect | ||
// we assume that tomcat version for uPortal and uPortal-start projects | ||
// are the same. inpath() will create an exploded version of tomcat-embed-core | ||
// within the WEB-INFO/classes directory. The only class that is modified | ||
// is org.apache.catalina.session.StandardSessionFacade, which implements | ||
// HttpSession and is the primary class that calls HttpSession.setAttributes | ||
// uPortal-start will copy that class into the appropriate location for | ||
// uPortal-start's tomcat location | ||
compileOnly "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}" | ||
inpath "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}" | ||
} |
60 changes: 60 additions & 0 deletions
60
custom/aop/src/main/java/org/apereo/portal/context/HttpSessionAspect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* Licensed to Apereo under one or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information regarding copyright ownership. Apereo | ||
* 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 the | ||
* following location: | ||
* | ||
* <p>http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* <p>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.apereo.portal.context; | ||
|
||
import java.io.Serializable; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import org.aspectj.lang.JoinPoint; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.annotation.Before; | ||
|
||
/** | ||
* HttpSessionAspect is responsible for instrumenting classes that implement HttpSession with | ||
* logging data, to determine if the instance of HttpSession is trying to add a class that is not | ||
* serialzable to the session. HttpSessionAspect is not needed at this point for any production | ||
* functionality; it is only used to identify classes that need to be modified to be serializable. | ||
* | ||
* <p>This is class is being included in the uPortal-webapp package so that as part of the uPortal | ||
* gradle build, the needed classes are available as part of the uPortal packaging. uPortal-start | ||
* will then pull needed instrumented classes and include them in the appropriate place within the | ||
* tomcat instance. This assumes that uPortal-start is being used to manage the installation into | ||
* the appropriate tomcat server. | ||
* | ||
* @author mgillian | ||
*/ | ||
@Aspect | ||
public class HttpSessionAspect { | ||
private static final Logger log = Logger.getLogger(HttpSessionAspect.class.getName()); | ||
|
||
@Before("execution(* javax.servlet.http.HttpSession+.setAttribute(..))") | ||
public void loggingAdvice(JoinPoint joinPoint) { | ||
Object[] args = joinPoint.getArgs(); | ||
if (args.length < 2) { | ||
log.log(Level.SEVERE, "HttpSession.setAttribute does not have at least 2 parameters"); | ||
return; | ||
} | ||
|
||
// HttpSession.setAttribute takes two parameters: | ||
// key: a string name for the parameter, not important for this use case | ||
// value: the object to be stored, which must be serializable | ||
Object value = args[1]; | ||
if (!(value instanceof Serializable)) { | ||
log.log(Level.INFO, "value [" + value.getClass().getName() + "] is NOT serializable"); | ||
} else { | ||
log.log(Level.FINE, "value [" + value.getClass().getName() + "] is serializable"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# 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. | ||
|
||
handlers = 1catalina.org.apache.juli.AsyncFileHandler, 2localhost.org.apache.juli.AsyncFileHandler, 3manager.org.apache.juli.AsyncFileHandler, 4host-manager.org.apache.juli.AsyncFileHandler, 5aop-serializer.org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler | ||
|
||
.handlers = 1catalina.org.apache.juli.AsyncFileHandler, 5aop-serializer.org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler | ||
|
||
############################################################ | ||
# Handler specific properties. | ||
# Describes specific configuration info for Handlers. | ||
############################################################ | ||
|
||
1catalina.org.apache.juli.AsyncFileHandler.level = FINE | ||
1catalina.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs | ||
1catalina.org.apache.juli.AsyncFileHandler.prefix = catalina. | ||
1catalina.org.apache.juli.AsyncFileHandler.encoding = UTF-8 | ||
|
||
2localhost.org.apache.juli.AsyncFileHandler.level = FINE | ||
2localhost.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs | ||
2localhost.org.apache.juli.AsyncFileHandler.prefix = localhost. | ||
2localhost.org.apache.juli.AsyncFileHandler.encoding = UTF-8 | ||
|
||
3manager.org.apache.juli.AsyncFileHandler.level = FINE | ||
3manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs | ||
3manager.org.apache.juli.AsyncFileHandler.prefix = manager. | ||
3manager.org.apache.juli.AsyncFileHandler.encoding = UTF-8 | ||
|
||
4host-manager.org.apache.juli.AsyncFileHandler.level = FINE | ||
4host-manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs | ||
4host-manager.org.apache.juli.AsyncFileHandler.prefix = host-manager. | ||
4host-manager.org.apache.juli.AsyncFileHandler.encoding = UTF-8 | ||
|
||
java.util.logging.ConsoleHandler.level = FINE | ||
java.util.logging.ConsoleHandler.formatter = org.apache.juli.OneLineFormatter | ||
java.util.logging.ConsoleHandler.encoding = UTF-8 | ||
|
||
5aop-serializer.org.apache.juli.AsyncFileHandler.level = INFO | ||
5aop-serializer.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs | ||
5aop-serializer.org.apache.juli.AsyncFileHandler.prefix = aop-serializer. | ||
5aop-serializer.org.apache.juli.AsyncFileHandler.encoding = UTF-8 | ||
############################################################ | ||
# Facility specific properties. | ||
# Provides extra control for each logger. | ||
############################################################ | ||
|
||
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO | ||
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.AsyncFileHandler | ||
|
||
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFO | ||
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = 3manager.org.apache.juli.AsyncFileHandler | ||
|
||
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].level = INFO | ||
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers = 4host-manager.org.apache.juli.AsyncFileHandler | ||
|
||
org.apereo.portal.[Catalina].[localhost].[/aop-serializer].level = INFO | ||
org.apereo.portal.[Catalina].[localhost].[/aop-serializer].handlers = 5aop-serializer.org.apache.juli.AsyncFileHandler | ||
|
||
# For example, set the org.apache.catalina.util.LifecycleBase logger to log | ||
# each component that extends LifecycleBase changing state: | ||
#org.apache.catalina.util.LifecycleBase.level = FINE | ||
|
||
# To see debug messages in TldLocationsCache, uncomment the following line: | ||
#org.apache.jasper.compiler.TldLocationsCache.level = FINE | ||
|
||
# To see debug messages for HTTP/2 handling, uncomment the following line: | ||
#org.apache.coyote.http2.level = FINE | ||
|
||
# To see debug messages for WebSocket handling, uncomment the following line: | ||
#org.apache.tomcat.websocket.level = FINE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
} | ||
|
||
apply plugin: 'java' | ||
|
||
sourceSets { | ||
main { | ||
java { | ||
srcDirs = ["custom/aop/src/main/java", "custom/aop/src", "aop/src/main/java", "aop/src", "src/main/java", "src"] | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compileOnly "org.aspectj:aspectjrt:${aspectjVersion}" | ||
runtimeOnly 'org.aspectj:aspectjweaver:1.9.9.1' | ||
} | ||
|
||
/* | ||
* deployAopArchives is a custom task that moves HttpSession instrumented classes and needed | ||
* dependencies to the correct place within ./gradle/tomcat. There are three primary parts: | ||
* 1. Build a jar that contains two cusomt classes, HttpSessionAspect and StandardSessionFacade | ||
* and puts them into the .gradle/tomcat/lib folder in their own jar. HttpSession's implementing class | ||
* must be located in tomcat's lib folder or it won't be found, and the aspect must be with it. | ||
* 2. Put the aspectjweaver.1.9.9.1 jar in the same lib folder | ||
* 3. Update the catalina.jar that also lives in this lib folder by deleting the now duplicated | ||
* StandardSessionFacade. The current implementation creates a duplicate jar with the missing file | ||
* and deletes the original file to prevent conflict. Once this is done, it's hard to recover without | ||
* doing a tomcatInstall, so this may need additinoal work, if this function is run. | ||
* If this function is not run, uPortal on tomcat will run as normal. | ||
*/ | ||
task deployAopArchives() { | ||
dependsOn ':portalProperties' | ||
dependsOn ':downloadDependencies' | ||
dependsOn ':buildAopJar' | ||
dependsOn ':buildCatalinaAopJar' | ||
doLast { | ||
String serverHome = rootProject.ext['buildProperties'].getProperty('server.home') | ||
def path = "${project.projectDir}/custom/aop/build/runtime" | ||
copy { | ||
from path | ||
include "*.jar" | ||
into "${serverHome}/lib" | ||
} | ||
delete "${serverHome}/lib/catalina.jar" | ||
} | ||
} | ||
|
||
task downloadDependencies(type :Copy) { | ||
def path = "${project.projectDir}/custom/aop/build/runtime" | ||
from sourceSets.main.runtimeClasspath | ||
into path | ||
|
||
doFirst { | ||
ant.delete(dir: path) | ||
ant.mkdir(dir: path) | ||
} | ||
} | ||
|
||
task buildAopJar(type: Zip) { | ||
dependsOn ":custom:aop:compileJava" | ||
|
||
description 'Build AOP Archive for HttpSession testing' | ||
|
||
// def path = "${project.projectDir}/custom/aop/build/runtime" | ||
def path = "${project.projectDir}/custom/aop/build/classes/java/main" | ||
def destinationPath = "${project.projectDir}/custom/aop/build/runtime" | ||
from (path) { | ||
include("org/apereo/portal/context/HttpSessionAspect.class") | ||
include("org/apache/catalina/session/StandardSessionFacade.class") | ||
} | ||
archiveName 'uPortalAopArchive.jar' | ||
destinationDir(file(destinationPath)) | ||
} | ||
|
||
task buildCatalinaAopJar(type: Zip) { | ||
dependsOn ':tomcatInstall' | ||
// I'm not sure why, but :portalProperties does not expose server.home | ||
// like it does in other functions. This is directly related to type: Zip | ||
// in the function designation. If the tomcat server is located in another location, | ||
// this property will need to be updated | ||
String serverHome = ".gradle/tomcat" | ||
from zipTree("${serverHome}/lib/catalina.jar").matching { | ||
exclude 'org/apache/catalina/session/StandardSessionFacade.class' | ||
} | ||
archiveName 'catalina-aop.jar' | ||
destinationDir(file("${serverHome}/lib")) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the difference between a
handler
and a.handler
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logging.properties comes directly from apache tomcat (https://tomcat.apache.org/tomcat-8.0-doc/logging.html). I don't understand what each of the configurations are for; I just tried to follow the existing pattern. I saw that the other handlers had entries in both lists, so I added the new one to both lists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This configuration file isn't related to this feature and in my mind shouldn't be on this commit.
Tomcat logging shouldn't be provided in all case because it's a user customisation. In my case I prefer to keep default tomcat logging file.
Your purpose is to provide a rotation on tomcat catalina.out file, this rotation should be done by logrotate (or any other tool) and is an "OS dependancy". Or if you want a such change do a request on tomcat source, you will get their feed back about a such feature/need.