diff --git a/integration-test/install-server.py b/integration-test/install-server.py index c102383deab0568a39e36a5df8c6cfd6b5e297c2..88b4e1c93471bbfc0575d11b81b2d2efbfe5cb73 100644 --- a/integration-test/install-server.py +++ b/integration-test/install-server.py @@ -129,6 +129,12 @@ response = requests.get("http://localhost:8080/api/auth/user",headers=header) print(response.status_code) print(response.text) +print("Getting user profile as vcard") +response = requests.get("http://localhost:8080/api/auth/directory/entry?username=aberaud&format=vcard",headers=header) +print(response.status_code) +print(response.text) + + response = requests.post("http://localhost:8080/api/update",headers=header) print(response.status_code) -print(response.text) \ No newline at end of file +print(response.text) diff --git a/jams-ca/src/main/java/net/jami/jams/ca/workers/crl/CRLFileStorage.java b/jams-ca/src/main/java/net/jami/jams/ca/workers/crl/CRLFileStorage.java index ab191b0c2247c013f189a8c165e6c72019d915f4..b8f24fc7baa304e7676e6bef0938c8c56c3c2c33 100644 --- a/jams-ca/src/main/java/net/jami/jams/ca/workers/crl/CRLFileStorage.java +++ b/jams-ca/src/main/java/net/jami/jams/ca/workers/crl/CRLFileStorage.java @@ -1,3 +1,25 @@ +/* +* Copyright (C) 2020 by Savoir-faire Linux +* Authors: William Enright <william.enright@savoirfairelinux.com> +* Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com> +* Johnny Flores <johnny.flores@savoirfairelinux.com> +* Mohammed Raza <mohammed.raza@savoirfairelinux.com> +* Felix Sidokhine <felix.sidokhine@savoirfairelinux.com> +* +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ package net.jami.jams.ca.workers.crl; import net.jami.jams.common.serialization.fs.FileStorage; diff --git a/jams-common/pom.xml b/jams-common/pom.xml index 065b4c7495ea8df8fa4e347d69376cf681f860ff..898d75355a6fdd576ed77935afd8b9be131c91a6 100644 --- a/jams-common/pom.xml +++ b/jams-common/pom.xml @@ -27,6 +27,11 @@ <artifactId>xbean-classloader</artifactId> <version>${xbean.version}</version> </dependency> + <dependency> + <groupId>com.googlecode.ez-vcard</groupId> + <artifactId>ez-vcard</artifactId> + <version>${ez.vcard.version}</version> + </dependency> </dependencies> </project> \ No newline at end of file diff --git a/jams-common/src/main/java/net/jami/jams/common/objects/user/UserProfile.java b/jams-common/src/main/java/net/jami/jams/common/objects/user/UserProfile.java index 96e6c856a05993ffb2b8fe97bff58aa7bb6e69f6..718a4ab9ce890d11b1393996c069f81083fecdc9 100644 --- a/jams-common/src/main/java/net/jami/jams/common/objects/user/UserProfile.java +++ b/jams-common/src/main/java/net/jami/jams/common/objects/user/UserProfile.java @@ -22,10 +22,24 @@ */ package net.jami.jams.common.objects.user; +import com.jsoniter.annotation.JsonIgnore; +import ezvcard.Ezvcard; +import ezvcard.VCard; +import ezvcard.VCardVersion; +import ezvcard.parameter.EmailType; +import ezvcard.parameter.ImageType; +import ezvcard.parameter.TelephoneType; +import ezvcard.property.Organization; +import ezvcard.property.Photo; +import ezvcard.property.StructuredName; +import ezvcard.property.Telephone; import lombok.Getter; import lombok.Setter; +import org.bouncycastle.util.encoders.Base64; import java.lang.reflect.Method; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.HashMap; @Getter @@ -52,5 +66,30 @@ public class UserProfile { private String email; private String organization; + @JsonIgnore + //Ignore this if we pass through JSON iterator. + public String getAsVCard(){ + VCard vCard = new VCard(); + + //We assume these always exist... + StructuredName structuredName = new StructuredName(); + structuredName.setFamily(URLEncoder.encode(this.getLastName(), StandardCharsets.UTF_8)); + structuredName.setGiven(URLEncoder.encode(this.getFirstName(), StandardCharsets.UTF_8)); + vCard.setStructuredName(structuredName); + + if(this.getPhoneNumber() != null) vCard.addTelephoneNumber(this.getPhoneNumber(), TelephoneType.WORK); + if(this.getMobileNumber() != null) vCard.addTelephoneNumber(this.getMobileNumber(),TelephoneType.CELL); + if(this.getFaxNumber() != null) vCard.addTelephoneNumber(this.getFaxNumber(), TelephoneType.FAX); + if(this.getEmail() != null) vCard.addEmail(this.getEmail(), EmailType.WORK); + if(this.getOrganization() != null) vCard.setOrganization(this.getOrganization()); + + /*I think this is how Base64 will work in this case*/ + if(this.getProfilePicture() != null) { + Photo photo = new Photo(Base64.decode(this.getProfilePicture()), ImageType.JPEG); + vCard.addPhoto(photo); + } + + return Ezvcard.write(vCard).version(VCardVersion.V3_0).go(); + } } diff --git a/jams-common/src/main/java/net/jami/jams/common/serialization/fs/FileStorage.java b/jams-common/src/main/java/net/jami/jams/common/serialization/fs/FileStorage.java index 6f3a6b4036eb01bd49d12e89f2d9cdef5456aca2..43322d32d568e86edad07a8691c339d11e4cfc05 100644 --- a/jams-common/src/main/java/net/jami/jams/common/serialization/fs/FileStorage.java +++ b/jams-common/src/main/java/net/jami/jams/common/serialization/fs/FileStorage.java @@ -1,3 +1,25 @@ +/* +* Copyright (C) 2020 by Savoir-faire Linux +* Authors: William Enright <william.enright@savoirfairelinux.com> +* Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com> +* Johnny Flores <johnny.flores@savoirfairelinux.com> +* Mohammed Raza <mohammed.raza@savoirfairelinux.com> +* Felix Sidokhine <felix.sidokhine@savoirfairelinux.com> +* +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ package net.jami.jams.common.serialization.fs; import lombok.Getter; diff --git a/jams-server/src/main/java/net/jami/jams/server/servlets/api/auth/directory/DirectoryEntryServlet.java b/jams-server/src/main/java/net/jami/jams/server/servlets/api/auth/directory/DirectoryEntryServlet.java index 6511eceb5b0501b48db6ace3dddf58ffad471329..5860c68396359db9e6dc9dd8315ba4548a27ed2d 100644 --- a/jams-server/src/main/java/net/jami/jams/server/servlets/api/auth/directory/DirectoryEntryServlet.java +++ b/jams-server/src/main/java/net/jami/jams/server/servlets/api/auth/directory/DirectoryEntryServlet.java @@ -51,7 +51,10 @@ public class DirectoryEntryServlet extends HttpServlet { UserProfile[] profiles = userAuthenticationModule.getAuthSources() .get(new AuthModuleKey(req.getParameter("directory"), AuthenticationSourceType.fromString(req.getParameter("directoryType")))) .getUserProfile(req.getParameter("username"), "LOGON_NAME"); - resp.getOutputStream().write(JsonStream.serialize(profiles[0]).getBytes()); + if(req.getParameter("format").equals("vcard")){ + resp.getOutputStream().write(profiles[0].getAsVCard().getBytes()); + } + else resp.getOutputStream().write(JsonStream.serialize(profiles[0]).getBytes()); return; } List<UserProfile> userProfiles = new ArrayList<>(); @@ -59,7 +62,10 @@ public class DirectoryEntryServlet extends HttpServlet { UserProfile[] profiles = v.getUserProfile(req.getParameter("username"), "LOGON_NAME"); if (profiles != null && profiles.length != 0) userProfiles.addAll(Arrays.asList(profiles)); }); - resp.getOutputStream().write(JsonStream.serialize(userProfiles.get(0)).getBytes()); + if(req.getParameter("format").equals("vcard")){ + resp.getOutputStream().write(userProfiles.get(0).getAsVCard().getBytes()); + } + else resp.getOutputStream().write(JsonStream.serialize(userProfiles.get(0)).getBytes()); } @Override diff --git a/jams-server/src/main/java/net/jami/jams/server/servlets/api/install/InstallLastStepServlet.java b/jams-server/src/main/java/net/jami/jams/server/servlets/api/install/InstallLastStepServlet.java index 23c5a8dd9ac2a8d1cd38743382fe80530dc3a025..099b4d33060512a6422c7a7f3e6ccd92caa7a4da 100644 --- a/jams-server/src/main/java/net/jami/jams/server/servlets/api/install/InstallLastStepServlet.java +++ b/jams-server/src/main/java/net/jami/jams/server/servlets/api/install/InstallLastStepServlet.java @@ -1,3 +1,25 @@ +/* +* Copyright (C) 2020 by Savoir-faire Linux +* Authors: William Enright <william.enright@savoirfairelinux.com> +* Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com> +* Johnny Flores <johnny.flores@savoirfairelinux.com> +* Mohammed Raza <mohammed.raza@savoirfairelinux.com> +* Felix Sidokhine <felix.sidokhine@savoirfairelinux.com> +* +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ package net.jami.jams.server.servlets.api.install; import com.jsoniter.output.JsonStream; diff --git a/pom.xml b/pom.xml index 556e86bd3201d83ebb036424b808af31b916bd9f..c50c937d7a9f2068e7d22430628e2e1e3b817b2f 100644 --- a/pom.xml +++ b/pom.xml @@ -54,6 +54,7 @@ <maven.model.version>3.2.5</maven.model.version> <apache.httpcore.version>4.4.12</apache.httpcore.version> <apache.httpclient.version>4.5.10</apache.httpclient.version> + <ez.vcard.version>0.10.6</ez.vcard.version> </properties> <dependencies>