REST API - Anonymous Access

HI,
As per the document I setup REST API ‘add on’.
Then created new entity…
Updated application.properties file with jmix.rest.anonymousUrlPatterns=/rest/entities/Country
And also set up initAnonymousUser() with rest-minimal role .
Still I getting issue while hitting REST API - Reading forbidden

Hi
Have you assigned the rest API role to the user?

Yes, In DatabaseUserRepository I updated initAnonymousUser() with rest-minimal role.

I see you are trying to access Entity Country, did you also give REST user access to this entity?

I am trying to set AnonymousUser access.Is there any way to setup Anonymous user access to on Entity. Can you please let us know the steps

Apart from setting the jmix.rest.anonymousUrlPatterns=/rest/entities/Country property, you should give the anonymous user rights to the Country entity. For example, create a resource role:

package com.company.demo.security;

import com.company.demo.entity.Country;
import io.jmix.security.model.EntityAttributePolicyAction;
import io.jmix.security.model.EntityPolicyAction;
import io.jmix.security.role.annotation.EntityAttributePolicy;
import io.jmix.security.role.annotation.EntityPolicy;
import io.jmix.security.role.annotation.ResourceRole;

@ResourceRole(name = "AnonymousRestRole", code = AnonymousRestRole.CODE, scope = "API")
public interface AnonymousRestRole {

    String CODE = "anonymous-rest-role";

    @EntityAttributePolicy(entityClass = Country.class, attributes = "*", action = EntityAttributePolicyAction.VIEW)
    @EntityPolicy(entityClass = Country.class, actions = EntityPolicyAction.READ)
    void country();
}

The assign it to the anonymous user:

@Primary
@Component("UserRepository")
public class DatabaseUserRepository extends AbstractDatabaseUserRepository<User> {
    // ...
    @Override
    protected void initAnonymousUser(User anonymousUser) {
        Collection<GrantedAuthority> authorities = getGrantedAuthoritiesBuilder()
                .addResourceRole(AnonymousRestRole.CODE)
                .build();
        anonymousUser.setAuthorities(authorities);
    }
}