org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException Java Examples
The following examples show how to use
org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException.
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: RemoteExistsMojo.java From exists-maven-plugin with Apache License 2.0 | 6 votes |
AuthenticationInfo getAuthInfo(String serverId) throws SecDispatcherException { Server server = settings.getServer(serverId); if (server == null) { return null; } /* begin https://github.com/chonton/exists-maven-plugin/issues/22 */ if (securityDispatcher instanceof DefaultSecDispatcher) { ((DefaultSecDispatcher) securityDispatcher) .setConfigurationFile("~/.m2/settings-security.xml"); } /* end https://github.com/chonton/exists-maven-plugin/issues/22 */ AuthenticationInfo authInfo = new AuthenticationInfo(); authInfo.setUserName(server.getUsername()); authInfo.setPassword(securityDispatcher.decrypt(server.getPassword())); authInfo.setPassphrase(server.getPassphrase()); authInfo.setPrivateKey(server.getPrivateKey()); return authInfo; }
Example #2
Source File: SecDispatcherImpl.java From quarkus with Apache License 2.0 | 5 votes |
private SettingsSecurity getSec() throws SecDispatcherException { String location = System.getProperty(SYSTEM_PROPERTY_SEC_LOCATION, getConfigurationFile()); String realLocation = location.charAt(0) == '~' ? System.getProperty("user.home") + location.substring(1) : location; SettingsSecurity sec = SecUtil.read(realLocation, true); if (sec == null) throw new SecDispatcherException( "cannot retrieve master password. Please check that " + realLocation + " exists and has data"); return sec; }
Example #3
Source File: SecDispatcherImpl.java From quarkus with Apache License 2.0 | 5 votes |
private String getMaster(SettingsSecurity sec) throws SecDispatcherException { String master = sec.getMaster(); if (master == null) throw new SecDispatcherException("master password is not set"); try { return _cipher.decryptDecorated(master, SYSTEM_PROPERTY_SEC_LOCATION); } catch (PlexusCipherException e) { throw new SecDispatcherException(e); } }
Example #4
Source File: AbstractHelmMojo.java From helm-maven-plugin with MIT License | 5 votes |
/** * Get credentials for given helm repo. If username is not provided the repo * name will be used to search for credentials in <code>settings.xml</code>. * * @param repository Helm repo with id and optional credentials. * @return Authentication object or <code>null</code> if no credentials are present. * @throws IllegalArgumentException Unable to get authentication because of misconfiguration. * @throws MojoExecutionException Unable to get password from settings.xml */ PasswordAuthentication getAuthentication(HelmRepository repository) throws IllegalArgumentException, MojoExecutionException { String id = repository.getName(); if (repository.getUsername() != null) { if (repository.getPassword() == null) { throw new IllegalArgumentException("Repo " + id + " has a username but no password defined."); } getLog().debug("Repo " + id + " has credentials definded, skip searching in server list."); return new PasswordAuthentication(repository.getUsername(), repository.getPassword().toCharArray()); } Server server = settings.getServer(id); if (server == null) { getLog().info("No credentials found for " + id + " in configuration or settings.xml server list."); return null; } getLog().debug("Use credentials from server list for " + id + "."); if (server.getUsername() == null || server.getPassword() == null) { throw new IllegalArgumentException("Repo " + id + " was found in server list but has no username/password."); } try { return new PasswordAuthentication(server.getUsername(), getSecDispatcher().decrypt(server.getPassword()).toCharArray()); } catch (SecDispatcherException e) { throw new MojoExecutionException(e.getMessage()); } }
Example #5
Source File: AbstractBaseConfluenceMojo.java From maven-confluence-plugin with Apache License 2.0 | 5 votes |
/** * Issue 39 * * Load username password from settings if user has not set them in JVM properties * * @throws MojoExecutionException */ private void loadUserInfoFromSettings() throws MojoExecutionException { if ((getUsername() == null || getPassword() == null) && (mavenSettings != null)) { if (this.serverId == null) throw new MojoExecutionException("'serverId' must be set! (username and/or password are not provided)"); Server server = this.mavenSettings.getServer(this.serverId); if (server == null) throw new MojoExecutionException(String.format("server with id [%s] not found in settings!", this.serverId)); if (getUsername() == null && server.getUsername() != null) username = server.getUsername(); if (getPassword() == null && server.getPassword() != null) { try { // // FIX to resolve // org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException: // java.io.FileNotFoundException: ~/.settings-security.xml (No such file or directory) // if (securityDispatcher instanceof DefaultSecDispatcher) { //System.setProperty( DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION, sb.toString() ); ((DefaultSecDispatcher) securityDispatcher).setConfigurationFile("~/.m2/settings-security.xml"); } password = securityDispatcher.decrypt(server.getPassword()); } catch (SecDispatcherException e) { throw new MojoExecutionException(e.getMessage()); } } } }
Example #6
Source File: SignConfig.java From webstart with MIT License | 5 votes |
private String decrypt(String encoded ) throws MojoExecutionException { try { return securityDispatcher.decrypt( encoded ); } catch ( SecDispatcherException e ) { throw new MojoExecutionException( "error using security dispatcher: " + e.getMessage(), e ); } }
Example #7
Source File: AbstractScmMojo.java From buildnumber-maven-plugin with MIT License | 5 votes |
private String decrypt( String str, String server ) { try { return securityDispatcher.decrypt( str ); } catch ( SecDispatcherException e ) { getLog().warn( "Failed to decrypt password/passphrase for server " + server + ", using auth token as is" ); return str; } }
Example #8
Source File: AbstractDockerMojo.java From docker-maven-plugin with Apache License 2.0 | 5 votes |
/** * Builds the registryAuth object from server details. * @return {@link RegistryAuth} * @throws MojoExecutionException */ protected RegistryAuth registryAuth() throws MojoExecutionException { if (settings != null && serverId != null) { final Server server = settings.getServer(serverId); if (server != null) { final RegistryAuth.Builder registryAuthBuilder = RegistryAuth.builder(); final String username = server.getUsername(); String password = server.getPassword(); if (secDispatcher != null) { try { password = secDispatcher.decrypt(password); } catch (SecDispatcherException ex) { throw new MojoExecutionException("Cannot decrypt password from settings", ex); } } final String email = getEmail(server); if (!isNullOrEmpty(username)) { registryAuthBuilder.username(username); } if (!isNullOrEmpty(email)) { registryAuthBuilder.email(email); } if (!isNullOrEmpty(password)) { registryAuthBuilder.password(password); } if (!isNullOrEmpty(registryUrl)) { registryAuthBuilder.serverAddress(registryUrl); } return registryAuthBuilder.build(); } else { // settings.xml has no entry for the configured serverId, warn the user getLog().warn("No entry found in settings.xml for serverId=" + serverId + ", cannot configure authentication for that registry"); } } return null; }
Example #9
Source File: SettingsDecrypterImpl.java From quarkus with Apache License 2.0 | 4 votes |
private String decrypt(String str) throws SecDispatcherException { return (str == null) ? null : securityDispatcher.decrypt(str); }
Example #10
Source File: SecDispatcherImpl.java From quarkus with Apache License 2.0 | 4 votes |
public String decrypt(String str) throws SecDispatcherException { if (!isEncryptedString(str)) return str; String bare = null; try { bare = _cipher.unDecorate(str); } catch (PlexusCipherException e1) { throw new SecDispatcherException(e1); } try { Map attr = stripAttributes(bare); String res = null; SettingsSecurity sec = getSec(); if (attr == null || attr.get("type") == null) { String master = getMaster(sec); res = _cipher.decrypt(bare, master); } else { String type = (String) attr.get(TYPE_ATTR); if (_decryptors == null) throw new SecDispatcherException( "plexus container did not supply any required dispatchers - cannot lookup " + type); Map conf = SecUtil.getConfig(sec, type); PasswordDecryptor dispatcher = (PasswordDecryptor) _decryptors.get(type); if (dispatcher == null) throw new SecDispatcherException("no dispatcher for hint " + type); String pass = strip(bare); return dispatcher.decrypt(pass, attr, conf); } return res; } catch (Exception e) { throw new SecDispatcherException(e); } }
Example #11
Source File: Utils.java From gate-core with GNU Lesser General Public License v3.0 | 4 votes |
public static DefaultRepositorySystemSession getRepositorySession(RepositorySystem repoSystem, WorkspaceReader workspace) { DefaultRepositorySystemSession repoSystemSession = MavenRepositorySystemUtils.newSession(); String repoLocation = System.getProperty("user.home") + File.separator + ".m2" + File.separator + "repository/"; ChainedProxySelector proxySelector = new ChainedProxySelector(); try { Settings effectiveSettings = loadMavenSettings(); if(effectiveSettings.getLocalRepository() != null) { repoLocation = effectiveSettings.getLocalRepository(); } List<Mirror> mirrors = effectiveSettings.getMirrors(); if(!mirrors.isEmpty()) { DefaultMirrorSelector mirrorSelector = new DefaultMirrorSelector(); for (Mirror mirror : mirrors) mirrorSelector.add( String.valueOf(mirror.getId()), mirror.getUrl(), mirror.getLayout(), false, mirror.getMirrorOf(), mirror.getMirrorOfLayouts()); repoSystemSession.setMirrorSelector(mirrorSelector); } List<Server> servers = effectiveSettings.getServers(); if(!servers.isEmpty()) { DefaultAuthenticationSelector selector = new DefaultAuthenticationSelector(); for (Server server : servers) { AuthenticationBuilder auth = new AuthenticationBuilder(); auth.addUsername(server.getUsername()).addPassword(PASSWORD_DECRYPTER.decrypt(server.getPassword())); auth.addPrivateKey(server.getPrivateKey(), PASSWORD_DECRYPTER.decrypt(server.getPassphrase())); selector.add(server.getId(), auth.build()); } repoSystemSession.setAuthenticationSelector(new ConservativeAuthenticationSelector(selector)); } // extract any proxies configured in the settings - we need to pass these // on so that any repositories declared in a dependency POM file can be // accessed through the proxy too. List<org.apache.maven.settings.Proxy> proxies = effectiveSettings.getProxies().stream().filter((p) -> p.isActive()) .collect(Collectors.toList()); if(!proxies.isEmpty()) { DefaultProxySelector defaultSelector = new DefaultProxySelector(); for (org.apache.maven.settings.Proxy proxy : proxies) { defaultSelector.add( new Proxy(proxy.getProtocol(), proxy.getHost(), proxy.getPort(), new AuthenticationBuilder().addUsername(proxy.getUsername()) .addPassword(PASSWORD_DECRYPTER.decrypt(proxy.getPassword())).build()), proxy.getNonProxyHosts()); } proxySelector.addSelector(defaultSelector); } // pass through the "offline" setting repoSystemSession.setOffline(effectiveSettings.isOffline()); } catch(SettingsBuildingException | SecDispatcherException | RuntimeException e) { log.warn( "Unable to load Maven settings, using default repository location, and no mirrors, proxy or authentication settings.", e); } LocalRepository localRepo = new LocalRepository(repoLocation); log.debug("Using local repository at: " + repoLocation); repoSystemSession.setLocalRepositoryManager(repoSystem .newLocalRepositoryManager(repoSystemSession, localRepo)); //repoSystemSession.setWorkspaceReader(new SimpleMavenCache(new File("repo"))); if (workspace != null) repoSystemSession.setWorkspaceReader(workspace); // try JRE proxies after any configured in settings proxySelector.addSelector(new JreProxySelector()); // set proxy selector for any repositories discovered in dependency poms repoSystemSession.setProxySelector(proxySelector); return repoSystemSession; }
Example #12
Source File: SqlExecMojo.java From sql-maven-plugin with Apache License 2.0 | 4 votes |
/** * Load username password from settings if user has not set them in JVM properties * * @throws MojoExecutionException */ private void loadUserInfoFromSettings() throws MojoExecutionException { if ( this.settingsKey == null ) { this.settingsKey = getUrl(); } if ( ( getUsername() == null || getPassword() == null ) && ( settings != null ) ) { Server server = this.settings.getServer( this.settingsKey ); if ( server != null ) { if ( getUsername() == null ) { setUsername( server.getUsername() ); } if ( getPassword() == null && server.getPassword() != null ) { try { setPassword( securityDispatcher.decrypt( server.getPassword() ) ); } catch ( SecDispatcherException e ) { throw new MojoExecutionException( e.getMessage() ); } } } } if ( getUsername() == null ) { // allow empty username setUsername( "" ); } if ( getPassword() == null ) { // allow empty password setPassword( "" ); } }