1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.core.logic;
20
21 import java.util.List;
22 import java.util.Optional;
23 import java.util.stream.Collectors;
24 import org.apache.commons.lang3.tuple.Pair;
25 import org.apache.syncope.common.lib.to.AuthProfileTO;
26 import org.apache.syncope.common.lib.types.AMEntitlement;
27 import org.apache.syncope.core.persistence.api.dao.AuthProfileDAO;
28 import org.apache.syncope.core.persistence.api.dao.NotFoundException;
29 import org.apache.syncope.core.persistence.api.entity.am.AuthProfile;
30 import org.apache.syncope.core.provisioning.api.data.AuthProfileDataBinder;
31 import org.springframework.security.access.prepost.PreAuthorize;
32 import org.springframework.transaction.annotation.Transactional;
33
34 public class AuthProfileLogic extends AbstractAuthProfileLogic {
35
36 public AuthProfileLogic(final AuthProfileDAO authProfileDAO, final AuthProfileDataBinder binder) {
37 super(authProfileDAO, binder);
38 }
39
40 @PreAuthorize("hasRole('" + AMEntitlement.AUTH_PROFILE_DELETE + "') ")
41 public void delete(final String key) {
42 authProfileDAO.delete(key);
43 }
44
45 @PreAuthorize("hasRole('" + AMEntitlement.AUTH_PROFILE_READ + "') ")
46 @Transactional(readOnly = true)
47 public AuthProfileTO read(final String key) {
48 return Optional.ofNullable(authProfileDAO.find(key)).
49 map(binder::getAuthProfileTO).
50 orElseThrow(() -> new NotFoundException(key + " not found"));
51 }
52
53 @PreAuthorize("hasRole('" + AMEntitlement.AUTH_PROFILE_CREATE + "') ")
54 public AuthProfileTO create(final AuthProfileTO authProfileTO) {
55 return binder.getAuthProfileTO(authProfileDAO.save(binder.create(authProfileTO)));
56 }
57
58 @PreAuthorize("hasRole('" + AMEntitlement.AUTH_PROFILE_UPDATE + "') ")
59 public void update(final AuthProfileTO authProfileTO) {
60 AuthProfile authProfile = Optional.ofNullable(authProfileDAO.find(authProfileTO.getKey())).
61 orElseThrow(() -> new NotFoundException(authProfileTO.getKey() + " not found"));
62 binder.update(authProfile, authProfileTO);
63 authProfileDAO.save(authProfile);
64 }
65
66 @PreAuthorize("hasRole('" + AMEntitlement.AUTH_PROFILE_LIST + "')")
67 @Transactional(readOnly = true)
68 public Pair<Integer, List<AuthProfileTO>> list(final int page, final int size) {
69 int count = authProfileDAO.count();
70
71 List<AuthProfileTO> result = authProfileDAO.findAll(page, size).
72 stream().
73 map(binder::getAuthProfileTO).
74 collect(Collectors.toList());
75
76 return Pair.of(count, result);
77 }
78 }