Skip to content

Commit

Permalink
Welcome ConnId 1.5.1.0 and JDK 8
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgrosso committed Apr 13, 2022
1 parent ed6e7bf commit e9ac59c
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 73 deletions.
23 changes: 10 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<parent>
<groupId>net.tirasa.connid</groupId>
<artifactId>connid</artifactId>
<version>1.4.5.1</version>
<version>1.5.1.0</version>
</parent>

<groupId>net.tirasa.connid.bundles</groupId>
Expand Down Expand Up @@ -83,7 +83,7 @@
</mailingLists>

<properties>
<connid.version>1.4.5.1</connid.version>
<connid.version>1.5.1.0</connid.version>
<google-api-client.version>1.33.4</google-api-client.version>
<google-oauth-client.version>1.33.2</google-oauth-client.version>
<google-api-services.version>1.25.0</google-api-services.version>
Expand Down Expand Up @@ -159,8 +159,8 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -187,10 +187,10 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<version>3.10.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

Expand Down Expand Up @@ -250,7 +250,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<version>3.2.0</version>
<executions>
<execution>
<id>copy-javadoc-legal-files</id>
Expand Down Expand Up @@ -292,17 +292,14 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<inherited>true</inherited>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<appendAssemblyId>true</appendAssemblyId>
<descriptors>
<descriptor>src/assemble/connector.xml</descriptor>
</descriptors>
<archive>
<index>true</index>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
<manifestEntries>
<ConnectorBundle-FrameworkVersion>${connid.version}</ConnectorBundle-FrameworkVersion>
<ConnectorBundle-Name>${project.artifactId}</ConnectorBundle-Name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,26 @@
public class CodeProcessorServlet extends HttpServlet {

private static final long serialVersionUID = -6813584667162798300L;
private String redirectUri;

private final String redirectUri;

public CodeProcessorServlet(final String redirectUri) {
this.redirectUri = redirectUri;
}

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {

GoogleTokenResponse response =
new GoogleAuthorizationCodeTokenRequest(CredentialsGeneratorApplication.HTTP_TRANSPORT,
CredentialsGeneratorApplication.JSON_FACTORY,
CredentialsGeneratorApplication.configMap.get("clientId").toString(),
CredentialsGeneratorApplication.configMap.get("clientSecret").toString(),
new AuthorizationCodeResponseUrl(req.getQueryString() == null
? req.getRequestURL().toString()
: new StringBuilder(req.getRequestURL().toString()).append('?')
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
GoogleTokenResponse response = new GoogleAuthorizationCodeTokenRequest(
CredentialsGeneratorApplication.HTTP_TRANSPORT,
CredentialsGeneratorApplication.JSON_FACTORY,
CredentialsGeneratorApplication.configMap.get("clientId").toString(),
CredentialsGeneratorApplication.configMap.get("clientSecret").toString(),
new AuthorizationCodeResponseUrl(req.getQueryString() == null
? req.getRequestURL().toString()
: new StringBuilder(req.getRequestURL().toString()).append('?')
.append(req.getQueryString())
.toString()).getCode(), redirectUri)
.execute();
.execute();

CredentialsGeneratorApplication.configMap.put("refreshToken", response.getRefreshToken());

Expand All @@ -57,4 +56,4 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO
resp.getWriter().write(secretsContent);
resp.getWriter().flush();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
import java.awt.Desktop;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.Banner;
import org.springframework.boot.CommandLineRunner;
Expand Down Expand Up @@ -64,7 +65,7 @@ public class CredentialsGeneratorApplication implements CommandLineRunner {
public static final String ADMIN_ENTERPRISE_LICENSE =
"https://www.googleapis.com/auth/apps.licensing";

public static final Map<String, Object> configMap = new LinkedHashMap<String, Object>(3);
public static final Map<String, Object> configMap = new LinkedHashMap<>(3);

public static final JsonFactory JSON_FACTORY = new GsonFactory();

Expand Down Expand Up @@ -98,7 +99,7 @@ private void getConfigurationMap(File clientJson) throws IOException, URISyntaxE
.setState("/profile").build();
System.out.println("Request Url is " + requestUrl);

java.awt.Desktop.getDesktop().getDesktop().browse(new URI(requestUrl));
Desktop.getDesktop().browse(new URI(requestUrl));
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,11 @@ public void getGoogleCredential() {
.setClientId(getClientId())
.setClientSecret(SecurityUtil.decrypt(getClientSecret()));

getRefreshToken().access(new GuardedString.Accessor() {

@Override
public void access(char[] chars) {
credentialsBuilder.setRefreshToken(new String(chars));
}
});
getRefreshToken().access(chars -> credentialsBuilder.setRefreshToken(new String(chars)));

final UserCredentials userCredentials = credentialsBuilder.build();
credentials = userCredentials
.createScoped(Arrays.asList(DirectoryScopes.ADMIN_DIRECTORY_USER,
credentials = userCredentials.createScoped(
Arrays.asList(DirectoryScopes.ADMIN_DIRECTORY_USER,
DirectoryScopes.ADMIN_DIRECTORY_USER_ALIAS,
DirectoryScopes.ADMIN_DIRECTORY_USERSCHEMA,
DirectoryScopes.ADMIN_DIRECTORY_ORGUNIT,
Expand Down Expand Up @@ -276,5 +270,4 @@ public Licensing getLicensing() {
}
return licensing;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -602,13 +602,7 @@ public Schema schema() {

@Override
public FilterTranslator<Filter> createFilterTranslator(ObjectClass objectClass, OperationOptions options) {
return new FilterTranslator<Filter>() {

@Override
public List<Filter> translate(Filter filter) {
return CollectionUtil.newList(filter);
}
};
return CollectionUtil::newList;
}

@Override
Expand Down Expand Up @@ -1271,7 +1265,7 @@ protected String getFields(OperationOptions options, String... nameAttribute) {
final boolean notBlankCustomSchemas = StringUtil.isNotBlank(configuration.getCustomSchemasJSON());
final List<String> customSchemaNames = notBlankCustomSchemas
? customSchemaNames(configuration.getCustomSchemasJSON())
: new ArrayList<String>();
: new ArrayList<>();
for (String attribute : options.getAttributesToGet()) {
if (AttributeUtil.namesEqual(PredefinedAttributes.DESCRIPTION, attribute)) {
attributes.add(DESCRIPTION_ATTR);
Expand Down Expand Up @@ -1352,7 +1346,7 @@ public Object handleNotFound(IOException e) {
final Set<String> activeGroups =
listGroups(configuration.getDirectory().groups(), uidAfterUpdate.getUidValue());

final List<Directory.Members.Insert> addGroups = new ArrayList<Directory.Members.Insert>();
final List<Directory.Members.Insert> addGroups = new ArrayList<>();
final Set<String> keepGroups = CollectionUtil.newCaseInsensitiveSet();

for (Object member : groups.getValue()) {
Expand Down Expand Up @@ -1499,14 +1493,11 @@ public Object handleNotFound(IOException e) {
final List<Map<String, String>> activeMembership =
listMembers(service, uidAfterUpdate.getUidValue(), null);

final List<Directory.Members.Insert> addMembership =
new ArrayList<Directory.Members.Insert>();
final List<Directory.Members.Patch> patchMembership =
new ArrayList<Directory.Members.Patch>();
final List<Directory.Members.Insert> addMembership = new ArrayList<>();
final List<Directory.Members.Patch> patchMembership = new ArrayList<>();

for (Object member : members.getValue()) {
if (member instanceof Map) {

String email = (String) ((Map) member).get(EMAIL_ATTR);
if (null == email) {
continue;
Expand Down Expand Up @@ -1841,23 +1832,20 @@ protected ConnectorObject fromGroup(
}

protected List<Map<String, String>> listMembers(Directory.Members service, String groupKey, String roles) {
final List<Map<String, String>> result = new ArrayList<Map<String, String>>();
final List<Map<String, String>> result = new ArrayList<>();
try {
Directory.Members.List request = service.list(groupKey);
request.setRoles(StringUtil.isBlank(roles) ? "OWNER,MANAGER,MEMBER" : roles);

String nextPageToken;
do {
nextPageToken = execute(request,
new RequestResultHandler<Directory.Members.List, Members, String>() {
nextPageToken = execute(request, new RequestResultHandler<Directory.Members.List, Members, String>() {

@Override
public String handleResult(Directory.Members.List request,
Members value) {
public String handleResult(Directory.Members.List request, Members value) {
if (null != value.getMembers()) {
for (Member member : value.getMembers()) {
Map<String, String> m =
new LinkedHashMap<String, String>(2);
Map<String, String> m = new LinkedHashMap<>(2);
m.put(EMAIL_ATTR, member.getEmail());
m.put(ROLE_ATTR, member.getRole());
result.add(m);
Expand Down Expand Up @@ -1886,8 +1874,7 @@ protected Set<String> listGroups(Directory.Groups service, String userKey) {

String nextPageToken;
do {
nextPageToken = execute(request,
new RequestResultHandler<Directory.Groups.List, Groups, String>() {
nextPageToken = execute(request, new RequestResultHandler<Directory.Groups.List, Groups, String>() {

@Override
public String handleResult(Directory.Groups.List request, Groups value) {
Expand Down Expand Up @@ -2030,5 +2017,4 @@ private List<String> customSchemaNames(final String customSchemasJSON) {
}
return customSchemaNames;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,4 @@ public void setInnerSchemas(final List<GoogleAppsCustomSchema> innerSchemas) {
this.innerSchemas.clear();
this.innerSchemas.addAll(innerSchemas);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import com.google.common.base.CharMatcher;
import com.google.common.escape.Escaper;
import com.google.common.escape.Escapers;
import java.util.Base64;
import java.util.HashMap;
import java.util.List;
import org.identityconnectors.framework.common.objects.filter.EqualsIgnoreCaseFilter;
Expand Down Expand Up @@ -843,7 +844,7 @@ public static Directory.Users.Photos.Update createUpdateUserPhoto(

UserPhoto content = new UserPhoto();
// Required
content.setPhotoData(com.google.api.client.util.Base64.encodeBase64URLSafeString(data));
content.setPhotoData(Base64.getMimeEncoder().encodeToString(data));

// @formatter:off
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
*/
package net.tirasa.connid.bundles.googleapps;

import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.identityconnectors.common.logging.Log;
import org.identityconnectors.common.security.GuardedString;
import org.identityconnectors.framework.api.APIConfiguration;
import org.identityconnectors.framework.api.ConnectorFacade;
Expand All @@ -27,18 +26,16 @@
import org.identityconnectors.framework.common.objects.ObjectClassInfo;
import org.identityconnectors.framework.common.objects.Schema;
import org.identityconnectors.test.common.TestHelpers;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

public class GoogleAppsConnectorUnitTests {

private static final Log LOG = Log.getLog(GoogleAppsConnectorUnitTests.class);

private static ConnectorFacade connector;

private static GoogleAppsConfiguration connectorConfiguration;

@BeforeClass
@BeforeAll
public static void setUp() {
connectorConfiguration = new GoogleAppsConfiguration();

Expand Down Expand Up @@ -98,5 +95,4 @@ public void schema() {
assertTrue(customSingleValuedSchemaFound2);
assertTrue(customMultivaluedSchemaFound);
}

}

0 comments on commit e9ac59c

Please sign in to comment.