Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Udl #13

Open
wants to merge 8 commits into
base: 7.10
Choose a base branch
from
Open

Udl #13

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pojo-bin
seam-bin
deploy.sh
log/
.idea
nuxeo-shibboleth-invitation.iml

*.pyc
*~
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should be removed from the commit.

Expand Down
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.nuxeo</groupId>
<artifactId>nuxeo-addons-parent</artifactId>
<version>7.10-HF35-SNAPSHOT</version>
<groupId>fr.udl.nuxeo</groupId>
<artifactId>package_parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<groupId>org.nuxeo.shibboleth.invitation</groupId>
<artifactId>nuxeo-shibboleth-invitation</artifactId>
<groupId>${marketplace.bundle.groupId}</groupId>
<artifactId>nuxeo-shibboleth-invitation-udl</artifactId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original groupId/artifactId should be set back.

<name>nuxeo-shibboleth-invitation</name>
<description>
This addon provides the ability to invite external users to join Nuxeo
Expand Down Expand Up @@ -122,4 +122,4 @@
</pluginRepository>
</pluginRepositories>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -64,32 +64,37 @@ public class ShibbolethUserMapper implements UserMapper {

@Override
public NuxeoPrincipal getOrCreateAndUpdateNuxeoPrincipal(Object userObject) {
log.trace("fuck getOrCreateAndUpdateNuxeoPrincipal");
return getOrCreateAndUpdateNuxeoPrincipal(userObject, true, true, null);
}

protected UserInvitationService fetchService() {
log.trace("fuck fetchService");
return Framework.getLocalService(UserRegistrationService.class);
}

@Override
public NuxeoPrincipal getOrCreateAndUpdateNuxeoPrincipal(Object userObject, boolean createIfNeeded, boolean update,
Map<String, Serializable> params) {

log.trace("fuck getOrCreateAndUpdateNuxeoPrincipal");
// Fetching keys from the shibboleth configuration in nuxeo
ShibbolethAuthenticationService shiboService = Framework.getService(ShibbolethAuthenticationService.class);
BiMap<String, String> metadata = shiboService.getUserMetadata();
String usernameKey = MoreObjects.firstNonNull(metadata.get("username"), "username");
String lastNameKey = MoreObjects.firstNonNull(metadata.get("lastName"), "lastName");
String firstNameKey = MoreObjects.firstNonNull(metadata.get("firstName"), "firstName");
String emailKey = MoreObjects.firstNonNull(metadata.get("email"), "email");
String companyKey = MoreObjects.firstNonNull(metadata.get("company"), "company");
String passwordKey = MoreObjects.firstNonNull(metadata.get("password"), "password");

String email = (String) ((Map) userObject).get(emailKey);
ShibbolethUserInfo userInfo = new ShibbolethUserInfo((String) ((Map) userObject).get(usernameKey),
(String) ((Map) userObject).get(passwordKey), (String) ((Map) userObject).get(firstNameKey),
(String) ((Map) userObject).get(lastNameKey), (String) ((Map) userObject).get(companyKey), email);

// BiMap<String, String> metadata = shiboService.getUserMetadata();
// String usernameKey = MoreObjects.firstNonNull(metadata.get("username"), "username");
// String lastNameKey = MoreObjects.firstNonNull(metadata.get("lastName"), "lastName");
// String firstNameKey = MoreObjects.firstNonNull(metadata.get("firstName"), "firstName");
// String emailKey = MoreObjects.firstNonNull(metadata.get("email"), "email");
// String companyKey = MoreObjects.firstNonNull(metadata.get("company"), "company");
// String passwordKey = MoreObjects.firstNonNull(metadata.get("password"), "password");
//
// String email = (String) ((Map) userObject).get(emailKey);
// ShibbolethUserInfo userInfo = new ShibbolethUserInfo((String) ((Map) userObject).get(usernameKey),
// (String) ((Map) userObject).get(passwordKey), (String) ((Map) userObject).get(firstNameKey),
// (String) ((Map) userObject).get(lastNameKey), (String) ((Map) userObject).get(companyKey), email);


ShibbolethUserInfo userInfo = new ShibbolethUserInfo((String)((Map)userObject).get("username"), (String)((Map)userObject).get("password"), (String)((Map)userObject).get("firstName"), (String)((Map)userObject).get("lastName"), (String)((Map)userObject).get("company"), (String)((Map)userObject).get("email"));
String email = (String)((Map)userObject).get("email");
// Check if email has been provided and if invitation has been assigned to a user with email as username
DocumentModel userDoc = null;
String userName = userInfo.getUserName();
Expand All @@ -111,15 +116,19 @@ public NuxeoPrincipal getOrCreateAndUpdateNuxeoPrincipal(Object userObject, bool
return userManager.getPrincipal(userId);
}

protected void updateACP(String userName, String email, DocumentModel userDoc) {
protected void updateACP(final String userName,final String email, final DocumentModel userDoc) {
log.trace("fuck updateACP");
new UnrestrictedSessionRunner(getTargetRepositoryName()) {
@Override
public void run() {

NuxeoPrincipal principal = userManager.getPrincipal(
(String) userDoc.getProperty(userSchemaName, "username"));
ArrayList<String> groups = new ArrayList<>(principal.getGroups());

log.trace("group for user " + userName + ":" + principal.getPrincipalId() + ":" + principal.getEmail());
for(String group: groups) {
log.trace(group);
}
userManager.deleteUser(userDoc);
userDoc.setPropertyValue("user:username", userName);
userDoc.setPropertyValue("user:groups", groups);
Expand Down Expand Up @@ -162,6 +171,7 @@ public void run() {
}

protected DocumentModel createUser(ShibbolethUserInfo userInfo) {
log.trace("fuck createUser");
DocumentModel userDoc;
try {
userDoc = userManager.getBareUserModel();
Expand All @@ -178,12 +188,14 @@ protected DocumentModel createUser(ShibbolethUserInfo userInfo) {

@Override
public void init(Map<String, String> params) throws Exception {
log.trace("fuck init");
userManager = Framework.getLocalService(UserManager.class);
userSchemaName = userManager.getUserSchemaName();
groupSchemaName = userManager.getGroupSchemaName();
}

private DocumentModel findUser(String field, String userName) {
log.trace("fuck findUser");
Map<String, Serializable> query = new HashMap<>();
query.put(field, userName);
DocumentModelList users = userManager.searchUsers(query, null);
Expand All @@ -195,26 +207,38 @@ private DocumentModel findUser(String field, String userName) {
}

private DocumentModel updateUser(DocumentModel userDoc, ShibbolethUserInfo userInfo) {
log.trace("fuck updateUser");
NuxeoPrincipal principal = userManager.getPrincipal(
(String) userDoc.getProperty(userSchemaName, "username"));
ArrayList<String> groups = new ArrayList<>(principal.getGroups());
log.trace("group for user :" + userDoc.getProperty(userSchemaName, "username") + ":" + principal.getEmail());
for(String group: groups) {
log.trace(group);
}
userDoc.setPropertyValue(userManager.getUserEmailField(), userInfo.getEmail());
userDoc.setProperty(userSchemaName, "firstName", userInfo.getFirstName());
userDoc.setProperty(userSchemaName, "lastName", userInfo.getLastName());
userDoc.setProperty(userSchemaName, "password", userInfo.getPassword());
userDoc.setProperty(userSchemaName, "company", userInfo.getCompany());
userDoc.setPropertyValue("user:groups", groups);
userManager.updateUser(userDoc);
return userDoc;
}

@Override
public Object wrapNuxeoPrincipal(NuxeoPrincipal principal, Object nativePrincipal,
Map<String, Serializable> params) {
log.trace("fuck wrapNuxeoPrincipal");
throw new UnsupportedOperationException();
}

@Override
public void release() {
log.trace("fuck release");
}

public String getTargetRepositoryName() {
log.trace("fuck getTargetRepositoryName");
return Framework.getService(RepositoryManager.class).getDefaultRepositoryName();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for deprecation instead of removal.