private Token parseToken(String parameter) { String tokenString = parameter; if (m_decodeBase64) { tokenString = StringUtils.decodeBase64(parameter); } return Token.parse(tokenString); }
/** * Creates a licene reference from an XML string. It is a shortcut for {@link #createFrom(java.io.Reader)} called with a * StringReader. In case the string is base 64 encoded it will be decoded first. * */ public static LicenseReference createFrom(final String ref) { return createFrom(new StringReader(StringUtils.decodeBase64(ref))); }
public String getUsername() { try { byte[] ticketArray = m_credentialText.getBytes("UTF-8"); SAMLTicket ticket; if (Base64.isArrayByteBase64(ticketArray)) { ticket = new SAMLTicket(StringUtils.decodeBase64(m_credentialText)); Subject subject = ticket.asSubject(""); for (Principal principal : subject.getPrincipals()) { if (principal instanceof UsernameIDPrincipal) { return ((UsernameIDPrincipal) principal).getName(); } } String ticketAsString = ticket.asString(); return (ticketAsString.length() > 40) ? ticketAsString.substring(0, 40) : ticketAsString; } } catch (UnsupportedEncodingException e) { // do nothing -> return ticket "as is" } catch (SAMLException e) { // do nothing -> return ticket "as is" } return m_credentialText; }
public AuthenticationContext authenticate(ServletRequestResponseContext requestCtx, AuthenticationService authService) throws AuthenticationException { HttpServletRequest request = requestCtx.getRequest(); String method = request.getMethod(); if ("GET".equals(method) && isDisableHttpGet()) { LOG.warn("Base64 credential login via HTTP GET not supported."); return null; } String cred = ServletUtils.getParameterValueEqualIgnoreCase(request, getCredentialParameterName()); if (cred == null || cred.isEmpty()) { return null; } String user; String pw; String authorizationString = StringUtils.decodeBase64(cred); int colon = authorizationString.indexOf(':'); if (colon < 0) { user = authorizationString; pw = null; } else { user = authorizationString.substring(0, colon); pw= authorizationString.substring(colon + 1); } CredentialsCallbackHandler callbackHandler = new CredentialsCallbackHandler(); callbackHandler.add(new UsernamePasswordCredential(user, pw)); callbackHandler.add(new IP4AddressCredential(request.getRemoteAddr())); return authService.login(callbackHandler); } };
/** * Responsible for adding http username and password to the http client as http basic authentication. * * @param httpRequest the http request. * @param pRequest the current request. */ protected void addHttpAuthentication(final HTTPRequest httpRequest, final Transferable pRequest) { TransferAttribute userattr = pRequest.getAttribute(TransferAttribute.HTTP_AUTH_BASIC_USERNAME); TransferAttribute pw = pRequest.getAttribute(TransferAttribute.HTTP_AUTH_BASIC_PASSWORD); if (userattr != null && userattr.getValue() != null) { String clearpw = pw != null ? (String) pw.getValue() : null; if (clearpw != null) { // password is hold in memory as base64 clearpw = StringUtils.decodeBase64(clearpw); } httpRequest.basicAuth((String) userattr.getValue(), clearpw.toCharArray()); } }
String password = null; String cred = authorizationHeaderValue.substring(6); String authorizationString = StringUtils.decodeBase64(cred);