org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher Java Examples

The following examples show how to use org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher. 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 vote down vote up
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: AbstractBaseConfluenceMojo.java    From maven-confluence-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #3
Source File: AbstractHelmMojo.java    From helm-maven-plugin with MIT License 4 votes vote down vote up
protected SecDispatcher getSecDispatcher() {
	if (securityDispatcher instanceof DefaultSecDispatcher) {
		((DefaultSecDispatcher) securityDispatcher).setConfigurationFile(getHelmSecurity());
	}
	return securityDispatcher;
}
 
Example #4
Source File: MojoExtension.java    From helm-maven-plugin with MIT License 4 votes vote down vote up
@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext context) throws ParameterResolutionException {
    try {

        // get descriptor

        Class<? extends AbstractHelmMojo> mojoType = (Class<AbstractHelmMojo>) parameterContext.getParameter().getType();
        MojoDescriptor descriptor = mojoDescriptors.get(mojoType);
        assertNotNull(descriptor, "Plugin descriptor for " + mojoType.getSimpleName() + " not found, run 'maven-plugin-plugin:descriptor'.");

        // create mojo with default values

        AbstractHelmMojo mojo = spy(mojoType);
        for (Parameter parameter : descriptor.getParameters()) {
            if (parameter.getDefaultValue() == null || !parameter.isEditable() || parameter.getType().equals("boolean")) {
                continue;
            }
            getField(mojoType, parameter.getName()).set(mojo, resolve(context, parameter.getDefaultValue()));
        }

        // read mojo values from annotations

        MojoProperty[] mojoProperties = ArrayUtils.addAll(
                context.getRequiredTestClass().getAnnotationsByType(MojoProperty.class),
                context.getRequiredTestMethod().getAnnotationsByType(MojoProperty.class));
        for (MojoProperty mojoProperty : mojoProperties) {
            getField(mojoType, mojoProperty.name()).set(mojo, resolve(context, mojoProperty.value()));
        }

        // settings

        getField(mojoType, "settings").set(mojo, new Settings());
        
        // plexus SecDispatcher

        SecDispatcher secDispatcher = spy(DefaultSecDispatcher.class);
        FieldSetter.setField(secDispatcher, DefaultSecDispatcher.class.getDeclaredField("_cipher"), new DefaultPlexusCipher());
        getField(mojoType, "securityDispatcher").set(mojo, secDispatcher);

        // validate that every parameter is set

        for (Parameter paramter : descriptor.getParameters()) {
            if (paramter.isRequired()) {
                assertNotNull(
                        getField(mojoType, paramter.getName()).get(mojo),
                        "Parameter '" + paramter.getName() + "' not set for mojo '" + mojoType.getSimpleName() + "'.");
            }
        }

        return mojo;
    } catch (ReflectiveOperationException | PlexusCipherException e) {
        throw new ParameterResolutionException("Failed to setup mockito.", e);
    }
}