Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Commit

Permalink
* #53: Make Adam compatible with Confluence 5.9+
Browse files Browse the repository at this point in the history
* Do some cleanup issues
  • Loading branch information
blaubaer committed Mar 2, 2016
1 parent 36ce6ef commit 3b21533
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 58 deletions.
61 changes: 17 additions & 44 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ **** BEGIN LICENSE BLOCK *****
~
~ echocat Adam, Copyright (c) 2014 echocat
~ echocat Adam, Copyright (c) 2014-2016 echocat
~
~ This library is free software; you can redistribute it and/or
~ modify it under the terms of the GNU Lesser General Public
Expand All @@ -26,7 +26,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.echocat</groupId>
<artifactId>adam</artifactId>
<version>0.2.0</version>
<version>0.1.10</version>
<name>echocat Adam</name>
<packaging>atlassian-plugin</packaging>

Expand All @@ -35,13 +35,13 @@
</description>

<properties>
<version.org.echocat.jomon>1.4.3</version.org.echocat.jomon>
<version.org.echocat.jomon>1.5.0</version.org.echocat.jomon>
<version.org.javassist>3.18.1-GA</version.org.javassist>
<version.org.slf4j>1.7.5</version.org.slf4j>
<version.org.eclipse.persistence>2.5.1</version.org.eclipse.persistence>
<version.com.atlassian.confluence>5.8.13</version.com.atlassian.confluence>
<version.com.atlassian.confluence.data>5.8.13</version.com.atlassian.confluence.data>
<version.com.atlassian.maven.plugins.amps>4.2.10</version.com.atlassian.maven.plugins.amps>
<version.com.atlassian.confluence>5.9.5</version.com.atlassian.confluence>
<version.com.atlassian.confluence.data>5.9.5</version.com.atlassian.confluence.data>
<version.com.atlassian.maven.plugins.amps>6.2.2</version.com.atlassian.maven.plugins.amps>
<version.com.atlassian.plugins.testrunner>1.1.1</version.com.atlassian.plugins.testrunner>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
Expand Down Expand Up @@ -97,6 +97,12 @@
</dependency>

<!-- Confluence dependencies -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.0-b01</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.atlassian.confluence</groupId>
<artifactId>confluence</artifactId>
Expand Down Expand Up @@ -157,12 +163,6 @@
<version>${version.com.atlassian.confluence}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.atlassian.confluence.plugins</groupId>
<artifactId>confluence-soy</artifactId>
<version>${version.com.atlassian.confluence}</version>
<scope>provided</scope>
</dependency>

<!-- Testing -->
<dependency>
Expand Down Expand Up @@ -227,11 +227,15 @@
<httpPort>1990</httpPort>
<product>confluence</product>
<productVersion>${version.com.atlassian.confluence}</productVersion>
<enableDevToolbox>true</enableDevToolbox>
<enableDevToolbox>false</enableDevToolbox>
<allowGoogleTracking>false</allowGoogleTracking>
<installPlugin>true</installPlugin>
<instructions>
<Import-Package>
org.springframework.ldap.core;version=*,
com.atlassian.crowd.directory.ldap;version=*,
com.atlassian.crowd.directory.ldap.mapper;version=*,
com.atlassian.crowd.directory.ldap.mapper.attribute;version=*,
org.randombits.confluence.conveyor;version=*,
org.randombits.confluence.conveyor.xwork;version=*,
org.randombits.confluence.conveyor.condition;version=*
Expand Down Expand Up @@ -267,29 +271,9 @@
<checksumPolicy>warn</checksumPolicy>
</releases>
</repository>
<repository>
<id>echocat</id>
<url>http://repo.echocat.org/all</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>echocat</id>
<url>http://repo.echocat.org/all</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>atlassian-public</id>
<url>https://maven.atlassian.com/repository/public</url>
Expand All @@ -309,17 +293,6 @@
<url>https://github.com/echocat/adam/issues</url>
</issueManagement>

<distributionManagement>
<repository>
<id>echocat-adam-releases</id>
<url>dav:https://repo.echocat.org/adam-releases</url>
</repository>
<snapshotRepository>
<id>echocat-adam-snapshots</id>
<url>dav:https://repo.echocat.org/adam-snapshots</url>
</snapshotRepository>
</distributionManagement>

<scm>
<connection>scm:git:[email protected]:echocat/adam.git</connection>
<developerConnection>scm:git:[email protected]:echocat/adam.git</developerConnection>
Expand Down
52 changes: 47 additions & 5 deletions src/main/java/org/echocat/adam/directory/DirectoryHelper.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*****************************************************************************************
* *** BEGIN LICENSE BLOCK *****
*
* echocat Adam, Copyright (c) 2014 echocat
* echocat Adam, Copyright (c) 2014-2016 echocat
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand All @@ -28,7 +28,9 @@
import org.springframework.ldap.core.DirContextAdapter;

import javax.annotation.Nonnull;
import javax.naming.directory.Attribute;
import javax.annotation.Nullable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;

import static java.util.Collections.singleton;
Expand All @@ -38,13 +40,34 @@

