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

First pass, app registry implementation #591

Merged
merged 12 commits into from
Aug 15, 2019
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.microsoft.identity.common.internal.cache;
iambmelt marked this conversation as resolved.
Show resolved Hide resolved

import com.google.gson.annotations.SerializedName;

public abstract class AbstractApplicationMetadata {
iambmelt marked this conversation as resolved.
Show resolved Hide resolved

protected static class SerializedNames {
iambmelt marked this conversation as resolved.
Show resolved Hide resolved
public static final String CLIENT_ID = "client_id";
static final String ENVIRONMENT = "environment";
static final String APPLICATION_UID = "application_uid";
}

@SerializedName(SerializedNames.CLIENT_ID)
private String mClientId;

@SerializedName(SerializedNames.ENVIRONMENT)
private String mEnvironment;

@SerializedName(SerializedNames.APPLICATION_UID)
private int mUid;

public String getClientId() {
return mClientId;
}

public void setClientId(final String mClientId) {
this.mClientId = mClientId;
}

public String getEnvironment() {
return mEnvironment;
}

public void setEnvironment(final String mEnvironment) {
this.mEnvironment = mEnvironment;
}

public int getUid() {
return mUid;
}

public void setUid(final int mUid) {
this.mUid = mUid;
}

//CHECKSTYLE:OFF
// This method is generated. Checkstyle and/or PMD has been disabled.
// This method *must* be regenerated if the class' structural definition changes through the
// addition/subtraction of fields.
@SuppressWarnings("PMD")
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

AbstractApplicationMetadata that = (AbstractApplicationMetadata) o;

if (mUid != that.mUid) return false;
if (mClientId != null ? !mClientId.equals(that.mClientId) : that.mClientId != null)
return false;
return mEnvironment != null ? mEnvironment.equals(that.mEnvironment) : that.mEnvironment == null;
}
//CHECKSTYLE:ON

//CHECKSTYLE:OFF
// This method is generated. Checkstyle and/or PMD has been disabled.
// This method *must* be regenerated if the class' structural definition changes through the
// addition/subtraction of fields.
@SuppressWarnings("PMD")
@Override
public int hashCode() {
int result = mClientId != null ? mClientId.hashCode() : 0;
result = 31 * result + (mEnvironment != null ? mEnvironment.hashCode() : 0);
result = 31 * result + mUid;
return result;
}
//CHECKSTYLE:ON
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,43 +24,15 @@

import com.google.gson.annotations.SerializedName;

