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

Updates methods determining a users google account identifier #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ protected void processMembershipAdd(GoogleAppsChangeLogConsumer consumer, Change
//For nested groups, ChangeLogEvents fire when the group is added, and also for each indirect user added,
//so we only need to handle PERSON events.
if (subjectType == SubjectTypeEnum.PERSON) {
User user = connector.fetchGooUser(connector.getAddressFormatter().qualifySubjectAddress(subjectId));
User user = connector.fetchGooUser(connector.fetchGooUserIdentifier(lookupSubject));
if (user == null) {
user = connector.createGooUser(lookupSubject);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private void processMatchedGroups(boolean dryRun, Collection<ComparableGroupItem
ArrayList<ComparableMemberItem> grouperMembers = new ArrayList<ComparableMemberItem>();
for (edu.internet2.middleware.grouper.Member member : item.getGrouperGroup().getMembers()) {
if (member.getSubjectType() == SubjectTypeEnum.PERSON) {
grouperMembers.add(new ComparableMemberItem(connector.getAddressFormatter().qualifySubjectAddress(member.getSubjectId()), member));
grouperMembers.add(new ComparableMemberItem(connector.fetchGooUserIdentifier(member.getSubject()), member));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public class GoogleGrouperConnector {
private AddressFormatter addressFormatter;
private RecentlyManipulatedObjectsList recentlyManipulatedObjectsList;

private String attributeForGooUserLookup;
private boolean appendDomainToGooUserAttribute;
private String domain;

public GoogleGrouperConnector() {
grouperSubjects = new Cache<Subject>();
grouperGroups = new Cache<edu.internet2.middleware.grouper.Group>();
Expand Down Expand Up @@ -130,6 +134,13 @@ public void initialize(String consumerName, final GoogleAppsSyncProperties prope
grouperGroups.seed(100);

recentlyManipulatedObjectsList = new RecentlyManipulatedObjectsList(properties.getRecentlyManipulatedQueueSize(), properties.getRecentlyManipulatedQueueDelay());

attributeForGooUserLookup = properties.getAttributeForGooUserLookup();

appendDomainToGooUserAttribute = properties.getAppendDomainToGooUserAttribute();

domain = properties.getGoogleDomain();

}

/**
Expand Down Expand Up @@ -236,7 +247,7 @@ public User createGooUser(Subject subject) throws IOException {
if (properties.shouldProvisionUsers()) {
newUser = new User();
newUser.setPassword(new BigInteger(130, new SecureRandom()).toString(32))
.setPrimaryEmail(email != null ? email : addressFormatter.qualifySubjectAddress(subject.getId()))
.setPrimaryEmail(email != null ? email : fetchGooUserIdentifier(subject))
.setIncludeInGlobalAddressList(properties.shouldIncludeUserInGlobalAddressList())
.setName(new UserName())
.getName().setFullName(subjectName);
Expand Down Expand Up @@ -325,7 +336,7 @@ public void createGooGroupIfNecessary(edu.internet2.middleware.grouper.Group gro
for (edu.internet2.middleware.grouper.Member member : members) {
if (member.getSubjectType() == SubjectTypeEnum.PERSON) {
Subject subject = fetchGrouperSubject(member.getSubjectSourceId(), member.getSubjectId());
String userKey = addressFormatter.qualifySubjectAddress(subject.getId());
String userKey = fetchGooUserIdentifier(subject);
User user = fetchGooUser(userKey);

if (user == null) {
Expand Down Expand Up @@ -502,7 +513,7 @@ public void cacheSyncedGroupsAndStems(boolean fullyPopulate) {

public void removeGooMembership(String groupName, Subject subject) throws IOException {
final String groupKey = addressFormatter.qualifyGroupAddress(groupName);
final String userKey = addressFormatter.qualifySubjectAddress(subject.getId());
final String userKey = fetchGooUserIdentifier(subject);

recentlyManipulatedObjectsList.delayIfNeeded(userKey);
GoogleAppsSdkUtils.removeGroupMember(directoryClient, groupKey, userKey);
Expand Down Expand Up @@ -535,7 +546,7 @@ public HashMap<String, String> getSyncedGroupsAndStems() {
}

public void createGooMember(edu.internet2.middleware.grouper.Group group, Subject subject, String role) throws IOException {
User user = fetchGooUser(addressFormatter.qualifySubjectAddress(subject.getId()));
User user = fetchGooUser(fetchGooUserIdentifier(subject));

if (user == null) {
user = createGooUser(subject);
Expand All @@ -549,7 +560,7 @@ public void createGooMember(edu.internet2.middleware.grouper.Group group, Subjec


public void updateGooMember(edu.internet2.middleware.grouper.Group group, Subject subject, String role) throws IOException {
User user = fetchGooUser(addressFormatter.qualifySubjectAddress(subject.getId()));
User user = fetchGooUser(fetchGooUserIdentifier(subject));
Group gooGroup = fetchGooGroup(addressFormatter.qualifyGroupAddress(group.getName()));

recentlyManipulatedObjectsList.delayIfNeeded(gooGroup.getEmail());
Expand All @@ -566,5 +577,26 @@ public void updateGooMember(edu.internet2.middleware.grouper.Group group, Subjec
recentlyManipulatedObjectsList.add(user.getPrimaryEmail());
}
}

/** Here we look for a user attribute that is attached to the subject that can be looked up.
* If not, we use the subject Identifer expression.
* @return the String that will be used for the Google User Identifier
*/
public String fetchGooUserIdentifier (Subject subject) {
LOG.debug("In fetchGooUserIdentifier with a subject: " + subject);

if (attributeForGooUserLookup != null) {
String gooSubjectIdentifier = subject.getAttributeValue( attributeForGooUserLookup );
LOG.debug ("The subject identifier is " + gooSubjectIdentifier);

if (appendDomainToGooUserAttribute) {
return String.format("%s@%s", gooSubjectIdentifier, domain);
} else {
return gooSubjectIdentifier;
}
} else {
return addressFormatter.qualifySubjectAddress(subject.getId());
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ public class GoogleAppsSyncProperties {

private boolean ignoreExtraGoogleMembers;

/** Use this attribute for subject lookups to obtain the Google User */
private String attributeForGooUserLookup;

/** Append the Domain to this attribute for subject lookups */
private boolean appendDomainToGooUserAttribute;

/** Newly deleted objects aren't always removed ASAP, nor are newly created/updated object ready immediately */
private int recentlyManipulatedQueueSize;
private int recentlyManipulatedQueueDelay;
Expand Down Expand Up @@ -255,6 +261,14 @@ public GoogleAppsSyncProperties(String consumerName) {
ignoreExtraGoogleMembers = GrouperLoaderConfig.retrieveConfig().propertyValueBoolean(PARAMETER_NAMESPACE + "ignoreExtraGoogleMembers", true);
LOG.debug("Google Apps Consumer - Setting ignoreExtraGoogleMembers to {}", ignoreExtraGoogleMembers);

attributeForGooUserLookup =
GrouperLoaderConfig.retrieveConfig().propertyValueString(qualifiedParameterNamespace + "attributeForGooUserLookup", null);
LOG.debug("Google Apps Consumer - Setting attributeForGooUserLookup to {}", attributeForGooUserLookup);

appendDomainToGooUserAttribute =
GrouperLoaderConfig.retrieveConfig().propertyValueBoolean(qualifiedParameterNamespace + "appendDomainToGooUserAttribute", false);
LOG.debug("Google Apps Consumer - Setting appendDomainToGooUserAttribute to {}", appendDomainToGooUserAttribute);

}

public boolean isRetryOnError() {
Expand Down Expand Up @@ -348,4 +362,12 @@ public int getRecentlyManipulatedQueueSize() {
public int getRecentlyManipulatedQueueDelay() {
return recentlyManipulatedQueueDelay;
}

public String getAttributeForGooUserLookup() {
return attributeForGooUserLookup;
}

public boolean getAppendDomainToGooUserAttribute() {
return appendDomainToGooUserAttribute;
}
}