Skip to content

Commit

Permalink
restore Liferay 6.1+ compatibility, following #7
Browse files Browse the repository at this point in the history
  • Loading branch information
evernat committed Feb 24, 2017
1 parent a9c35bc commit 3f10953
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
liferay-javamelody
=========================

Plugin for JavaMelody to monitor performance in a [Liferay](http://www.liferay.com/) server 7.0 or later.
Plugin for JavaMelody to monitor performance in a [Liferay](http://www.liferay.com/) server 6.1 or later.

See https://github.com/javamelody/javamelody/wiki

Expand Down
19 changes: 10 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>net.bull.javamelody</groupId>
<artifactId>liferay-javamelody-hook</artifactId>
<version>1.64.0</version>
<version>1.63.1</version>
<packaging>war</packaging>

<name>Liferay JavaMelody Plugin</name>
Expand Down Expand Up @@ -61,8 +61,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -137,15 +137,16 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>com.liferay.portal.kernel</artifactId>
<version>2.21.0</version>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-service</artifactId>
<version>6.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.3</version>
<groupId>com.liferay.portal</groupId>
<artifactId>com.liferay.portal.kernel</artifactId>
<version>2.21.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
23 changes: 20 additions & 3 deletions src/main/java/net/bull/javamelody/LiferayMonitoringFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
* @author Emeric Vernat
*/
public class LiferayMonitoringFilter extends PluginMonitoringFilter {
private boolean liferay7;

/** {@inheritDoc} */
@Override
public String getApplicationType() {
Expand Down Expand Up @@ -106,8 +108,23 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
}

private boolean isAdmin(HttpServletRequest httpRequest) throws PortalException, SystemException {
final long userId = PortalUtil.getUserId(httpRequest);
final long companyId = PortalUtil.getDefaultCompanyId();
return UserLocalServiceUtil.hasRoleUser(companyId, RoleConstants.ADMINISTRATOR, userId, true);
try {
if (!liferay7) {
// for liferay 6
final long userId = com.liferay.portal.util.PortalUtil.getUserId(httpRequest);
final long companyId = com.liferay.portal.util.PortalUtil.getDefaultCompanyId();
return com.liferay.portal.service.UserLocalServiceUtil.hasRoleUser(companyId,
com.liferay.portal.model.RoleConstants.ADMINISTRATOR, userId, true);
}
} catch (final NoClassDefFoundError e) {
liferay7 = true;
}
if (liferay7) {
// for liferay 7
final long userId = PortalUtil.getUserId(httpRequest);
final long companyId = PortalUtil.getDefaultCompanyId();
return UserLocalServiceUtil.hasRoleUser(companyId, RoleConstants.ADMINISTRATOR, userId, true);
}
return false;
}
}
2 changes: 1 addition & 1 deletion src/main/webapp/WEB-INF/liferay-plugin-package.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ page-url=https://github.com/javamelody/javamelody/wiki
author=Emeric Vernat
licenses=ASL
# compatibility "6.1+" is currently like "6.1.1+,6.1.20+,6.2.0+" (6.1 CE GA2+,6.1 EE GA2+, and 6.2 CE GA1+)
liferay-versions=7.0.0+
liferay-versions=6.1+,7.0.0+

# security-manager required by the App Manager of Liferay Marketplace
#security-manager-enabled=true
Expand Down

0 comments on commit 3f10953

Please sign in to comment.