org.ctoolkit.restapi.client.adapter.AuthRequestImpl Maven / Gradle / Ivy
/*
* Copyright (c) 2018 Comvai, s.r.o. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.ctoolkit.restapi.client.adapter;
import org.ctoolkit.restapi.client.AuthRequest;
import org.ctoolkit.restapi.client.Request;
import org.ctoolkit.restapi.client.RequestCredential;
import org.ctoolkit.restapi.client.provider.TokenProvider;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* The authentication request implementation, it wraps the original request instance
* and implements authentication related methods.
*
* @author Aurel Medvegy
*/
class AuthRequestImpl
implements AuthRequest
{
private final Request request;
private GoogleRequestHeaders filler;
AuthRequestImpl( Request request, GoogleRequestHeaders filler )
{
this.request = checkNotNull( request );
this.filler = checkNotNull( filler );
}
@Override
public Request bearer()
{
filler.setAuthScheme( AuthScheme.BEARER );
return this;
}
@Override
public Request oauth()
{
filler.setAuthScheme( AuthScheme.OAUTH );
return this;
}
@Override
public Request onBehalfOf( @Nonnull Object of )
{
filler.setOnBehalfOf( of );
return this;
}
@Override
public T finish()
{
return request.finish();
}
@Override
public T finish( @Nonnull RequestCredential credential )
{
return request.finish( credential );
}
@Override
public T finish( @Nullable Map parameters )
{
return request.finish( parameters );
}
@Override
public T finish( @Nullable Locale locale )
{
return request.finish( locale );
}
@Override
public T finish( @Nullable Map parameters, @Nullable Locale locale )
{
return request.finish( parameters, locale );
}
@Override
public Request configWith( @Nonnull Properties properties )
{
return request.configWith( properties );
}
@Override
public Request forLang( @Nonnull Locale locale )
{
return request.forLang( locale );
}
@Override
public Request add( @Nonnull String name, @Nonnull Object value )
{
return request.add( name, value );
}
@Override
public Request add( @Nonnull String name, @Nonnull String value )
{
return request.add( name, value );
}
@Override
public Request addHeader( @Nonnull String header, @Nonnull String value )
{
return request.addHeader( header, value );
}
@Override
public AuthRequest authBy( @Nonnull String token )
{
return request.authBy( token );
}
@Override
public AuthRequest authBy( @Nonnull TokenProvider