use of org.broadleafcommerce.openadmin.server.security.domain.AdminPermission in project BroadleafCommerce by BroadleafCommerce.
the class AdminPermissionDaoImpl method readAdminPermissionByNameAndType.
@Override
public AdminPermission readAdminPermissionByNameAndType(String name, String type) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<AdminPermission> criteria = builder.createQuery(AdminPermission.class);
Root<AdminPermissionImpl> adminPerm = criteria.from(AdminPermissionImpl.class);
criteria.select(adminPerm);
List<Predicate> restrictions = new ArrayList<Predicate>();
restrictions.add(builder.equal(adminPerm.get("name"), name));
restrictions.add(builder.equal(adminPerm.get("type"), type));
// Execute the query with the restrictions
criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
TypedQuery<AdminPermission> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "blAdminSecurityQuery");
List<AdminPermission> results = query.getResultList();
if (results == null || results.size() == 0) {
return null;
} else {
return results.get(0);
}
}
use of org.broadleafcommerce.openadmin.server.security.domain.AdminPermission in project BroadleafCommerce by BroadleafCommerce.
the class AdminPermissionDaoImpl method readAllAdminPermissions.
@SuppressWarnings("unchecked")
public List<AdminPermission> readAllAdminPermissions() {
Query query = em.createNamedQuery("BC_READ_ALL_ADMIN_PERMISSIONS");
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "blAdminSecurityQuery");
List<AdminPermission> permissions = query.getResultList();
return permissions;
}
use of org.broadleafcommerce.openadmin.server.security.domain.AdminPermission in project BroadleafCommerce by BroadleafCommerce.
the class AdminSecurityServiceRemote method getAdminUser.
@Override
public org.broadleafcommerce.openadmin.server.security.remote.AdminUser getAdminUser() throws ServiceException {
AdminUser persistentAdminUser = getPersistentAdminUser();
if (persistentAdminUser != null) {
org.broadleafcommerce.openadmin.server.security.remote.AdminUser response = new org.broadleafcommerce.openadmin.server.security.remote.AdminUser();
for (AdminRole role : persistentAdminUser.getAllRoles()) {
response.getRoles().add(role.getName());
for (AdminPermission permission : role.getAllPermissions()) {
response.getPermissions().add(permission.getName());
}
}
for (AdminPermission permission : persistentAdminUser.getAllPermissions()) {
response.getPermissions().add(permission.getName());
}
response.setUserName(persistentAdminUser.getLogin());
response.setCurrentSandBoxId(String.valueOf(SandBoxContext.getSandBoxContext().getSandBoxId()));
response.setEmail(persistentAdminUser.getEmail());
response.setName(persistentAdminUser.getName());
response.setPhoneNumber(persistentAdminUser.getPhoneNumber());
response.setId(persistentAdminUser.getId());
return response;
}
return null;
}
use of org.broadleafcommerce.openadmin.server.security.domain.AdminPermission in project BroadleafCommerce by BroadleafCommerce.
the class AdminPermissionTest method testAdminPermissionSave.
@Test(groups = { "testAdminPermissionSave" }, dataProvider = "setupAdminPermission", dataProviderClass = AdminPermissionDataProvider.class)
@Rollback(true)
public void testAdminPermissionSave(AdminPermission permission) throws Exception {
AdminPermission newPermission = adminSecurityService.saveAdminPermission(permission);
AdminPermission permissionFromDB = adminSecurityService.readAdminPermissionById(newPermission.getId());
assert (permissionFromDB != null);
}
use of org.broadleafcommerce.openadmin.server.security.domain.AdminPermission in project BroadleafCommerce by BroadleafCommerce.
the class AdminPermissionDataProvider method createAdminUser.
@DataProvider(name = "setupAdminPermission")
public static Object[][] createAdminUser() {
AdminPermission adminPermission = new AdminPermissionImpl();
adminPermission.setName("TestAdminPermissionName");
adminPermission.setDescription("Test Admin Permission Description");
adminPermission.setType(PermissionType.ALL);
return new Object[][] { new Object[] { adminPermission } };
}
Aggregations