Java Code Examples for jcifs.util.Base64#decode()

The following examples show how to use jcifs.util.Base64#decode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NTLMSchemeFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Type2Message decodeType2Message(String challenge) throws NTLMEngineException {
    try {
        return new Type2Message(Base64.decode(challenge));
    } catch (final IOException exception) {
        throw new NTLMEngineException("Invalid Type2 message", exception);
    }
}
 
Example 2
Source File: NTLMSchemeFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Type2Message decodeType2Message(String challenge) throws NTLMEngineException {
    try {
        return new Type2Message(Base64.decode(challenge));
    } catch (final IOException exception) {
        throw new NTLMEngineException("Invalid Type2 message", exception);
    }
}
 
Example 3
Source File: SpnegoCredentialsAction.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
@Override
protected Credential constructCredentialsFromRequest(
        final RequestContext context) {
    final HttpServletRequest request = WebUtils
            .getHttpServletRequest(context);

    final String authorizationHeader = request
            .getHeader(SpnegoConstants.HEADER_AUTHORIZATION);

    if (StringUtils.hasText(authorizationHeader)
            && authorizationHeader.startsWith(this.messageBeginPrefix)
            && authorizationHeader.length() > this.messageBeginPrefix.length()) {
        if (logger.isDebugEnabled()) {
            logger.debug("SPNEGO Authorization header found with "
                    + (authorizationHeader.length() - this.messageBeginPrefix
                            .length()) + " bytes");
        }
        final byte[] token = Base64.decode(authorizationHeader
                .substring(this.messageBeginPrefix.length()));
        if (logger.isDebugEnabled()) {
            logger.debug("Obtained token: " + new String(token));
        }
        return new SpnegoCredential(token);
    }

    return null;
}
 
Example 4
Source File: NTLMSchemeFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Type2Message decodeType2Message(String challenge) throws NTLMEngineException {
    try {
        return new Type2Message(Base64.decode(challenge));
    } catch (final IOException exception) {
        throw new NTLMEngineException("Invalid Type2 message", exception);
    }
}
 
Example 5
Source File: NTLMSchemeFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Type2Message decodeType2Message(String challenge) throws NTLMEngineException {
    try {
        return new Type2Message(Base64.decode(challenge));
    } catch (final IOException exception) {
        throw new NTLMEngineException("Invalid Type2 message", exception);
    }
}
 
Example 6
Source File: URLFetcher.java    From PADListener with GNU General Public License v2.0 4 votes vote down vote up
private String constructAuthenticationHeader(String[] challenges, String credentials, String url, String method) {
    /* credentials string looks like:
     * Basic BASE64(username:password)
     * or
     * Digest BASE64(username:password
     * or)
     * NTLM BASE64(domain\ username:password)
     */
    // _logger.info("Constructing auth header from " + credentials);
    if (credentials == null)
        return null;
    if (credentials.startsWith("Basic")) {
        return credentials;
    }
    if (credentials.startsWith("Digest") && challenges != null && challenges.length > 0){
        // digest handshake
        String proxyAuthHeader = challenges[0];
        int i = proxyAuthHeader.indexOf(' ');
        String authParameters = proxyAuthHeader.substring(i + 1);
        String realm = "";
        String nonce = "";
        String QOP   = "";
        String algorithm = "";
        String opaque = "";
        boolean stale;
        if (authParameters != null) {
            int parPos;
            do {
                parPos = authParameters.indexOf(',');
                if (parPos < 0) {
                    // have only one parameter
                    // parseParameter(authParameters);
                } else {
                    String tokenVal = authParameters.substring(0,parPos);
                    int tokenValPos = tokenVal.indexOf('=');
                    if (tokenValPos >= 0) {
                        String token = tokenVal.substring(0, tokenValPos).trim();
                        String value = AuthDigestManager.trimDoubleQuotesIfAny(tokenVal.substring(tokenValPos + 1).trim());
                        
                        if (token.equalsIgnoreCase(AuthDigestManager.REALM_TOKEN)) {
                            realm = value;
                        }
                        if (token.equalsIgnoreCase(AuthDigestManager.NONCE_TOKEN)) {
                            nonce = value;
                        }
                        if (token.equalsIgnoreCase(AuthDigestManager.STALE_TOKEN)) {
                            if (value.equalsIgnoreCase("true")) {
                                stale = true;
                            }
                        }
                        if (token.equalsIgnoreCase(AuthDigestManager.OPAQUE_TOKEN)) {
                            opaque = value;
                        }
                        if (token.equalsIgnoreCase(AuthDigestManager.QOP_TOKEN)) {
                            QOP = value.toLowerCase();
                        }
                        if (token.equalsIgnoreCase(AuthDigestManager.ALGORITHM_TOKEN)) {
                            algorithm = value.toLowerCase();
                        }
                        authParameters = authParameters.substring(parPos + 1);
                    }
                }
            } while (parPos >= 0);
        }
        String userNamePassword = credentials.substring(credentials.indexOf(" ") + 1);
        userNamePassword = new String(Base64.decode(userNamePassword)); // decode the base64
        String username = userNamePassword.substring(0, userNamePassword.indexOf(":"));
        String password = userNamePassword.substring(username.length() + 1);
        return "Digest " + AuthDigestManager.computeDigestAuthResponse(username, password, realm, nonce, QOP, algorithm, opaque, method, url);
    }
    if (challenges != null) {
        for (int i=0; i<challenges.length; i++) {
            if (LOGD) _logger.fine("Challenge: " + challenges[i]);
            if (challenges[i].startsWith("NTLM") && credentials.startsWith("NTLM")) {
                return attemptNegotiation(challenges[i], credentials);
            }
            if (challenges[i].startsWith("Negotiate") && credentials.startsWith("Negotiate")) {
                if (LOGD) _logger.fine("Attempting 'Negotiate' Authentication");
                return attemptNegotiation(challenges[i], credentials);
            }
            if (LOGD) _logger.info("Can't do auth for " + challenges[i]);
        }
    }
    return credentials;
}