Skip to content
Snippets Groups Projects
Commit 5239d7a3 authored by Felix Sidokhine's avatar Felix Sidokhine
Browse files

Added vcard support

parent 31097581
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......@@ -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
......@@ -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();
}
}
......@@ -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
......
......@@ -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>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment