1
What hint would you give when for example a user cannot have access to an X object?
For example:
URL: /student/{id}
The user who is HEADMASTER of a school has access to the profile of all students of the school that he is headmaster The user who is a school teacher has access to the profile of all students in the classes he teaches
then how would I do it using the Springsecurity?
One more thing
I have a screen where I search for students, that famous screen where there are several filters, pagination and etc. There I also wanted to do something similar to the requirement above (from the URL).
I would want the search screen when the user was a teacher, in the list appeared only students of the classes he teaches and when principal of the school he runs. I thought of an interesting way, but I don’t know how to inject the correct implementation when creating the MVC Controller.
Example:
public interface AlunoRepository {
public List<Aluno> getAlunoByParams(Map<String, Object> params, int offset, int size);
}
Now follow the specific implementations for each PROFILE
Implementation specifies pro Teacher profile
public class AlunoRepositoryImpl4Professor implements AlunoRepository {
public List<Aluno> getAlunoByParams(Map<String, Object> params, int offset, int size){
return // retorna uma lista somente dos alunos das turmas que ele seleciona de acordo com os parametros
}
}
Implementation specifies Director profile pro
public class AlunoRepositoryImpl4Diretor implements AlunoRepository {
public List<Aluno> getAlunoByParams(Map<String, Object> params, int offset, int size){
return // retorna uma lista somente dos alunos da escola que ele dirige de acordo com os parametros
}
}
Controller
@Controller
public class AlunoController {
@AutoWired
private AlunoRepository repository; // como injetar o AlunoRepository de acordo com o perfil que esta sendo utilizado aqui?
@GET
public List<Alunos> query(Map<String, Object> params, int offset, int size){
return repository.getAlunoByParams(params, offset, size);
}
}