Limit access in app areas to different users

Asked

Viewed 748 times

0

I’m working on an app project for a company and I ended up getting into a problem I didn’t find how to review it.

I would like to limit access to certain parts of the app to different users.

Ex.: would like the company administrators with their logins to see things in the app that employees, with their logins, could not see.

  • Allow exclusive pages to administrators only, making other users unable to access.

I’m using Firebase and Android Studio, would like to know if there is a class or API for this.

  • 1

    You can use the logic of our friend Edson Reis, I have no knowledge of Android development, but usually for permissions is made in the way he quoted. Another cool way is to create a class that will carry out the control of the pages by user level, inside you can put a switch case Czech will return a array or other amounts authorizing or not access. You could return a boolean and play all admin pages within an array for example. Then just check the switch case to see if administrators have access to a particular page.

  • I decided not to answer your question with an example, because by not understand Android programming may not be what you expect.

  • In short, make a method: private Boolean checaAcessoPagina(String nivelPermissao){} - within the method use a switch case(nivelPermissao) to differentiate levels, can be "admin, user, Visitor, etc". So now it’s up to you, just a more practical suggestion.

  • Check out this discussion (I don’t know if I can post external links here): http://respostas.guj.com.br/1529-controle-de-acesso-com-android

2 answers

1

1.You have to have value that defines who is admin or user in your user database. Example: nivel = "admin" level = "function"

  1. You can use Realtime Database Firebase. to create a new user. Example.

    private void writeNewUserIfNeeded(final String userId, final String username, final String name) {
    final DatabaseReference usersRef = rootRef.child("users").child(userId);
    
    usersRef.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (!dataSnapshot.exists())
                usersRef.setValue(new User(username, name));
        }
    
        @Override
        public void onCancelled(DatabaseError databaseError) {
    
        }
    });
    

    }

3.Every screen call you want to limit to the user level you has to make a condition. Example:

       if(user.nivel.equals("admin")){

        //ABRIR A TELA PARA ADMIN
        }else{
        // BLOQUEADO! 
        }

0

You could add viewing conditions, for example:

When logging in the method would return the group in which that user would belong

public GrupoDeUsuario autenticar(usuario, senha){

} 

boolean isAdm = GrupoDeUsuario.Administrador;

In your Views you could check and only show the View if it was for the interest group

btnAcessoPeloAdm = findViewByID(R.id.btnAdm);
btnAcessoPeloAdm.setVisibility(isAdm ? View.VISIBLE : View.GONE);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.