Search in sources :

Example 1 with AdminPermission

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);
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) AdminPermission(org.broadleafcommerce.openadmin.server.security.domain.AdminPermission) AdminPermissionImpl(org.broadleafcommerce.openadmin.server.security.domain.AdminPermissionImpl) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate)

Example 2 with AdminPermission

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;
}
Also used : CriteriaQuery(javax.persistence.criteria.CriteriaQuery) TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) AdminPermission(org.broadleafcommerce.openadmin.server.security.domain.AdminPermission)

Example 3 with AdminPermission

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;
}
Also used : AdminPermission(org.broadleafcommerce.openadmin.server.security.domain.AdminPermission) AdminUser(org.broadleafcommerce.openadmin.server.security.domain.AdminUser) AdminRole(org.broadleafcommerce.openadmin.server.security.domain.AdminRole)

Example 4 with AdminPermission

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);
}
Also used : AdminPermission(org.broadleafcommerce.openadmin.server.security.domain.AdminPermission) Test(org.testng.annotations.Test) Rollback(org.springframework.test.annotation.Rollback)

Example 5 with AdminPermission

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 } };
}
Also used : AdminPermission(org.broadleafcommerce.openadmin.server.security.domain.AdminPermission) AdminPermissionImpl(org.broadleafcommerce.openadmin.server.security.domain.AdminPermissionImpl) DataProvider(org.testng.annotations.DataProvider)

Aggregations

AdminPermission (org.broadleafcommerce.openadmin.server.security.domain.AdminPermission)9 AdminPermissionImpl (org.broadleafcommerce.openadmin.server.security.domain.AdminPermissionImpl)3 ArrayList (java.util.ArrayList)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 Predicate (javax.persistence.criteria.Predicate)2 ServiceException (org.broadleafcommerce.common.exception.ServiceException)2 Entity (org.broadleafcommerce.openadmin.dto.Entity)2 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)2 PersistencePerspective (org.broadleafcommerce.openadmin.dto.PersistencePerspective)2 AdminRole (org.broadleafcommerce.openadmin.server.security.domain.AdminRole)2 Query (javax.persistence.Query)1 TypedQuery (javax.persistence.TypedQuery)1 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)1 CriteriaTransferObject (org.broadleafcommerce.openadmin.dto.CriteriaTransferObject)1 AdminUser (org.broadleafcommerce.openadmin.server.security.domain.AdminUser)1 Rollback (org.springframework.test.annotation.Rollback)1 DataProvider (org.testng.annotations.DataProvider)1 Test (org.testng.annotations.Test)1