-
Notifications
You must be signed in to change notification settings - Fork 283
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
Allow setting of server default values for member expiry days #2840
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4820,6 +4820,9 @@ public DomainRoleMembers getOverdueReview(ResourceContext ctx, String domainName | |
} | ||
|
||
Timestamp getMemberDueDate(long cfgDueDateMillis, Timestamp memberDueDate) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please update the testGetMemberDueDate unit test case to include the cfgDueDateMillis == 0 case. |
||
if (cfgDueDateMillis == 0) { | ||
return memberDueDate; | ||
} | ||
if (memberDueDate == null) { | ||
return Timestamp.fromMillis(cfgDueDateMillis); | ||
} else if (memberDueDate.millis() > cfgDueDateMillis) { | ||
|
@@ -4893,23 +4896,6 @@ private <T> void updateMemberDueDate(MemberDueDays memberDueDays, | |
} | ||
} | ||
|
||
Timestamp memberDueDateTimestamp(Integer domainDueDateDays, Integer roleDueDateDays, Timestamp memberDueDate) { | ||
|
||
long cfgExpiryMillis = ZMSUtils.configuredDueDateMillis(domainDueDateDays, roleDueDateDays); | ||
|
||
// if we have no value configured then return | ||
// the membership expiration as is | ||
|
||
if (cfgExpiryMillis == 0) { | ||
return memberDueDate; | ||
} | ||
|
||
// otherwise compare the configured expiry days with the specified | ||
// membership value and choose the smallest expiration value | ||
|
||
return getMemberDueDate(cfgExpiryMillis, memberDueDate); | ||
} | ||
|
||
@Override | ||
public Response putMembership(ResourceContext ctx, String domainName, String roleName, | ||
String memberName, String auditRef, Boolean returnObj, String resourceOwner, Membership membership) { | ||
|
@@ -5066,6 +5052,7 @@ Timestamp getUserAuthorityExpiry(final String userName, final String expiryAttrV | |
void setRoleMemberExpiration(final AthenzDomain domain, final Role role, final RoleMember roleMember, | ||
final Membership membership, final String caller) { | ||
|
||
MemberDueDays memberExpiryDueDays = new MemberDueDays(domain.getDomain(), role, MemberDueDays.Type.EXPIRY); | ||
switch (Principal.Type.getType(roleMember.getPrincipalType())) { | ||
|
||
case USER: | ||
|
@@ -5077,44 +5064,39 @@ void setRoleMemberExpiration(final AthenzDomain domain, final Role role, final R | |
|
||
Timestamp userAuthorityExpiry = getUserAuthorityExpiry(roleMember.memberName, | ||
role.getUserAuthorityExpiration(), caller); | ||
Timestamp memberExpiry = memberDueDateTimestamp(domain.getDomain().getMemberExpiryDays(), | ||
role.getMemberExpiryDays(), membership.getExpiration()); | ||
Timestamp memberExpiry = getMemberDueDate(memberExpiryDueDays.getUserDueDateMillis(), membership.getExpiration()); | ||
roleMember.setExpiration(ZMSUtils.smallestExpiry(memberExpiry, userAuthorityExpiry)); | ||
break; | ||
|
||
case SERVICE: | ||
case USER_HEADLESS: | ||
|
||
roleMember.setExpiration(memberDueDateTimestamp(domain.getDomain().getServiceExpiryDays(), | ||
role.getServiceExpiryDays(), membership.getExpiration())); | ||
roleMember.setExpiration(getMemberDueDate(memberExpiryDueDays.getServiceDueDateMillis(), membership.getExpiration())); | ||
break; | ||
|
||
case GROUP: | ||
|
||
roleMember.setExpiration(memberDueDateTimestamp(domain.getDomain().getGroupExpiryDays(), | ||
role.getGroupExpiryDays(), membership.getExpiration())); | ||
roleMember.setExpiration(getMemberDueDate(memberExpiryDueDays.getGroupDueDateMillis(), membership.getExpiration())); | ||
break; | ||
} | ||
} | ||
|
||
void setRoleMemberReview(final Role role, final RoleMember roleMember, | ||
final Membership membership) { | ||
|
||
MemberDueDays memberReminderDueDays = new MemberDueDays(null, role, MemberDueDays.Type.REMINDER); | ||
switch (Principal.Type.getType(roleMember.getPrincipalType())) { | ||
case USER: | ||
roleMember.setReviewReminder(memberDueDateTimestamp(null, | ||
role.getMemberReviewDays(), membership.getReviewReminder())); | ||
roleMember.setReviewReminder(getMemberDueDate(memberReminderDueDays.getUserDueDateMillis(), membership.getReviewReminder())); | ||
break; | ||
|
||
case SERVICE: | ||
case USER_HEADLESS: | ||
roleMember.setReviewReminder(memberDueDateTimestamp(null, | ||
role.getServiceReviewDays(), membership.getReviewReminder())); | ||
roleMember.setReviewReminder(getMemberDueDate(memberReminderDueDays.getServiceDueDateMillis(), membership.getReviewReminder())); | ||
break; | ||
|
||
case GROUP: | ||
roleMember.setReviewReminder(memberDueDateTimestamp(null, | ||
role.getGroupReviewDays(), membership.getReviewReminder())); | ||
roleMember.setReviewReminder(getMemberDueDate(memberReminderDueDays.getGroupDueDateMillis(), membership.getReviewReminder())); | ||
break; | ||
} | ||
} | ||
|
@@ -11164,22 +11146,21 @@ public GroupMembership getGroupMembership(ResourceContext ctx, String domainName | |
void setGroupMemberExpiration(final AthenzDomain domain, final Group group, final GroupMember groupMember, | ||
final GroupMembership membership, final String caller) { | ||
|
||
MemberDueDays memberExpiryDueDays = new MemberDueDays(domain.getDomain(), group); | ||
switch (Principal.Type.getType(groupMember.getPrincipalType())) { | ||
|
||
case USER: | ||
|
||
Timestamp userAuthorityExpiry = getUserAuthorityExpiry(groupMember.memberName, | ||
group.getUserAuthorityExpiration(), caller); | ||
Timestamp memberExpiry = memberDueDateTimestamp(domain.getDomain().getMemberExpiryDays(), | ||
group.getMemberExpiryDays(), membership.getExpiration()); | ||
Timestamp memberExpiry = getMemberDueDate(memberExpiryDueDays.getUserDueDateMillis(), membership.getExpiration()); | ||
groupMember.setExpiration(ZMSUtils.smallestExpiry(memberExpiry, userAuthorityExpiry)); | ||
break; | ||
|
||
case SERVICE: | ||
case USER_HEADLESS: | ||
|
||
groupMember.setExpiration(memberDueDateTimestamp(domain.getDomain().getServiceExpiryDays(), | ||
group.getServiceExpiryDays(), membership.getExpiration())); | ||
groupMember.setExpiration(getMemberDueDate(memberExpiryDueDays.getServiceDueDateMillis(), membership.getExpiration())); | ||
break; | ||
|
||
case GROUP: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,9 +19,14 @@ | |
import com.yahoo.athenz.zms.Group; | ||
import com.yahoo.athenz.zms.Role; | ||
import com.yahoo.athenz.zms.utils.ZMSUtils; | ||
import com.yahoo.athenz.zms.ZMSConsts; | ||
|
||
public class MemberDueDays { | ||
|
||
private static final int DEFAULT_USER_EXPIRY = Integer.parseInt(System.getProperty(ZMSConsts.ZMS_PROP_DEFAULT_USER_EXPIRY, "0")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here. let's name these DEFAULT_MAX_USER_EXPIRY, etc to correctly indicate the max aspect of the value. |
||
private static final int DEFAULT_SERVICE_EXPIRY = Integer.parseInt(System.getProperty(ZMSConsts.ZMS_PROP_DEFAULT_SERVICE_EXPIRY, "0")); | ||
private static final int DEFAULT_GROUP_EXPIRY = Integer.parseInt(System.getProperty(ZMSConsts.ZMS_PROP_DEFAULT_GROUP_EXPIRY, "0")); | ||
|
||
final long userDueDateMillis; | ||
final long serviceDueDateMillis; | ||
final long groupDueDateMillis; | ||
|
@@ -59,9 +64,9 @@ public MemberDueDays(Domain domain, Role role, Type type) { | |
roleGroupDays = role.getGroupReviewDays(); | ||
} | ||
|
||
userDueDateMillis = ZMSUtils.configuredDueDateMillis(domainUserDays, roleUserDays); | ||
serviceDueDateMillis = ZMSUtils.configuredDueDateMillis(domainServiceDays, roleServiceDays); | ||
groupDueDateMillis = ZMSUtils.configuredDueDateMillis(domainGroupDays, roleGroupDays); | ||
userDueDateMillis = ZMSUtils.configuredDueDateMillis(DEFAULT_USER_EXPIRY, domainUserDays, roleUserDays); | ||
serviceDueDateMillis = ZMSUtils.configuredDueDateMillis(DEFAULT_SERVICE_EXPIRY, domainServiceDays, roleServiceDays); | ||
groupDueDateMillis = ZMSUtils.configuredDueDateMillis(DEFAULT_GROUP_EXPIRY, domainGroupDays, roleGroupDays); | ||
} | ||
|
||
public MemberDueDays(Domain domain, Group group) { | ||
|
@@ -74,8 +79,8 @@ public MemberDueDays(Domain domain, Group group) { | |
Integer groupUserDays = group.getMemberExpiryDays(); | ||
Integer groupServiceDays = group.getServiceExpiryDays(); | ||
|
||
userDueDateMillis = ZMSUtils.configuredDueDateMillis(domainUserDays, groupUserDays); | ||
serviceDueDateMillis = ZMSUtils.configuredDueDateMillis(domainServiceDays, groupServiceDays); | ||
userDueDateMillis = ZMSUtils.configuredDueDateMillis(DEFAULT_USER_EXPIRY, domainUserDays, groupUserDays); | ||
serviceDueDateMillis = ZMSUtils.configuredDueDateMillis(DEFAULT_SERVICE_EXPIRY, domainServiceDays, groupServiceDays); | ||
groupDueDateMillis = 0; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -449,7 +449,7 @@ public static boolean metaValueChanged(Object domainValue, Object metaValue) { | |
return metaValue != null && !metaValue.equals(domainValue); | ||
} | ||
|
||
public static long configuredDueDateMillis(Integer domainDueDateDays, Integer roleDueDateDays) { | ||
public static long configuredDueDateMillis(Integer serverDefaultDueDateDays, Integer domainDueDateDays, Integer roleDueDateDays) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we have serverDefaultDueDateDays (should also be called serverDefaultMaxDueDateDays) set as Integer? It's int so we should define the function as such and it also eliminates the boxing and unnecessary null check later. |
||
|
||
// the role expiry days settings overrides the domain one if one configured | ||
|
||
|
@@ -459,6 +459,13 @@ public static long configuredDueDateMillis(Integer domainDueDateDays, Integer ro | |
} else if (domainDueDateDays != null && domainDueDateDays > 0) { | ||
expiryDays = domainDueDateDays; | ||
} | ||
|
||
if (serverDefaultDueDateDays != null && serverDefaultDueDateDays > 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. once serverDefaultMaxDueDateDays is defined as int, the null check is not necessary here |
||
if (expiryDays == 0 || expiryDays > serverDefaultDueDateDays) { | ||
expiryDays = serverDefaultDueDateDays; | ||
} | ||
} | ||
|
||
return expiryDays == 0 ? 0 : System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(expiryDays, TimeUnit.DAYS); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's rename these three variables to be athenz.zms.default_max_... (add the max_ component). default value indicates that we'll set this if no value is specified but here we're doing 2 things: first if no value is set, we default to this value and second, if a value is specified then we do not allow the value to be bigger than this (which is max part and not necessarily default).