0

As we know, one of the methods of accessing objects is using the spring security acl method. In this method, after performing a set of settings and storing the data needed, using the following method, we will check the user's access to do something in the method. Consider a project with the structure shown in the figure below. In this graph, each user has access to a single department, so if the information is create on the system, it should be based on this access. For example, the user should not be able to register a job for a worker who is not in his or her authorized department.

public class Department {
    String departmentName;
    List<Employee> employeeList;

}

public class Employee {
    Department department;
    List<Job> jobList;
}

public class Job {
    String jobTitle;
    Employee employee;
}

public class User {
    String username;
    List<Department> departmentList;
}



@Transactional
@PreAuthorize("hasPermission(#job.employee.department.id, ‘Department’, 'write')")
public void save(Job job) {
    super.save(job);
    //TODO 
}

Consider that the information sent to the UI layer is sent as JSON. In this case, for the job insert, the JSON needs to be as follows.

{
    jobTitle:”CTO”,
    employee:{
           id:1
        }
}

This information is converted to the Job object in the controller layer, and then the save method is called in the service layer. In this case, the access given is not working, as job.employee.department.id is null. To determine what this should be, do I need to load this object in the controller based on id? Is there a way other than ACL?

ali akbar azizkhani
  • 2,213
  • 5
  • 31
  • 48
  • As far as I understood your question you are looking for a way to only execute the `save` method if a job is created for the same department the employee, who's triggering the save method, works for? Though you don't specify the department explicitely as this maybe is implicitly determined by the user invoking the task? In that particular case you should better check if the employee is allowed to inovke the save method by examine his assigned roles or permissions. If the department is mandatory you should retrun an error to the user creating the job. – Roman Vottner Nov 04 '17 at 17:50
  • when i want save job i just need jobTitle and employee id . but when check security i need job.employee.department.id – ali akbar azizkhani Nov 04 '17 at 17:55
  • my ui application is create with angular js and spring rest controller – ali akbar azizkhani Nov 04 '17 at 17:56

0 Answers0