Search in sources :

Example 1 with CifsAcl

use of com.iwave.ext.netapp.model.CifsAcl in project coprhd-controller by CoprHD.

the class NetAppFileStorageDevice method addShareAcl.

private void addShareAcl(NetAppApi nApi, String shareName, List<ShareACL> aclsToAdd) {
    if (aclsToAdd == null || aclsToAdd.isEmpty()) {
        return;
    }
    List<CifsAcl> acls = new ArrayList<CifsAcl>();
    for (ShareACL newAcl : aclsToAdd) {
        CifsAcl cif_new = new CifsAcl();
        String domain = newAcl.getDomain();
        String userOrGroup = newAcl.getGroup() == null ? newAcl.getUser() : newAcl.getGroup();
        if (domain != null && !domain.isEmpty()) {
            userOrGroup = domain + "\\" + userOrGroup;
        }
        // for netapp api user and group are same.and need to set only user
        cif_new.setUserName(userOrGroup);
        cif_new.setShareName(shareName);
        cif_new.setAccess(getAccessEnum(newAcl.getPermission()));
        acls.add(cif_new);
    }
    nApi.modifyCIFSShareAcl(shareName, acls);
}
Also used : CifsAcl(com.iwave.ext.netapp.model.CifsAcl) ArrayList(java.util.ArrayList) ShareACL(com.emc.storageos.model.file.ShareACL)

Example 2 with CifsAcl

use of com.iwave.ext.netapp.model.CifsAcl in project coprhd-controller by CoprHD.

the class NetAppFileStorageDevice method deleteShareAcl.

private void deleteShareAcl(NetAppApi nApi, String shareName, List<ShareACL> aclsToDelete) {
    if (aclsToDelete == null || aclsToDelete.isEmpty()) {
        return;
    }
    List<CifsAcl> acls = new ArrayList<CifsAcl>();
    for (ShareACL newAcl : aclsToDelete) {
        CifsAcl cif_new = new CifsAcl();
        String domain = newAcl.getDomain();
        String userOrGroup = newAcl.getGroup() == null ? newAcl.getUser() : newAcl.getGroup();
        if (domain != null && !domain.isEmpty()) {
            userOrGroup = domain + "\\" + userOrGroup;
        }
        // for netapp api user and group are same.and need to set only user
        cif_new.setUserName(userOrGroup);
        cif_new.setShareName(shareName);
        cif_new.setAccess(getAccessEnum(newAcl.getPermission()));
        acls.add(cif_new);
    }
    nApi.deleteCIFSShareAcl(shareName, acls);
}
Also used : CifsAcl(com.iwave.ext.netapp.model.CifsAcl) ArrayList(java.util.ArrayList) ShareACL(com.emc.storageos.model.file.ShareACL)

Example 3 with CifsAcl

use of com.iwave.ext.netapp.model.CifsAcl in project coprhd-controller by CoprHD.

the class NetAppFileStorageDevice method forceDeleteShareAcl.

private void forceDeleteShareAcl(NetAppApi nApi, String shareName, List<ShareACL> aclsToDelete) {
    if (aclsToDelete == null || aclsToDelete.isEmpty()) {
        return;
    }
    List<CifsAcl> acls = new ArrayList<CifsAcl>();
    for (ShareACL newAcl : aclsToDelete) {
        CifsAcl cif_new = new CifsAcl();
        String domain = newAcl.getDomain();
        String userOrGroup = newAcl.getGroup() == null ? newAcl.getUser() : newAcl.getGroup();
        if (domain != null && !domain.isEmpty()) {
            userOrGroup = domain + "\\" + userOrGroup;
        }
        // for netapp api user and group are same.and need to set only user
        cif_new.setUserName(userOrGroup);
        cif_new.setShareName(shareName);
        cif_new.setAccess(getAccessEnum(newAcl.getPermission()));
        acls.add(cif_new);
    }
    for (CifsAcl cifsAcl : acls) {
        try {
            List<CifsAcl> singleACL = new ArrayList<CifsAcl>();
            singleACL.add(cifsAcl);
            nApi.deleteCIFSShareAcl(shareName, singleACL);
        } catch (Exception e) {
            _log.error("NetAppFileStorageDevice:: Force delete of ACL for user [" + cifsAcl.getUserName() + "] failed with an Exception", e);
        }
    }
}
Also used : CifsAcl(com.iwave.ext.netapp.model.CifsAcl) ArrayList(java.util.ArrayList) ShareACL(com.emc.storageos.model.file.ShareACL) ControllerException(com.emc.storageos.volumecontroller.ControllerException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) NetAppException(com.emc.storageos.netapp.NetAppException)

Example 4 with CifsAcl

use of com.iwave.ext.netapp.model.CifsAcl in project coprhd-controller by CoprHD.

the class NetAppFileCommunicationInterface method getACLs.

/**
 * get ACLs for smb shares of fs object
 *
 * @param unManagedSMBFileShareHashSet
 * @param netAppApi
 * @param fsId
 * @return
 */
