Java Code Examples for org.eclipse.jgit.util.Base64#decode()
The following examples show how to use
org.eclipse.jgit.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: PropertyBasedSshSessionFactory.java From spring-cloud-config with Apache License 2.0 | 6 votes |
@Override protected Session createSession(Host hc, String user, String host, int port, FS fs) throws JSchException { if (this.sshKeysByHostname.containsKey(host)) { JGitEnvironmentProperties sshUriProperties = this.sshKeysByHostname.get(host); this.jSch.addIdentity(host, sshUriProperties.getPrivateKey().getBytes(), null, null); if (sshUriProperties.getKnownHostsFile() != null) { this.jSch.setKnownHosts(sshUriProperties.getKnownHostsFile()); } if (sshUriProperties.getHostKey() != null) { HostKey hostkey = new HostKey(host, Base64.decode(sshUriProperties.getHostKey())); this.jSch.getHostKeyRepository().add(hostkey, null); } return this.jSch.getSession(user, host, port); } throw new JSchException("no keys configured for hostname " + host); }
Example 2
Source File: WebServer.java From git-as-svn with GNU General Public License v2.0 | 5 votes |
/** * Return current user information. * * @param authorization HTTP authorization header value. * @return Return value: * <ul> * <li>no authorization header - anonymous user;</li> * <li>invalid authorization header - null;</li> * <li>valid authorization header - user information.</li> * </ul> */ @Nullable public User getAuthInfo(@Nullable final String authorization, int tokenEnsureTime) { final UserDB userDB = context.sure(UserDB.class); // Check HTTP authorization. if (authorization == null) { return User.getAnonymous(); } if (authorization.startsWith(AUTH_BASIC)) { final String raw = new String(Base64.decode(authorization.substring(AUTH_BASIC.length()).trim()), StandardCharsets.UTF_8); final int separator = raw.indexOf(':'); if (separator > 0) { final String username = raw.substring(0, separator); final String password = raw.substring(separator + 1); try { return userDB.check(username, password); } catch (SVNException e) { log.error("Authorization error: " + e.getMessage(), e); } } return null; } if (authorization.startsWith(AUTH_TOKEN)) { return TokenHelper.parseToken(createEncryption(), authorization.substring(AUTH_TOKEN.length()).trim(), tokenEnsureTime); } return null; }
Example 3
Source File: GitUserHelper.java From fabric8-forge with Apache License 2.0 | 4 votes |
public UserDetails createUserDetails(HttpServletRequest request) { StopWatch watch = new StopWatch(); String user = gitUser; String password = gitPassword; String authorization = null; String emailHeader = null; // lets try custom headers or request parameters if (request != null) { authorization = request.getHeader("GogsAuthorization"); if (Strings.isNullOrEmpty(authorization)) { authorization = request.getParameter(Constants.RequestParameters.GOGS_AUTH); } emailHeader = request.getHeader("GogsEmail"); if (Strings.isNullOrEmpty(emailHeader)) { emailHeader = request.getParameter(Constants.RequestParameters.GOGS_EMAIL); } } if (!Strings.isNullOrEmpty(authorization)) { String basicPrefix = "basic"; String lower = authorization.toLowerCase(); if (lower.startsWith(basicPrefix)) { String base64Credentials = authorization.substring(basicPrefix.length()).trim(); String credentials = new String(Base64.decode(base64Credentials), Charset.forName("UTF-8")); // credentials = username:password String[] values = credentials.split(":", 2); if (values != null && values.length > 1) { user = values[0]; password = values[1]; } } } String email = "[email protected]"; if (!Strings.isNullOrEmpty(emailHeader)) { email = emailHeader; } if (Strings.isNullOrEmpty(address)) { address = getGogsURL(true); internalAddress = getGogsURL(false); if (!address.endsWith("/")) { address += "/"; } if (!internalAddress.endsWith("/")) { internalAddress += "/"; } } LOG.info("createUserDetails took " + watch.taken()); return new UserDetails(address, internalAddress, user, password, email); }