Search in sources :

Example 1 with SmbAuthException

use of jcifs.smb.SmbAuthException in project cas by apereo.

the class NtlmAuthenticationHandler method doAuthentication.

@Override
protected AuthenticationHandlerExecutionResult doAuthentication(final Credential credential) throws GeneralSecurityException {
    val ntlmCredential = (SpnegoCredential) credential;
    val src = ntlmCredential.getInitToken();
    var success = false;
    try {
        val dc = getUniAddress();
        val challenge = SmbSession.getChallenge(dc);
        switch(src[NTLM_TOKEN_TYPE_FIELD_INDEX]) {
            case NTLM_TOKEN_TYPE_ONE:
                LOGGER.debug("Type 1 received");
                val type1 = new Type1Message(src);
                val type2 = new Type2Message(type1, challenge, null);
                LOGGER.debug("Type 2 returned. Setting next token.");
                ntlmCredential.setNextToken(type2.toByteArray());
                break;
            case NTLM_TOKEN_TYPE_THREE:
                LOGGER.debug("Type 3 received");
                val type3 = new Type3Message(src);
                val lmResponse = type3.getLMResponse() == null ? ArrayUtils.EMPTY_BYTE_ARRAY : type3.getLMResponse();
                val ntResponse = type3.getNTResponse() == null ? ArrayUtils.EMPTY_BYTE_ARRAY : type3.getNTResponse();
                val ntlm = new NtlmPasswordAuthentication(type3.getDomain(), type3.getUser(), challenge, lmResponse, ntResponse);
                LOGGER.debug("Trying to authenticate [{}] with domain controller", type3.getUser());
                try {
                    SmbSession.logon(dc, ntlm);
                    ntlmCredential.setPrincipal(this.principalFactory.createPrincipal(type3.getUser()));
                    success = true;
                } catch (final SmbAuthException sae) {
                    throw new FailedLoginException(sae.getMessage());
                }
                break;
            default:
                LOGGER.debug("Unknown type: [{}]", src[NTLM_TOKEN_TYPE_FIELD_INDEX]);
        }
    } catch (final Exception e) {
        throw new FailedLoginException(e.getMessage());
    }
    if (!success) {
        throw new FailedLoginException();
    }
    return new DefaultAuthenticationHandlerExecutionResult(this, new BasicCredentialMetaData(ntlmCredential), ntlmCredential.getPrincipal());
}
Also used : lombok.val(lombok.val) Type1Message(jcifs.ntlmssp.Type1Message) SpnegoCredential(org.apereo.cas.support.spnego.authentication.principal.SpnegoCredential) SmbAuthException(jcifs.smb.SmbAuthException) FailedLoginException(javax.security.auth.login.FailedLoginException) NtlmPasswordAuthentication(jcifs.smb.NtlmPasswordAuthentication) Type2Message(jcifs.ntlmssp.Type2Message) Type3Message(jcifs.ntlmssp.Type3Message) DefaultAuthenticationHandlerExecutionResult(org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult) GeneralSecurityException(java.security.GeneralSecurityException) FailedLoginException(javax.security.auth.login.FailedLoginException) SmbAuthException(jcifs.smb.SmbAuthException) BasicCredentialMetaData(org.apereo.cas.authentication.metadata.BasicCredentialMetaData)

Example 2 with SmbAuthException

use of jcifs.smb.SmbAuthException in project AmazeFileManager by TeamAmaze.

the class LoadFilesListTask method doInBackground.

