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,100 @@
// Copyright (c) Microsoft Corporation.
// All rights reserved.
//
// This code is licensed under the MIT License.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
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 @@ -23,6 +23,7 @@
package com.microsoft.identity.common.internal.cache;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
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,61 @@
// Copyright (c) Microsoft Corporation.
// All rights reserved.
//
// This code is licensed under the MIT License.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
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.
*/
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();
}
Loading