Skip to content

Commit

Permalink
Apply google-java-format to the codebase in bulk
Browse files Browse the repository at this point in the history
    Doing this now will prevent spurious diffs in the future
  • Loading branch information
stea-uw committed Apr 16, 2024
1 parent 316a31b commit 4390170
Show file tree
Hide file tree
Showing 80 changed files with 8,791 additions and 8,856 deletions.
378 changes: 194 additions & 184 deletions src/main/java/edu/washington/iam/registry/accessctrl/AccessCtrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,197 +15,207 @@
* ========================================================================
*/


package edu.washington.iam.registry.accessctrl;

import edu.washington.iam.registry.exception.AccessCtrlException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;
import java.util.UUID;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AccessCtrl implements Serializable {

private final Logger log = LoggerFactory.getLogger(getClass());

private Boolean is2FASet;
private Boolean auto2FA;
private String groupAuto2FA;
private Boolean conditional;
private String conditionalGroup;
private String conditionalLink;
private String entityId;
private UUID uuid;
private String startTime;
private String endTime;
private String updatedBy;


private String safePy(String in) {
return in.replaceAll("\"","\\\"");
}




public AccessCtrl(){

//is2FASet keeps track if some idiot (like your author) tries to enable conditional AND auto 2fa
//perhaps a better name would have been "is2FASetByUser". If the DB sets the value we don't care.
is2FASet = false;
auto2FA = false;
groupAuto2FA = "";
conditional = false;
conditionalGroup = "";
conditionalLink = "";
entityId = "";
uuid = null;
startTime = null;
endTime = null;
updatedBy = "";

}


//"conditional 2fa" is a virtual state--it means auto2fa is true and a group is set to a non-empty string
public Boolean getCond2FA() {
if (auto2FA && getGroupAuto2FA() != "")
{
return true;
} else return false;
}
//for setting the virtual state above
public void setCond2FA(String group) throws AccessCtrlException {
if (is2FASet) { throw new AccessCtrlException("Can't sent Auto 2FA AND Conditional 2FA!!"); }
if (StringUtils.isNotBlank(group))
{
this.auto2FA = true;
this.groupAuto2FA = group;
is2FASet = true; //2fa is set. We can't set it again

} else {
throw new AccessCtrlException("tried to set conditional 2FA but provided empty or whitespace string for group name");
}

}

//this is for external stuff to call--if this returns true then the entity ID uses "auto 2fa". Handles the logic
//of figuring out the auto2fa/group-is-populated permutations.
public Boolean getAuto2FA() {
if (auto2FA && getGroupAuto2FA() == "")
{
return true;
} else return false;
}
//like the get method, sets the state to "auto 2fa" without you having to figure out if the group field is populated
//or not
public void setAuto2FA(Boolean auto2FA) throws AccessCtrlException {
if (is2FASet) { throw new AccessCtrlException("Can't sent Auto 2FA AND Conditional 2FA!!"); }
this.auto2FA = auto2FA;
this.groupAuto2FA = "";
is2FASet = true; //2fa is set. We can't set it again
}

//only use when DB is setting this property (doesn't have the safety features of the other methods)
//DB needs to be able to set auto2fa and groupAuto2FA properties independently
public void setAuto2FAInternal(Boolean auto2FA)
{
this.auto2FA = auto2FA;
}
//also for DB use only--DB needs to be able to get the "naked" auto2fa state
public Boolean getAuto2FAInternal() {
return this.auto2FA;
}

public String getGroupAuto2FA() {
//if not null, empty, or only whitespace, return the string
if (StringUtils.isNotBlank(groupAuto2FA)) { return groupAuto2FA; }
//otherwise return a string that is definitely empty (avoids whitespace issues)
else { return ""; }
}

public void setGroupAuto2FA(String groupAuto2FA) {
this.groupAuto2FA = groupAuto2FA;
}

public Boolean getConditional() {
return conditional;
}

public void setConditional(Boolean conditional) {
this.conditional = conditional;
}

public String getConditionalGroup() {
return conditionalGroup;
}

public void setConditionalGroup(String conditionalGroup) {
public class AccessCtrl implements Serializable {

private final Logger log = LoggerFactory.getLogger(getClass());

private Boolean is2FASet;
private Boolean auto2FA;
private String groupAuto2FA;
private Boolean conditional;
private String conditionalGroup;
private String conditionalLink;
private String entityId;
private UUID uuid;
private String startTime;
private String endTime;
private String updatedBy;

private String safePy(String in) {
return in.replaceAll("\"", "\\\"");
}

public AccessCtrl() {

// is2FASet keeps track if some idiot (like your author) tries to enable conditional AND auto
// 2fa
// perhaps a better name would have been "is2FASetByUser". If the DB sets the value we don't
// care.
is2FASet = false;
auto2FA = false;
groupAuto2FA = "";
conditional = false;
conditionalGroup = "";
conditionalLink = "";
entityId = "";
uuid = null;
startTime = null;
endTime = null;
updatedBy = "";
}

// "conditional 2fa" is a virtual state--it means auto2fa is true and a group is set to a
// non-empty string
public Boolean getCond2FA() {
if (auto2FA && getGroupAuto2FA() != "") {
return true;
} else return false;
}

// for setting the virtual state above
public void setCond2FA(String group) throws AccessCtrlException {
if (is2FASet) {
throw new AccessCtrlException("Can't sent Auto 2FA AND Conditional 2FA!!");
}
if (StringUtils.isNotBlank(group)) {
this.auto2FA = true;
this.groupAuto2FA = group;
is2FASet = true; // 2fa is set. We can't set it again

} else {
throw new AccessCtrlException(
"tried to set conditional 2FA but provided empty or whitespace string for group name");
}
}

// this is for external stuff to call--if this returns true then the entity ID uses "auto 2fa".
// Handles the logic
// of figuring out the auto2fa/group-is-populated permutations.
public Boolean getAuto2FA() {
if (auto2FA && getGroupAuto2FA() == "") {
return true;
} else return false;
}

// like the get method, sets the state to "auto 2fa" without you having to figure out if the group
// field is populated
// or not
public void setAuto2FA(Boolean auto2FA) throws AccessCtrlException {
if (is2FASet) {
throw new AccessCtrlException("Can't sent Auto 2FA AND Conditional 2FA!!");
}
this.auto2FA = auto2FA;
this.groupAuto2FA = "";
is2FASet = true; // 2fa is set. We can't set it again
}

// only use when DB is setting this property (doesn't have the safety features of the other
// methods)
// DB needs to be able to set auto2fa and groupAuto2FA properties independently
public void setAuto2FAInternal(Boolean auto2FA) {
this.auto2FA = auto2FA;
}

// also for DB use only--DB needs to be able to get the "naked" auto2fa state
public Boolean getAuto2FAInternal() {
return this.auto2FA;
}

public String getGroupAuto2FA() {
// if not null, empty, or only whitespace, return the string
if (StringUtils.isNotBlank(groupAuto2FA)) {
return groupAuto2FA;
}
// otherwise return a string that is definitely empty (avoids whitespace issues)
else {
return "";
}
}

public void setGroupAuto2FA(String groupAuto2FA) {
this.groupAuto2FA = groupAuto2FA;
}

public Boolean getConditional() {
return conditional;
}

public void setConditional(Boolean conditional) {
this.conditional = conditional;
}

public String getConditionalGroup() {
return conditionalGroup;
}

public void setConditionalGroup(String conditionalGroup) {
this.conditionalGroup = conditionalGroup;
}

public String getConditionalLink() {
return conditionalLink;
}

public void setConditionalLink(String conditionalLink) {
this.conditionalLink = conditionalLink;
}

// for setting conditional access using user input--DB uses plain "unsafe" methods above
public void setConditionalByUser(
Boolean conditional, String conditionalGroup, String conditionalLink)
throws AccessCtrlException {

if (conditional) {
if (StringUtils.isNotBlank(conditionalGroup)) {
this.conditionalGroup = conditionalGroup;
}

public String getConditionalLink() {
return conditionalLink;
}

public void setConditionalLink(String conditionalLink) {
this.conditionalLink = conditionalLink;
}

//for setting conditional access using user input--DB uses plain "unsafe" methods above
public void setConditionalByUser(Boolean conditional, String conditionalGroup, String conditionalLink) throws AccessCtrlException {

if (conditional) {
if (StringUtils.isNotBlank(conditionalGroup))
{
this.conditionalGroup = conditionalGroup;
this.conditionalLink = conditionalLink;
this.conditional = true;
} else {
throw new AccessCtrlException("tried to set conditional access but provided empty or whitespace" +
"string for group name");
}
} else { this.conditional = false; }
}
public String getEntityId() {
return entityId;
}

public void setEntityId(String entityId) {
this.entityId = entityId;
}

public UUID getUuid() {
return uuid;
}

public void setUuid(UUID uuid) {
this.uuid = uuid;
}
public String getStartTime() {
return startTime;
}

public void setStartTime(String startTime) {
this.startTime = startTime;
}

public String getEndTime() {
return endTime;
}

public void setEndTime(String endTime) {
this.endTime = endTime;
}

public String getUpdatedBy() {
return updatedBy;
}

public void setUpdatedBy(String updatedBy) {
this.updatedBy = updatedBy;
}
this.conditional = true;
} else {
throw new AccessCtrlException(
"tried to set conditional access but provided empty or whitespace"
+ "string for group name");
}
} else {
this.conditional = false;
}
}

public String getEntityId() {
return entityId;
}

public void setEntityId(String entityId) {
this.entityId = entityId;
}

public UUID getUuid() {
return uuid;
}

public void setUuid(UUID uuid) {
this.uuid = uuid;
}

public String getStartTime() {
return startTime;
}

public void setStartTime(String startTime) {
this.startTime = startTime;
}

public String getEndTime() {
return endTime;
}

public void setEndTime(String endTime) {
this.endTime = endTime;
}

public String getUpdatedBy() {
return updatedBy;
}

public void setUpdatedBy(String updatedBy) {
this.updatedBy = updatedBy;
}
}

Loading

0 comments on commit 4390170

Please sign in to comment.