@Override
protected Pair<OpenMode, ArrayList<LayoutElementParcelable>> doInBackground(Void... p) {
    HybridFile hFile = null;
    if (openmode == OpenMode.UNKNOWN) {
        hFile = new HybridFile(OpenMode.UNKNOWN, path);
        hFile.generateMode(ma.getActivity());
        openmode = hFile.getMode();
        if (hFile.isSmb()) {
            ma.smbPath = path;
        } else if (android.util.Patterns.EMAIL_ADDRESS.matcher(path).matches()) {
            openmode = OpenMode.ROOT;
        }
    }
    if (isCancelled())
        return null;
    ma.folder_count = 0;
    ma.file_count = 0;
    final ArrayList<LayoutElementParcelable> list;
    switch(openmode) {
        case SMB:
            if (hFile == null) {
                hFile = new HybridFile(OpenMode.SMB, path);
            }
            try {
                SmbFile[] smbFile = hFile.getSmbFile(5000).listFiles();
                list = ma.addToSmb(smbFile, path);
                openmode = OpenMode.SMB;
            } catch (SmbAuthException e) {
                if (!e.getMessage().toLowerCase().contains("denied")) {
                    ma.reauthenticateSmb();
                }
                return null;
            } catch (SmbException | NullPointerException e) {
                e.printStackTrace();
                return null;
            }
            break;
        case SFTP:
            HybridFile sftpHFile = new HybridFile(OpenMode.SFTP, path);
            list = new ArrayList<LayoutElementParcelable>();
            sftpHFile.forEachChildrenFile(c, false, file -> {
                LayoutElementParcelable elem = createListParcelables(file);
                if (elem != null)
                    list.add(elem);
            });
            break;
        case CUSTOM:
            switch(Integer.parseInt(path)) {
                case 0:
                    list = listImages();
                    break;
                case 1:
                    list = listVideos();
                    break;
                case 2:
                    list = listaudio();
                    break;
                case 3:
                    list = listDocs();
                    break;
                case 4:
                    list = listApks();
                    break;
                case 5:
                    list = listRecent();
                    break;
                case 6:
                    list = listRecentFiles();
                    break;
                default:
                    throw new IllegalStateException();
            }
            break;
        case OTG:
            list = new ArrayList<>();
            listOtg(path, new OnFileFound() {

                @Override
                public void onFileFound(HybridFileParcelable file) {
                    LayoutElementParcelable elem = createListParcelables(file);
                    if (elem != null)
                        list.add(elem);
                }
            });
            openmode = OpenMode.OTG;
            break;
        case DROPBOX:
        case BOX:
        case GDRIVE:
        case ONEDRIVE:
            CloudStorage cloudStorage = dataUtils.getAccount(openmode);
            list = new ArrayList<>();
            try {
                listCloud(path, cloudStorage, openmode, new OnFileFound() {

                    @Override
                    public void onFileFound(HybridFileParcelable file) {
                        LayoutElementParcelable elem = createListParcelables(file);
                        if (elem != null)
                            list.add(elem);
                    }
                });
            } catch (CloudPluginException e) {
                e.printStackTrace();
                AppConfig.toast(c, c.getResources().getString(R.string.failed_no_connection));
                return new Pair<>(openmode, list);
            }
            break;
        default:
            // we're neither in OTG not in SMB, load the list based on root/general filesystem
            list = new ArrayList<>();
            RootHelper.getFiles(path, ma.getMainActivity().isRootExplorer(), showHiddenFiles, new RootHelper.GetModeCallBack() {

                @Override
                public void getMode(OpenMode mode) {
                    openmode = mode;
                }
            }, new OnFileFound() {

                @Override
                public void onFileFound(HybridFileParcelable file) {
                    LayoutElementParcelable elem = createListParcelables(file);
                    if (elem != null)
                        list.add(elem);
                }
            });
            break;
    }
    if (list != null && !(openmode == OpenMode.CUSTOM && ((path).equals("5") || (path).equals("6")))) {
        Collections.sort(list, new FileListSorter(ma.dsort, ma.sortby, ma.asc));
    }
    return new Pair<>(openmode, list);
}
Also used : LayoutElementParcelable(com.amaze.filemanager.adapters.data.LayoutElementParcelable) OpenMode(com.amaze.filemanager.utils.OpenMode) SmbFile(jcifs.smb.SmbFile) SmbException(jcifs.smb.SmbException) HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) CloudStorage(com.cloudrail.si.interfaces.CloudStorage) HybridFile(com.amaze.filemanager.filesystem.HybridFile) CloudPluginException(com.amaze.filemanager.exceptions.CloudPluginException) SmbAuthException(jcifs.smb.SmbAuthException) RootHelper(com.amaze.filemanager.filesystem.RootHelper) FileListSorter(com.amaze.filemanager.utils.files.FileListSorter) OnFileFound(com.amaze.filemanager.utils.OnFileFound) Pair(android.support.v4.util.Pair)

Aggregations

SmbAuthException (jcifs.smb.SmbAuthException)2 Pair (android.support.v4.util.Pair)1 LayoutElementParcelable (com.amaze.filemanager.adapters.data.LayoutElementParcelable)1 CloudPluginException (com.amaze.filemanager.exceptions.CloudPluginException)1 HybridFile (com.amaze.filemanager.filesystem.HybridFile)1 HybridFileParcelable (com.amaze.filemanager.filesystem.HybridFileParcelable)1 RootHelper (com.amaze.filemanager.filesystem.RootHelper)1 OnFileFound (com.amaze.filemanager.utils.OnFileFound)1 OpenMode (com.amaze.filemanager.utils.OpenMode)1 FileListSorter (com.amaze.filemanager.utils.files.FileListSorter)1 CloudStorage (com.cloudrail.si.interfaces.CloudStorage)1 GeneralSecurityException (java.security.GeneralSecurityException)1 FailedLoginException (javax.security.auth.login.FailedLoginException)1 Type1Message (jcifs.ntlmssp.Type1Message)1 Type2Message (jcifs.ntlmssp.Type2Message)1 Type3Message (jcifs.ntlmssp.Type3Message)1 NtlmPasswordAuthentication (jcifs.smb.NtlmPasswordAuthentication)1 SmbException (jcifs.smb.SmbException)1 SmbFile (jcifs.smb.SmbFile)1 lombok.val (lombok.val)1