Search in sources :

Example 1 with AuthorizationTypeIterator

use of com.amplifyframework.core.model.auth.AuthorizationTypeIterator in project amplify-android by aws-amplify.

the class MultiAuthModeStrategy method authTypesFor.

@Override
public AuthorizationTypeIterator authTypesFor(@NonNull ModelSchema modelSchema, @NonNull ModelOperation operation) {
    final List<AuthRule> applicableRules = new ArrayList<>();
    Consumer<List<AuthRule>> filterAuthRules = authRules -> {
        for (AuthRule rule : authRules) {
            if (rule.getOperationsOrDefault().contains(operation)) {
                applicableRules.add(rule);
            }
        }
    };
    filterAuthRules.accept(modelSchema.getAuthRules());
    for (ModelField field : modelSchema.getFields().values()) {
        filterAuthRules.accept(field.getAuthRules());
    }
    return new MultiAuthorizationTypeIterator(applicableRules);
}
Also used : Consumer(com.amplifyframework.core.Consumer) List(java.util.List) AuthorizationTypeIterator(com.amplifyframework.core.model.auth.AuthorizationTypeIterator) MultiAuthorizationTypeIterator(com.amplifyframework.core.model.auth.MultiAuthorizationTypeIterator) NonNull(androidx.annotation.NonNull) AuthRule(com.amplifyframework.core.model.AuthRule) ModelSchema(com.amplifyframework.core.model.ModelSchema) ModelOperation(com.amplifyframework.core.model.ModelOperation) ModelField(com.amplifyframework.core.model.ModelField) ArrayList(java.util.ArrayList) MultiAuthorizationTypeIterator(com.amplifyframework.core.model.auth.MultiAuthorizationTypeIterator) ModelField(com.amplifyframework.core.model.ModelField) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) AuthRule(com.amplifyframework.core.model.AuthRule)

Aggregations

NonNull (androidx.annotation.NonNull)1 Consumer (com.amplifyframework.core.Consumer)1 AuthRule (com.amplifyframework.core.model.AuthRule)1 ModelField (com.amplifyframework.core.model.ModelField)1 ModelOperation (com.amplifyframework.core.model.ModelOperation)1 ModelSchema (com.amplifyframework.core.model.ModelSchema)1 AuthorizationTypeIterator (com.amplifyframework.core.model.auth.AuthorizationTypeIterator)1 MultiAuthorizationTypeIterator (com.amplifyframework.core.model.auth.MultiAuthorizationTypeIterator)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1