private List<UnManagedCifsShareACL> getACLs(HashSet<UnManagedSMBFileShare> unManagedSMBFileShareHashSet, NetAppApi netAppApi, URI fsId) {
    // get list of acls for given set of shares
    UnManagedCifsShareACL unManagedCifsShareACL = null;
    List<UnManagedCifsShareACL> unManagedCifsShareACLList = new ArrayList<UnManagedCifsShareACL>();
    // get acls for each share
    List<CifsAcl> cifsAclList = null;
    if (unManagedSMBFileShareHashSet != null && !unManagedSMBFileShareHashSet.isEmpty()) {
        for (UnManagedSMBFileShare unManagedSMBFileShare : unManagedSMBFileShareHashSet) {
            // find acl for given share
            String unManagedSMBFileShareName = unManagedSMBFileShare.getName();
            _logger.info("New smb share name: {} and fs : {}", unManagedSMBFileShareName, fsId);
            cifsAclList = netAppApi.listCIFSShareAcl(unManagedSMBFileShareName);
            if (cifsAclList != null && !cifsAclList.isEmpty()) {
                for (CifsAcl cifsAcl : cifsAclList) {
                    _logger.info("Cifs share ACL: {} ", cifsAcl.toString());
                    unManagedCifsShareACL = new UnManagedCifsShareACL();
                    unManagedCifsShareACL.setShareName(unManagedSMBFileShareName);
                    String user = cifsAcl.getUserName();
                    if (user != null) {
                        unManagedCifsShareACL.setUser(user);
                    } else {
                        unManagedCifsShareACL.setGroup(cifsAcl.getGroupName());
                    }
                    // permission
                    unManagedCifsShareACL.setPermission(cifsAcl.getAccess().name());
                    unManagedCifsShareACL.setId(URIUtil.createId(UnManagedCifsShareACL.class));
                    // filesystem id
                    unManagedCifsShareACL.setFileSystemId(fsId);
                    // add the acl to acl-list
                    unManagedCifsShareACLList.add(unManagedCifsShareACL);
                }
            }
        }
    }
    return unManagedCifsShareACLList;
}
Also used : UnManagedCifsShareACL(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedCifsShareACL) UnManagedSMBFileShare(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBFileShare) CifsAcl(com.iwave.ext.netapp.model.CifsAcl) ArrayList(java.util.ArrayList)

Example 5 with CifsAcl

use of com.iwave.ext.netapp.model.CifsAcl in project coprhd-controller by CoprHD.

the class FileShare method listCIFSAcls.

public List<CifsAcl> listCIFSAcls(String shareName) {
    List<CifsAcl> acls = new ArrayList<CifsAcl>();
    NaElement elem = new NaElement("cifs-share-acl-list-iter-start");
    if (shareName != null && !shareName.isEmpty()) {
        // shareName can contain wildcards * or ?
        elem.addNewChild("share-name", shareName);
    }
    try {
        NaElement result = server.invokeElem(elem);
        String tag = result.getChildContent("tag");
        elem = new NaElement("cifs-share-acl-list-iter-next");
        elem.addNewChild("tag", tag);
        elem.addNewChild("maximum", MAX_LIST + "");
        List<NaElement> shareElems = server.invokeElem(elem).getChildByName("cifs-share-acls").getChildren();
        for (NaElement shareElem : shareElems) {
            String name = shareElem.getChildContent("share-name");
            shareElem = shareElem.getChildByName("user-acl-info");
            // Note: can't use shareElem.getChildByName("access-rights-info");
            // as this only gets the first element
            List<NaElement> infos = shareElem.getChildren();
            for (NaElement info : infos) {
                CifsAcl acl = new CifsAcl();
                acl.setShareName(name);
                String access = info.getChildContent("access-rights");
                try {
                    acl.setAccess(CifsAccess.valueOfAccess(access));
                } catch (IllegalArgumentException e) {
                    log.warn("Invalid permission for a CIFS share: " + name, e);
                    log.info("Continue with next acl");
                    continue;
                }
                String user = info.getChildContent("user-name");
                String group = info.getChildContent("unix-group-name");
                /*
                     * numeric groups are returned as users like: {gid:0}
                     */
                if (user != null && user.startsWith("{gid:")) {
                    int brace = user.indexOf('}');
                    group = user.substring(5, brace);
                    user = null;
                }
                acl.setUserName(user);
                acl.setGroupName(group);
                acls.add(acl);
            }
        }
        elem = new NaElement("cifs-share-list-iter-end");
        elem.addNewChild("tag", tag);
        server.invokeElem(elem);
        return acls;
    } catch (Exception e) {
        String msg = "Failed to list CIFS ACLs.";
        log.error(msg, e);
        throw new NetAppException(msg, e);
    }
}
Also used : CifsAcl(com.iwave.ext.netapp.model.CifsAcl) ArrayList(java.util.ArrayList) NaElement(netapp.manage.NaElement) NaAPIFailedException(netapp.manage.NaAPIFailedException)

Aggregations

CifsAcl (com.iwave.ext.netapp.model.CifsAcl)11 ArrayList (java.util.ArrayList)7 ShareACL (com.emc.storageos.model.file.ShareACL)4 NetAppFacade (com.iwave.ext.netapp.NetAppFacade)4 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)2 NetAppException (com.emc.storageos.netapp.NetAppException)2 ControllerException (com.emc.storageos.volumecontroller.ControllerException)2 UnManagedCifsShareACL (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedCifsShareACL)1 UnManagedSMBFileShare (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBFileShare)1 NetAppApi (com.emc.storageos.netapp.NetAppApi)1 NaAPIFailedException (netapp.manage.NaAPIFailedException)1 NaElement (netapp.manage.NaElement)1