public class BrokerApplicationMetadata {
public class BrokerApplicationMetadata extends AbstractApplicationMetadata {

private static final class SerializedNames {
public static final String CLIENT_ID = "client_id";
static final String ENVIRONMENT = "environment";
private static final class SerializedNames extends AbstractApplicationMetadata.SerializedNames {
static final String FAMILY_ID = "family_id";
static final String APPLICATION_UID = "application_uid";
}

@SerializedName(SerializedNames.CLIENT_ID)
private String mClientId;

@SerializedName(SerializedNames.ENVIRONMENT)
private String mEnvironment;

@SerializedName(SerializedNames.FAMILY_ID)
private String mFoci;

@SerializedName(SerializedNames.APPLICATION_UID)
private int mUid;

public String getClientId() {
return mClientId;
}

public void setClientId(final String mClientId) {
this.mClientId = mClientId;
}

public String getEnvironment() {
return mEnvironment;
}

public void setEnvironment(final String mEnvironment) {
this.mEnvironment = mEnvironment;
}

public String getFoci() {
return mFoci;
}
Expand All @@ -69,14 +41,6 @@ public void setFoci(final String mFoci) {
this.mFoci = mFoci;
}

public int getUid() {
return mUid;
}

public void setUid(final int mUid) {
this.mUid = mUid;
}

//CHECKSTYLE:OFF
// This method is generated. Checkstyle and/or PMD has been disabled.
// This method *must* be regenerated if the class' structural definition changes through the
Expand All @@ -86,15 +50,11 @@ public void setUid(final int mUid) {
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;

BrokerApplicationMetadata that = (BrokerApplicationMetadata) o;
BrokerApplicationMetadata metadata = (BrokerApplicationMetadata) o;

if (mUid != that.mUid) return false;
if (mClientId != null ? !mClientId.equals(that.mClientId) : that.mClientId != null)
return false;
if (mEnvironment != null ? !mEnvironment.equals(that.mEnvironment) : that.mEnvironment != null)
return false;
return mFoci != null ? mFoci.equals(that.mFoci) : that.mFoci == null;
return mFoci != null ? mFoci.equals(metadata.mFoci) : metadata.mFoci == null;
}
//CHECKSTYLE:ON

Expand All @@ -105,10 +65,8 @@ public boolean equals(Object o) {
@SuppressWarnings("PMD")
@Override
public int hashCode() {
int result = mClientId != null ? mClientId.hashCode() : 0;
result = 31 * result + (mEnvironment != null ? mEnvironment.hashCode() : 0);
int result = super.hashCode();
result = 31 * result + (mFoci != null ? mFoci.hashCode() : 0);
result = 31 * result + mUid;
return result;
}
//CHECKSTYLE:ON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@
// THE SOFTWARE.
package com.microsoft.identity.common.internal.cache;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.List;
import java.util.Set;

public interface IBrokerApplicationMetadataCache {
public interface IBrokerApplicationMetadataCache extends ISimpleCache<BrokerApplicationMetadata> {

/**
* @return A Set of all ClientIds known to this cache. May be empty, but never null.
Expand Down Expand Up @@ -60,35 +59,4 @@ public interface IBrokerApplicationMetadataCache {
*/
@Nullable
BrokerApplicationMetadata getMetadata(String clientId, String environment, int processUid);

/**
* Inserts a new entry in the cache.
*
* @param metadata The metadata to save.
* @return True, if saved. False otherwise.
*/
boolean insert(BrokerApplicationMetadata metadata);

/**
* Removes an existing entry in the cache.
*
* @param metadata The metadata to remove.
* @return True if removed or does not exist. False otherwise.
*/
boolean remove(BrokerApplicationMetadata metadata);

/**
* Returns all entries in the app metadata cache.
*
* @return A List of {@link BrokerApplicationMetadata}.
*/
@NonNull
List<BrokerApplicationMetadata> getAll();

/**
* Removes all entries in the app metadata cache.
*
* @return True if the cache has been successfully cleared. False otherwise.
*/
boolean clear();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.microsoft.identity.common.internal.cache;
iambmelt marked this conversation as resolved.
Show resolved Hide resolved

import java.util.List;

/**
* A generic caching interface.
*
* @param <T> The object or metadata to cache.
*/
public interface ISimpleCache<T> {

/**
* Inserts a new T into the cache.
*
* @param t The item to insert.
* @return True, if inserted. False otherwise.
*/
boolean insert(T t);

/**
* Removes an existing T from the cache.
*
* @param t The item to remove.
* @return True if removed or does not exist. False otherwise.
*/
boolean remove(T t);

/**
* Gets all entries in the cache.
*
* @return The List of cache entries. May be empty, never null.
*/
List<T> getAll();

/**
* Removes all entries in the cache.
*
* @return True if the cache has been successfully cleared. False otherwise.
*/
boolean clear();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.microsoft.identity.common.internal.cache.registry;
iambmelt marked this conversation as resolved.
Show resolved Hide resolved

import com.google.gson.annotations.SerializedName;
import com.microsoft.identity.common.internal.cache.AbstractApplicationMetadata;

public class BrokerApplicationRegistryData extends AbstractApplicationMetadata {
iambmelt marked this conversation as resolved.
Show resolved Hide resolved

private static final class SerializedNames extends AbstractApplicationMetadata.SerializedNames {
static final String ALLOW_WPJ_ACCESS = "wpj_account_access_allowed";
}

@SerializedName(SerializedNames.ALLOW_WPJ_ACCESS)
private boolean mWpjAccountAccessAllowed;

public boolean isWpjAccountAccessAllowed() {
return mWpjAccountAccessAllowed;
}

public void setWpjAccountAccessAllowed(final boolean allow) {
mWpjAccountAccessAllowed = allow;
}

//CHECKSTYLE:OFF
// This method is generated. Checkstyle and/or PMD has been disabled.
// This method *must* be regenerated if the class' structural definition changes through the
// addition/subtraction of fields.
@SuppressWarnings("PMD")
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;

BrokerApplicationRegistryData that = (BrokerApplicationRegistryData) o;

return mWpjAccountAccessAllowed == that.mWpjAccountAccessAllowed;
}
//CHECKSTYLE:ON

//CHECKSTYLE:OFF
// This method is generated. Checkstyle and/or PMD has been disabled.
// This method *must* be regenerated if the class' structural definition changes through the
// addition/subtraction of fields.
@SuppressWarnings("PMD")
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (mWpjAccountAccessAllowed ? 1 : 0);
return result;
}
//CHECKSTYLE:ON
}
Loading