本文整理了Java中org.apache.maven.artifact.repository.Authentication
类的一些代码示例,展示了Authentication
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Authentication
类的具体详情如下:
包路径:org.apache.maven.artifact.repository.Authentication
类名称:Authentication
[英]Authentication
[中]认证
代码示例来源:origin: apache/maven
private static Authentication toAuthentication( org.apache.maven.artifact.repository.Authentication auth )
{
Authentication result = null;
if ( auth != null )
{
AuthenticationBuilder authBuilder = new AuthenticationBuilder();
authBuilder.addUsername( auth.getUsername() ).addPassword( auth.getPassword() );
authBuilder.addPrivateKey( auth.getPrivateKey(), auth.getPassphrase() );
result = authBuilder.build();
}
return result;
}
代码示例来源:origin: apache/maven
private Authentication getAuthentication( RepositorySystemSession session, ArtifactRepository repository )
{
if ( session != null )
{
AuthenticationSelector selector = session.getAuthenticationSelector();
if ( selector != null )
{
RemoteRepository repo = RepositoryUtils.toRepo( repository );
org.eclipse.aether.repository.Authentication auth = selector.getAuthentication( repo );
if ( auth != null )
{
repo = new RemoteRepository.Builder( repo ).setAuthentication( auth ).build();
AuthenticationContext authCtx = AuthenticationContext.forRepository( session, repo );
Authentication result =
new Authentication( authCtx.get( AuthenticationContext.USERNAME ),
authCtx.get( AuthenticationContext.PASSWORD ) );
result.setPrivateKey( authCtx.get( AuthenticationContext.PRIVATE_KEY_PATH ) );
result.setPassphrase( authCtx.get( AuthenticationContext.PRIVATE_KEY_PASSPHRASE ) );
authCtx.close();
return result;
}
}
}
return null;
}
代码示例来源:origin: apache/maven
String getRepositoryKey( ArtifactRepository repository )
{
StringBuilder buffer = new StringBuilder( 256 );
Proxy proxy = repository.getProxy();
if ( proxy != null )
{
if ( proxy.getUserName() != null )
{
int hash = ( proxy.getUserName() + proxy.getPassword() ).hashCode();
buffer.append( hash ).append( '@' );
}
buffer.append( proxy.getHost() ).append( ':' ).append( proxy.getPort() ).append( '>' );
}
// consider the username&password because a repo manager might block artifacts depending on authorization
Authentication auth = repository.getAuthentication();
if ( auth != null )
{
int hash = ( auth.getUsername() + auth.getPassword() ).hashCode();
buffer.append( hash ).append( '@' );
}
// consider the URL (instead of the id) as this most closely relates to the contents in the repo
buffer.append( repository.getUrl() );
return buffer.toString();
}
代码示例来源:origin: org.springframework.boot.experimental/spring-boot-thin-launcher
private org.apache.maven.repository.Proxy proxy(MavenSettings settings,
RepositorySystemSession session, RemoteRepository remote,
ProxySelector proxy) {
Proxy config = proxy.getProxy(remote);
if (config == null) {
return null;
}
org.apache.maven.repository.Proxy result = new org.apache.maven.repository.Proxy();
result.setHost(config.getHost());
if (config.getAuthentication() != null) {
org.apache.maven.artifact.repository.Authentication auth = authentication(
settings, session,
new RemoteRepository.Builder(remote)
.setAuthentication(config.getAuthentication()).build(),
config.getAuthentication());
result.setUserName(auth.getUsername());
result.setPassword(auth.getPassword() != null ? auth.getPassword()
: auth.getPassphrase());
}
result.setProtocol(config.getType());
result.setPort(config.getPort());
return result;
}
代码示例来源:origin: spring-projects/sts4
private String getLastUpdatedKey(ArtifactRepository repository, Artifact artifact) {
StringBuilder key = new StringBuilder();
// repository part
key.append(repository.getId());
if (repository.getAuthentication() != null) {
key.append('|').append(repository.getAuthentication().getUsername());
}
key.append('|').append(repository.getUrl());
// artifact part
key.append('|').append(artifact.getClassifier());
return key.toString();
}
代码示例来源:origin: org.kie.soup/kie-soup-maven-integration
private ArtifactRepository toArtifactRepository( RemoteRepository remoteRepository ) {
final String id = remoteRepository.getId();
final String url = remoteRepository.getUrl();
final ArtifactRepositoryLayout layout = new DefaultRepositoryLayout();
ArtifactRepositoryPolicy snapshots = new ArtifactRepositoryPolicy();
ArtifactRepositoryPolicy releases = new ArtifactRepositoryPolicy();
if ( remoteRepository.getPolicy( true ) != null ) {
snapshots = new ArtifactRepositoryPolicy( remoteRepository.getPolicy( true ).isEnabled(),
remoteRepository.getPolicy( true ).getUpdatePolicy(),
remoteRepository.getPolicy( true ).getChecksumPolicy() );
}
if ( remoteRepository.getPolicy( false ) != null ) {
releases = new ArtifactRepositoryPolicy( remoteRepository.getPolicy( false ).isEnabled(),
remoteRepository.getPolicy( false ).getUpdatePolicy(),
remoteRepository.getPolicy( false ).getChecksumPolicy() );
}
final ArtifactRepository artifactRepository = new MavenArtifactRepository( id,
url,
layout,
snapshots,
releases );
final Server server = settings.getServer( id );
if ( server != null ) {
artifactRepository.setAuthentication( new Authentication( server.getUsername(),
server.getPassword() ) );
}
return artifactRepository;
}
}
代码示例来源:origin: apache/maven
private AuthenticationInfo authenticationInfo( ArtifactRepository repository )
{
AuthenticationInfo ai = new AuthenticationInfo();
ai.setUserName( repository.getAuthentication().getUsername() );
ai.setPassword( repository.getAuthentication().getPassword() );
return ai;
}
代码示例来源:origin: spring-projects/sts4
private List<ArtifactRepository> removeDuplicateRepositories(ArrayList<ArtifactRepository> repositories) {
ArrayList<ArtifactRepository> result = new ArrayList<ArtifactRepository>();
HashSet<String> keys = new HashSet<String>();
for (ArtifactRepository repository : repositories) {
StringBuilder key = new StringBuilder();
if (repository.getId() != null) {
key.append(repository.getId());
}
key.append(':').append(repository.getUrl()).append(':');
if (repository.getAuthentication() != null && repository.getAuthentication().getUsername() != null) {
key.append(repository.getAuthentication().getUsername());
}
if (keys.add(key.toString())) {
result.add(repository);
}
}
return result;
}
代码示例来源:origin: org.uberfire/uberfire-maven-integration
private ArtifactRepository toArtifactRepository( RemoteRepository remoteRepository ) {
final String id = remoteRepository.getId();
final String url = remoteRepository.getUrl();
final ArtifactRepositoryLayout layout = new DefaultRepositoryLayout();
ArtifactRepositoryPolicy snapshots = new ArtifactRepositoryPolicy();
ArtifactRepositoryPolicy releases = new ArtifactRepositoryPolicy();
if ( remoteRepository.getPolicy( true ) != null ) {
snapshots = new ArtifactRepositoryPolicy( remoteRepository.getPolicy( true ).isEnabled(),
remoteRepository.getPolicy( true ).getUpdatePolicy(),
remoteRepository.getPolicy( true ).getChecksumPolicy() );
}
if ( remoteRepository.getPolicy( false ) != null ) {
releases = new ArtifactRepositoryPolicy( remoteRepository.getPolicy( false ).isEnabled(),
remoteRepository.getPolicy( false ).getUpdatePolicy(),
remoteRepository.getPolicy( false ).getChecksumPolicy() );
}
final ArtifactRepository artifactRepository = new MavenArtifactRepository( id,
url,
layout,
snapshots,
releases );
final Server server = settings.getServer( id );
if ( server != null ) {
artifactRepository.setAuthentication( new Authentication( server.getUsername(),
server.getPassword() ) );
}
return artifactRepository;
}
}
代码示例来源:origin: io.takari.maven.plugins/takari-lifecycle-plugin
private static Authentication toAuthentication(org.apache.maven.artifact.repository.Authentication auth) {
Authentication result = null;
if (auth != null) {
AuthenticationBuilder authBuilder = new AuthenticationBuilder();
authBuilder.addUsername(auth.getUsername()).addPassword(auth.getPassword());
authBuilder.addPrivateKey(auth.getPrivateKey(), auth.getPassphrase());
result = authBuilder.build();
}
return result;
}
代码示例来源:origin: apache/maven
private Authentication getAuthentication( RepositorySystemSession session, ArtifactRepository repository )
{
if ( session != null )
{
AuthenticationSelector selector = session.getAuthenticationSelector();
if ( selector != null )
{
RemoteRepository repo = RepositoryUtils.toRepo( repository );
org.eclipse.aether.repository.Authentication auth = selector.getAuthentication( repo );
if ( auth != null )
{
repo = new RemoteRepository.Builder( repo ).setAuthentication( auth ).build();
AuthenticationContext authCtx = AuthenticationContext.forRepository( session, repo );
Authentication result =
new Authentication( authCtx.get( AuthenticationContext.USERNAME ),
authCtx.get( AuthenticationContext.PASSWORD ) );
result.setPrivateKey( authCtx.get( AuthenticationContext.PRIVATE_KEY_PATH ) );
result.setPassphrase( authCtx.get( AuthenticationContext.PRIVATE_KEY_PASSPHRASE ) );
authCtx.close();
return result;
}
}
}
return null;
}
代码示例来源:origin: wildfly-swarm-archive/ARCHIVE-wildfly-swarm
public void remoteRepository(ArtifactRepository repo) {
RemoteRepository.Builder builder = new RemoteRepository.Builder(repo.getId(), "default", repo.getUrl());
final Authentication mavenAuth = repo.getAuthentication();
if (mavenAuth != null && mavenAuth.getUsername() != null && mavenAuth.getPassword() != null) {
builder.setAuthentication(new AuthenticationBuilder()
.addUsername(mavenAuth.getUsername())
.addPassword(mavenAuth.getPassword()).build());
}
this.remoteRepositories.add(builder.build());
}
代码示例来源:origin: takari/takari-lifecycle
private static Authentication toAuthentication(org.apache.maven.artifact.repository.Authentication auth) {
Authentication result = null;
if (auth != null) {
AuthenticationBuilder authBuilder = new AuthenticationBuilder();
authBuilder.addUsername(auth.getUsername()).addPassword(auth.getPassword());
authBuilder.addPrivateKey(auth.getPrivateKey(), auth.getPassphrase());
result = authBuilder.build();
}
return result;
}
代码示例来源:origin: apache/maven
Authentication authentication = new Authentication( server.getUsername(), server.getPassword() );
authentication.setPrivateKey( server.getPrivateKey() );
authentication.setPassphrase( server.getPassphrase() );
代码示例来源:origin: egineering-llc/gitflow-helper-maven-plugin
/**
* Builds a RemoteRepository for resolving artifacts.
*
* @param altRepository the repository identifier or alt-syntax specification
* @return the resolve remote repository
* @throws MojoExecutionException if the provided repository specification defines an invalid repository layout
* @throws MojoFailureException if the provided repository specification is invalid
*/
RemoteRepository getRepository(final String altRepository) throws MojoExecutionException, MojoFailureException {
if (getLog().isDebugEnabled()) {
getLog().debug("Creating remote Aether repository (to resolve remote artifacts) for: " + altRepository);
}
// Get an appropriate injected ArtifactRepository. (This resolves authentication in the 'normal' manner from Maven)
ArtifactRepository remoteArtifactRepo = getDeploymentRepository(altRepository);
if (getLog().isDebugEnabled()) {
getLog().debug("Resolved maven deployment repository. Transcribing to Aether Repository...");
}
RemoteRepository.Builder remoteRepoBuilder = new RemoteRepository.Builder(remoteArtifactRepo.getId(), remoteArtifactRepo.getLayout().getId(), remoteArtifactRepo.getUrl());
// Add authentication.
if (remoteArtifactRepo.getAuthentication() != null) {
if (getLog().isDebugEnabled()) {
getLog().debug("Maven deployment repsoitory has Authentication. Transcribing to Aether Authentication...");
}
remoteRepoBuilder.setAuthentication(new AuthenticationBuilder().addUsername(remoteArtifactRepo.getAuthentication().getUsername())
.addPassword(remoteArtifactRepo.getAuthentication().getPassword())
.addPrivateKey(remoteArtifactRepo.getAuthentication().getPrivateKey(), remoteArtifactRepo.getAuthentication().getPassphrase())
.build());
}
return remoteRepoBuilder.build();
}
代码示例来源:origin: shillner/unleash-maven-plugin
private Authentication createServerAuthentication(Server server) {
Authentication authentication = new Authentication(server.getUsername(), server.getPassword());
authentication.setPrivateKey(server.getPrivateKey());
authentication.setPassphrase(server.getPassphrase());
return authentication;
}
}
代码示例来源:origin: com.itemis.maven.plugins/unleash-maven-plugin
private Authentication createServerAuthentication(Server server) {
Authentication authentication = new Authentication(server.getUsername(), server.getPassword());
authentication.setPrivateKey(server.getPrivateKey());
authentication.setPassphrase(server.getPassphrase());
return authentication;
}
}
代码示例来源:origin: org.springframework.boot.experimental/spring-boot-thin-launcher
private org.apache.maven.artifact.repository.Authentication authentication(
MavenSettings settings, RepositorySystemSession session,
RemoteRepository remote, Authentication authentication) {
AuthenticationContext context = AuthenticationContext.forRepository(session,
remote);
if (context == null) {
return null;
}
authentication.fill(context, "username", Collections.<String, String>emptyMap());
authentication.fill(context, "password", Collections.<String, String>emptyMap());
authentication.fill(context, "passphrase",
Collections.<String, String>emptyMap());
authentication.fill(context, "privateKey",
Collections.<String, String>emptyMap());
org.apache.maven.artifact.repository.Authentication maven = new org.apache.maven.artifact.repository.Authentication(
context.get("username"), context.get("password"));
if (context.get("passphrase") != null) {
maven.setPassphrase(context.get("passphrase"));
}
if (context.get("privateKey") != null) {
maven.setPrivateKey(context.get("privateKey"));
}
return maven;
}
内容来源于网络,如有侵权,请联系作者删除!