public class DirectoryHelper {

private static final Method GET_ATTRIBUTES_OF_CONTEXTADAPTER_METHOD;
private static final Method GET_OF_ATTRIBUTES_METHOD;
private static final Method GET_OF_ATTRIBUTE_METHOD;

static {
final ClassLoader classLoader = AttributeMapper.class.getClassLoader();
try {
final Class<?> contextAdapterType = classLoader.loadClass("org.springframework.ldap.core.DirContextAdapter");
GET_ATTRIBUTES_OF_CONTEXTADAPTER_METHOD = contextAdapterType.getMethod("getAttributes");

final Class<?> attributesType = classLoader.loadClass("javax.naming.directory.Attributes");
GET_OF_ATTRIBUTES_METHOD = attributesType.getMethod("get", String.class);

final Class<?> attributeType = classLoader.loadClass("javax.naming.directory.Attribute");
GET_OF_ATTRIBUTE_METHOD = attributeType.getMethod("get");
} catch (final Exception e) {
throw new RuntimeException("Could not load required signatures from classpath. Did the API of confluence changed?", e);
}
}

@Nonnull
private final GroupProvider _groupProvider;

public DirectoryHelper(@Nonnull GroupProvider groupProvider) {
_groupProvider = groupProvider;
}

@SuppressWarnings("unused")
@Nonnull
public List<AttributeMapper> extendAttributeMappers(@Nonnull List<AttributeMapper> original) {
final List<AttributeMapper> result = new ArrayList<>(original);
Expand Down Expand Up @@ -76,6 +99,26 @@ public List<ElementModel> getAllElementModels() {
return asImmutableList(result);
}

@Nullable
private static Object getAttribute(@Nonnull Object context, @Nonnull String key) throws Exception {
// We have to do this ugly hack because of https://github.com/echocat/adam/issues/53
// It is not longer possible to easy access the DirContextAdapter class from plugins.
// So we do reflection access via classLoader of AttributeMapper class.
try {
final Object attributes = GET_ATTRIBUTES_OF_CONTEXTADAPTER_METHOD.invoke(context);
final Object attribute = attributes != null ? GET_OF_ATTRIBUTES_METHOD.invoke(attributes, key) : null;
return attribute != null ? GET_OF_ATTRIBUTE_METHOD.invoke(attribute) : null;
} catch (final InvocationTargetException e) {
final Throwable target = e.getTargetException();
if (target instanceof Exception) {
// noinspection ThrowInsideCatchBlockWhichIgnoresCaughtException
throw (Exception) target;
} else {
throw e;
}
}
}

protected class AttributeMapperImpl implements AttributeMapper {

@Nonnull
Expand All @@ -94,8 +137,7 @@ public String getKey() {
@Override
@Nonnull
public Set<String> getValues(@Nonnull DirContextAdapter context) throws Exception {
final Attribute attribute = context.getAttributes().get(getKey());
final Object value = attribute != null ? attribute.get() : null;
final Object value = getAttribute(context, getKey());
return value != null ? singleton(value.toString()) : Collections.<String>emptySet();
}

Expand All @@ -105,4 +147,4 @@ public Set<String> getRequiredLdapAttributes() {
return singleton(getKey());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*****************************************************************************************
* *** BEGIN LICENSE BLOCK *****
*
* echocat Adam, Copyright (c) 2014 echocat
* echocat Adam, Copyright (c) 2014-2016 echocat
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand All @@ -22,6 +22,7 @@
package org.echocat.adam.profile;

import com.atlassian.confluence.search.v2.AbstractChainableSearchFilter;
import com.atlassian.confluence.search.v2.SearchFilter;
import org.echocat.adam.report.Filter;
import org.echocat.adam.report.Report;

Expand Down Expand Up @@ -81,4 +82,8 @@ public String getKey() {
return "userProfileDataFilter";
}

@SuppressWarnings("override")
public SearchFilter expand() {
return this;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*****************************************************************************************
* *** BEGIN LICENSE BLOCK *****
*
* echocat Adam, Copyright (c) 2014 echocat
* echocat Adam, Copyright (c) 2014-2016 echocat
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand All @@ -21,6 +21,7 @@

package org.echocat.adam.profile;

import com.atlassian.confluence.search.v2.SearchFilter;
import com.atlassian.confluence.search.v2.SearchQuery;
import org.echocat.adam.report.Column;
import org.echocat.jomon.runtime.CollectionUtils;
Expand Down Expand Up @@ -85,4 +86,8 @@ public String getKey() {
return "userProfileDataQuery";
}

@SuppressWarnings("override")
public SearchQuery expand() {
return this;
}
}
8 changes: 3 additions & 5 deletions src/main/resources/atlassian-plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ **** BEGIN LICENSE BLOCK *****
~
~ echocat Adam, Copyright (c) 2014 echocat
~ echocat Adam, Copyright (c) 2014-2016 echocat
~
~ This library is free software; you can redistribute it and/or
~ modify it under the terms of the GNU Lesser General Public
Expand All @@ -21,9 +21,7 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->

<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.name}" plugins-version="2"
xmlns="http://www.atlassian.com/schema/plugins"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.atlassian.com/schema/plugins https://bitbucket.org/atlassian/atlassian-xsd/raw/5e78bb51fddadbfacb3386551675cf00f1f94566/confluence/confluence-3.5.xsd">
xmlns="http://www.atlassian.com/schema/plugins">
<plugin-info>
<description>${project.description}</description>
<version>${project.version}</version>
Expand Down Expand Up @@ -216,4 +214,4 @@

<rest key="rest" name="REST API" path="/adam" version="1.0" />

</atlassian-plugin>
</atlassian-plugin>
4 changes: 2 additions & 2 deletions src/main/resources/org/echocat/adam/convoyed/edituser.vm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#end
</fieldset>
#else
#tag( "Hidden" "name='username'" "size='50'" "value='$!action.user.name'" )
#tag( "Hidden" "name='username'" "value='$!action.user.name'" )
#end

#tag( "Submit" "theme='aui'" )
Expand All @@ -35,4 +35,4 @@

#parse ( "/breadcrumbs.vm" )
</body>
</html>
</html>

0 comments on commit 3b21533

Please sign in to comment.