Skip to content

Commit

Permalink
Applied automatic code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
craigdbarber committed Apr 15, 2019
1 parent 464a7fe commit d6239b1
Show file tree
Hide file tree
Showing 49 changed files with 1,051 additions and 1,591 deletions.
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@
<scope>test</scope>
<optional>true</optional>
</dependency>

<!-- OAuth Credentials dependency -->
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,21 @@
*/
package com.google.jenkins.plugins.credentials.oauth;

import org.kohsuke.stapler.QueryParameter;

import static com.google.common.base.Preconditions.checkNotNull;

import com.cloudbees.plugins.credentials.CredentialsDescriptor;
import com.google.common.base.Strings;

import hudson.util.FormValidation;
import org.kohsuke.stapler.QueryParameter;

/**
* The descriptor for Google robot account credential extensions.
*
* @author Matt Moore
*/
public abstract class AbstractGoogleRobotCredentialsDescriptor
extends CredentialsDescriptor {
public abstract class AbstractGoogleRobotCredentialsDescriptor extends CredentialsDescriptor {
protected AbstractGoogleRobotCredentialsDescriptor(
Class<? extends GoogleRobotCredentials> clazz,
GoogleRobotCredentialsModule module) {
Class<? extends GoogleRobotCredentials> clazz, GoogleRobotCredentialsModule module) {
super(clazz);
this.module = checkNotNull(module);
}
Expand All @@ -43,28 +39,22 @@ protected AbstractGoogleRobotCredentialsDescriptor(
this(clazz, new GoogleRobotCredentialsModule());
}

/**
* The module to use for instantiating depended upon resources
*/
/** The module to use for instantiating depended upon resources */
public GoogleRobotCredentialsModule getModule() {
return module;
}

private final GoogleRobotCredentialsModule module;

/**
* Validate project-id entries
*/
/** Validate project-id entries */
public FormValidation doCheckProjectId(@QueryParameter String projectId) {
if (!Strings.isNullOrEmpty(projectId)) {
return FormValidation.ok();
} else {
return FormValidation.error(
Messages.GoogleRobotMetadataCredentials_ProjectIDError());
return FormValidation.error(Messages.GoogleRobotMetadataCredentials_ProjectIDError());
}
}

/**
* For {@link Serializable}
*/
/** For {@link Serializable} */
private static final long serialVersionUID = 1L;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
*/
package com.google.jenkins.plugins.credentials.oauth;

import java.security.GeneralSecurityException;

import com.google.api.client.auth.oauth2.Credential;
import java.security.GeneralSecurityException;

/**
* Google-specific username / access token combination.
*
* <p>Implementations surface an API for obtaining the Google-standard
* {@link Credential} object for interacting with OAuth2 APIs.
* <p>Implementations surface an API for obtaining the Google-standard {@link Credential} object for
* interacting with OAuth2 APIs.
*/
public interface GoogleOAuth2Credentials
extends StandardUsernameOAuth2Credentials<GoogleOAuth2ScopeRequirement> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,5 @@
*/
package com.google.jenkins.plugins.credentials.oauth;

/**
* Used to type filter Google-specific {@link OAuth2ScopeRequirement}s.
*/
public abstract class GoogleOAuth2ScopeRequirement
extends OAuth2ScopeRequirement {
}
/** Used to type filter Google-specific {@link OAuth2ScopeRequirement}s. */
public abstract class GoogleOAuth2ScopeRequirement extends OAuth2ScopeRequirement {}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
*/
package com.google.jenkins.plugins.credentials.oauth;

import hudson.Extension;
import java.util.Collection;

import org.kohsuke.stapler.DataBoundConstructor;

import hudson.Extension;

/**
* A Google-specific implementation of the {@link OAuth2ScopeSpecification}
* that limits its application to Google-specific {@link OAuth2ScopeRequirement}
* A Google-specific implementation of the {@link OAuth2ScopeSpecification} that limits its
* application to Google-specific {@link OAuth2ScopeRequirement}
*/
public class GoogleOAuth2ScopeSpecification
extends OAuth2ScopeSpecification<GoogleOAuth2ScopeRequirement> {
Expand All @@ -33,22 +31,19 @@ public GoogleOAuth2ScopeSpecification(Collection<String> specifiedScopes) {
}

/**
* Denoted this class is a {@code DomainSpecification} plugin, in particular
* for {@link OAuth2ScopeSpecification}
* Denoted this class is a {@code DomainSpecification} plugin, in particular for {@link
* OAuth2ScopeSpecification}
*/
@Extension
public static class DescriptorImpl
extends OAuth2ScopeSpecification.Descriptor {
public static class DescriptorImpl extends OAuth2ScopeSpecification.Descriptor {
public DescriptorImpl() {
super(GoogleOAuth2ScopeRequirement.class);
}

/**
* {@inheritDoc}
*/
/** {@inheritDoc} */
@Override
public String getDisplayName() {
return Messages.GoogleOAuth2ScopeSpecification_DisplayName();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
*/
package com.google.jenkins.plugins.credentials.oauth;

import java.io.IOException;
import java.security.GeneralSecurityException;

import static com.google.common.base.Preconditions.checkNotNull;

import com.cloudbees.plugins.credentials.CredentialsNameProvider;
Expand All @@ -26,30 +23,27 @@
import com.google.api.client.auth.oauth2.Credential;
import com.google.common.collect.ImmutableList;
import com.google.jenkins.plugins.credentials.domains.DomainRequirementProvider;

import hudson.security.ACL;
import hudson.util.ListBoxModel;
import hudson.util.Secret;
import java.io.IOException;
import java.security.GeneralSecurityException;
import jenkins.model.Jenkins;

/**
* The base implementation of service account (aka robot) credentials using
* OAuth2. These robot credentials can be used to access Google APIs as the
* robot user.
* The base implementation of service account (aka robot) credentials using OAuth2. These robot
* credentials can be used to access Google APIs as the robot user.
*
* @author Matt Moore
*/
public abstract class GoogleRobotCredentials
implements GoogleOAuth2Credentials {
public abstract class GoogleRobotCredentials implements GoogleOAuth2Credentials {
/**
* Base constructor for populating the name and id for Google credentials.
*
* @param projectId The project id with which this credential is associated.
* @param module The module to use for instantiating the dependencies of
* credentials.
* @param module The module to use for instantiating the dependencies of credentials.
*/
protected GoogleRobotCredentials(String projectId,
GoogleRobotCredentialsModule module) {
protected GoogleRobotCredentials(String projectId, GoogleRobotCredentialsModule module) {
this.projectId = checkNotNull(projectId);

if (module != null) {
Expand All @@ -59,50 +53,39 @@ protected GoogleRobotCredentials(String projectId,
}
}

/**
* Fetch the module used for instantiating the dependencies
* of credentials
*/
/** Fetch the module used for instantiating the dependencies of credentials */
public GoogleRobotCredentialsModule getModule() {
return module;
}

private final GoogleRobotCredentialsModule module;

/**
* Retrieve a unique identifier that should be used to link to this object.
*/
/** Retrieve a unique identifier that should be used to link to this object. */
public String getId() {
return getProjectId();
}

/**
* {@inheritDoc}
*/
/** {@inheritDoc} */
@Override
public String getDescription() {
return Messages.GoogleRobotCredentials_Description();
}

/**
* {@inheritDoc}
*/
/** {@inheritDoc} */
@Override
public AbstractGoogleRobotCredentialsDescriptor getDescriptor() {
return (AbstractGoogleRobotCredentialsDescriptor) Jenkins.getInstance()
.getDescriptorOrDie(getClass());
return (AbstractGoogleRobotCredentialsDescriptor)
Jenkins.getInstance().getDescriptorOrDie(getClass());
}

/**
* {@inheritDoc}
*/
/** {@inheritDoc} */
@Override
public Secret getAccessToken(GoogleOAuth2ScopeRequirement requirement) {
try {
Credential credential = getGoogleCredential(requirement);

Long rawExpiration = credential.getExpiresInSeconds();
if ((rawExpiration == null)
|| (rawExpiration < MINIMUM_DURATION_SECONDS)) {
if ((rawExpiration == null) || (rawExpiration < MINIMUM_DURATION_SECONDS)) {
// Access token expired or is near expiration.
if (!credential.refreshToken()) {
return null;
Expand All @@ -117,43 +100,35 @@ public Secret getAccessToken(GoogleOAuth2ScopeRequirement requirement) {
}
}

/**
* The minimum duration to allow for an access token before attempting to
* refresh it.
*/
private static final Long MINIMUM_DURATION_SECONDS =
new Long(3 * 60 /* 3 minutes*/);
/** The minimum duration to allow for an access token before attempting to refresh it. */
private static final Long MINIMUM_DURATION_SECONDS = new Long(3 * 60 /* 3 minutes*/);

/**
* A trivial tuple for wrapping the list box of matched credentials with the
* requirements that were used to filter them.
* A trivial tuple for wrapping the list box of matched credentials with the requirements that
* were used to filter them.
*/
public static class CredentialsListBoxModel extends ListBoxModel {
public CredentialsListBoxModel(GoogleOAuth2ScopeRequirement requirement) {
this.requirement = requirement;
}

/**
* Retrieve the set of scopes for our requirement.
*/
/** Retrieve the set of scopes for our requirement. */
public Iterable<String> getScopes() {
return requirement.getScopes();
}

private final GoogleOAuth2ScopeRequirement requirement;
}

/**
* Helper utility for populating a jelly list box with matching
* {@link GoogleRobotCredentials} to avoid listing credentials that avoids
* surfacing those with insufficient permissions.
* Helper utility for populating a jelly list box with matching {@link GoogleRobotCredentials} to
* avoid listing credentials that avoids surfacing those with insufficient permissions.
*
* Modeled after:
* http://developer-blog.cloudbees.com/2012/10/using-ssh-from-jenkins.html
* <p>Modeled after: http://developer-blog.cloudbees.com/2012/10/using-ssh-from-jenkins.html
*
* @param clazz The class annotated with @RequiresDomain indicating its scope
* requirements.
* @return a list box populated solely with credentials compatible for the
* extension being configured.
* @param clazz The class annotated with @RequiresDomain indicating its scope requirements.
* @return a list box populated solely with credentials compatible for the extension being
* configured.
*/
public static CredentialsListBoxModel getCredentialsListBox(Class<?> clazz) {
GoogleOAuth2ScopeRequirement requirement =
Expand All @@ -167,7 +142,9 @@ public static CredentialsListBoxModel getCredentialsListBox(Class<?> clazz) {
CredentialsListBoxModel listBox = new CredentialsListBoxModel(requirement);
Iterable<GoogleRobotCredentials> allGoogleCredentials =
CredentialsProvider.lookupCredentials(
GoogleRobotCredentials.class, Jenkins.getInstance(), ACL.SYSTEM,
GoogleRobotCredentials.class,
Jenkins.getInstance(),
ACL.SYSTEM,
ImmutableList.<DomainRequirement>of(requirement));

for (GoogleRobotCredentials credentials : allGoogleCredentials) {
Expand All @@ -177,9 +154,7 @@ public static CredentialsListBoxModel getCredentialsListBox(Class<?> clazz) {
return listBox;
}

/**
* Retrieves the {@link GoogleRobotCredentials} identified by {@code id}.
*/
/** Retrieves the {@link GoogleRobotCredentials} identified by {@code id}. */
public static GoogleRobotCredentials getById(String id) {
Iterable<GoogleRobotCredentials> allGoogleCredentials =
CredentialsProvider.lookupCredentials(
Expand All @@ -193,11 +168,8 @@ public static GoogleRobotCredentials getById(String id) {
return null;
}

/**
* Retrieve a version of the credential that can be used on a remote machine.
*/
public GoogleRobotCredentials forRemote(
GoogleOAuth2ScopeRequirement requirement)
/** Retrieve a version of the credential that can be used on a remote machine. */
public GoogleRobotCredentials forRemote(GoogleOAuth2ScopeRequirement requirement)
throws GeneralSecurityException {
if (this instanceof RemotableGoogleCredentials) {
return this;
Expand All @@ -206,11 +178,10 @@ public GoogleRobotCredentials forRemote(
}
}

/**
* Retrieve the project id for this credential
*/
/** Retrieve the project id for this credential */
public String getProjectId() {
return projectId;
}

private final String projectId;
}

0 comments on commit d6239b1

Please sign in to comment.