org.springframework.extensions.surf.util.Base64 Java Examples
The following examples show how to use
org.springframework.extensions.surf.util.Base64.
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: BasicHttpAuthenticatorFactory.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
protected boolean isBasicAuthHeaderPresentForAdmin() { if (authorization == null || authorization.isEmpty()) { return false; } String[] authorizationParts = authorization.split(" "); if (!authorizationParts[0].equalsIgnoreCase("basic")) { return false; } String decodedAuthorisation = new String(Base64.decode(authorizationParts[1])); Authorization auth = new Authorization(decodedAuthorisation); if (auth.isTicket() || auth.getUserName() == null || auth.getUserName().isEmpty()) { return false; } // optimization: check the admin user name first if (AuthenticationUtil.getAdminUserName().equals(auth.getUserName())) { return true; } // then check the admin group return AuthenticationUtil.runAsSystem(() -> authorityService.isAdminAuthority(auth.getUserName())); }
Example #2
Source File: AbstractRemoteAlfrescoTicketImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Returns the Ticket in the form used for HTTP Basic Authentication. * This should be added as the value to a HTTP Request Header with * key Authorization */ public String getAsHTTPAuthorization() { // Build from the Username and Password Pair<String,String> userPass = getAsUsernameAndPassword(); Credentials credentials = new UsernamePasswordCredentials(userPass.getFirst(), userPass.getSecond()); // Encode it into the required format String credentialsEncoded = Base64.encodeBytes( credentials.toString().getBytes(utf8), Base64.DONT_BREAK_LINES ); // Mark it as Basic, and we're done return "Basic " + credentialsEncoded; }
Example #3
Source File: DefaultEncryptionUtils.java From alfresco-core with GNU Lesser General Public License v3.0 | 5 votes |
protected void setRequestMac(HttpMethod method, byte[] mac) { if(mac == null) { throw new AlfrescoRuntimeException("Mac cannot be null"); } method.setRequestHeader(HEADER_MAC, Base64.encodeBytes(mac)); }
Example #4
Source File: DefaultEncryptionUtils.java From alfresco-core with GNU Lesser General Public License v3.0 | 5 votes |
/** * Set the MAC on the HTTP response * * @param response HttpServletResponse * @param mac byte[] */ protected void setMac(HttpServletResponse response, byte[] mac) { if(mac == null) { throw new AlfrescoRuntimeException("Mac cannot be null"); } response.setHeader(HEADER_MAC, Base64.encodeBytes(mac)); }
Example #5
Source File: DefaultEncryptionUtils.java From alfresco-core with GNU Lesser General Public License v3.0 | 5 votes |
/** * Get the MAC (Message Authentication Code) on the HTTP request * * @param req HttpServletRequest * @return the MAC * @throws IOException */ protected byte[] getMac(HttpServletRequest req) throws IOException { String header = req.getHeader(HEADER_MAC); if(header != null) { return Base64.decode(header); } else { return null; } }
Example #6
Source File: DefaultEncryptionUtils.java From alfresco-core with GNU Lesser General Public License v3.0 | 5 votes |
/** * Get the MAC (Message Authentication Code) on the HTTP response * * @param res HttpMethod * @return the MAC * @throws IOException */ protected byte[] getResponseMac(HttpMethod res) throws IOException { Header header = res.getResponseHeader(HEADER_MAC); if(header != null) { return Base64.decode(header.getValue()); } else { return null; } }
Example #7
Source File: DefaultEncryptionUtils.java From alfresco-core with GNU Lesser General Public License v3.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void setRequestAlgorithmParameters(HttpMethod method, AlgorithmParameters params) throws IOException { if(params != null) { method.setRequestHeader(HEADER_ALGORITHM_PARAMETERS, Base64.encodeBytes(params.getEncoded())); } }
Example #8
Source File: DefaultEncryptionUtils.java From alfresco-core with GNU Lesser General Public License v3.0 | 5 votes |
/** * Set the algorithm parameters header on the HTTP response * * @param response HttpServletResponse * @param params AlgorithmParameters * @throws IOException */ protected void setAlgorithmParameters(HttpServletResponse response, AlgorithmParameters params) throws IOException { if(params != null) { response.setHeader(HEADER_ALGORITHM_PARAMETERS, Base64.encodeBytes(params.getEncoded())); } }
Example #9
Source File: DefaultEncryptionUtils.java From alfresco-core with GNU Lesser General Public License v3.0 | 5 votes |
/** * Decode cipher algorithm parameters from the HTTP method * * @param method HttpMethod * @return decoded algorithm parameters * @throws IOException */ protected AlgorithmParameters decodeAlgorithmParameters(HttpMethod method) throws IOException { Header header = method.getResponseHeader(HEADER_ALGORITHM_PARAMETERS); if(header != null) { byte[] algorithmParams = Base64.decode(header.getValue()); AlgorithmParameters algorithmParameters = encryptor.decodeAlgorithmParameters(algorithmParams); return algorithmParameters; } else { return null; } }
Example #10
Source File: DefaultEncryptionUtils.java From alfresco-core with GNU Lesser General Public License v3.0 | 5 votes |
/** * Decode cipher algorithm parameters from the HTTP method * * @param req * @return decoded algorithm parameters * @throws IOException */ protected AlgorithmParameters decodeAlgorithmParameters(HttpServletRequest req) throws IOException { String header = req.getHeader(HEADER_ALGORITHM_PARAMETERS); if(header != null) { byte[] algorithmParams = Base64.decode(header); AlgorithmParameters algorithmParameters = encryptor.decodeAlgorithmParameters(algorithmParams); return algorithmParameters; } else { return null; } }
Example #11
Source File: AuthenticationsImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
protected String getTicket(Parameters parameters) { // First check the alf_ticket in the URL final String alfTicket = parameters.getParameter(PARAM_ALF_TICKET); if (StringUtils.isNotEmpty(alfTicket)) { return alfTicket; } // Check the Authorization header final String authorization = parameters.getRequest().getHeader(AUTHORIZATION_HEADER); if (StringUtils.isEmpty(authorization)) { throw new InvalidArgumentException("Authorization header is required."); } final String[] authorizationParts = authorization.split(" "); if (authorizationParts[0].equalsIgnoreCase("basic")) { final String decodedAuthorisation = new String(Base64.decode(authorizationParts[1])); Authorization authObj = new Authorization(decodedAuthorisation); if (!authObj.isTicket()) { throw new InvalidArgumentException("Ticket base authentication required."); } return authObj.getTicket(); } else if (authorizationParts[0].equalsIgnoreCase("bearer")) { return getTicketFromRemoteUserMapperUserId(parameters); } throw new InvalidArgumentException("Authorization '" + authorizationParts[0] + "' not supported."); }