Search in sources :

Example 1 with AuthenticationChannelHandler

use of co.cask.cdap.common.http.AuthenticationChannelHandler in project cdap by caskdata.

the class AuthorizationHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    CConfiguration conf = CConfiguration.create();
    conf.setBoolean(Constants.Security.Authorization.ENABLED, true);
    conf.setBoolean(Constants.Security.ENABLED, true);
    properties.setProperty("superusers", admin.getName());
    final InMemoryAuthorizer auth = new InMemoryAuthorizer();
    auth.initialize(FACTORY.create(properties));
    service = new CommonNettyHttpServiceBuilder(conf, getClass().getSimpleName()).setHttpHandlers(new AuthorizationHandler(auth, new AuthorizerInstantiator(conf, FACTORY) {

        @Override
        public Authorizer get() {
            return auth;
        }
    }, conf, auth, new MasterAuthenticationContext(), entityExistenceVerifier)).setChannelPipelineModifier(new ChannelPipelineModifier() {

        @Override
        public void modify(ChannelPipeline pipeline) {
            pipeline.addBefore("dispatcher", "usernamesetter", new TestUserNameSetter());
            pipeline.addAfter("usernamesetter", "authenticator", new AuthenticationChannelHandler());
        }
    }).build();
    service.start();
    client = new AuthorizationClient(ClientConfig.builder().setConnectionConfig(ConnectionConfig.builder().setHostname(service.getBindAddress().getHostName()).setPort(service.getBindAddress().getPort()).setSSLEnabled(false).build()).build());
    System.setProperty(USERNAME_PROPERTY, admin.getName());
}
Also used : MasterAuthenticationContext(co.cask.cdap.security.auth.context.MasterAuthenticationContext) CommonNettyHttpServiceBuilder(co.cask.cdap.common.http.CommonNettyHttpServiceBuilder) AuthorizerInstantiator(co.cask.cdap.security.authorization.AuthorizerInstantiator) AuthenticationChannelHandler(co.cask.cdap.common.http.AuthenticationChannelHandler) CConfiguration(co.cask.cdap.common.conf.CConfiguration) ChannelPipeline(io.netty.channel.ChannelPipeline) InMemoryAuthorizer(co.cask.cdap.security.authorization.InMemoryAuthorizer) InMemoryAuthorizer(co.cask.cdap.security.authorization.InMemoryAuthorizer) Authorizer(co.cask.cdap.security.spi.authorization.Authorizer) AuthorizationClient(co.cask.cdap.client.AuthorizationClient) ChannelPipelineModifier(co.cask.http.ChannelPipelineModifier) Before(org.junit.Before)

Aggregations

AuthorizationClient (co.cask.cdap.client.AuthorizationClient)1 CConfiguration (co.cask.cdap.common.conf.CConfiguration)1 AuthenticationChannelHandler (co.cask.cdap.common.http.AuthenticationChannelHandler)1 CommonNettyHttpServiceBuilder (co.cask.cdap.common.http.CommonNettyHttpServiceBuilder)1 MasterAuthenticationContext (co.cask.cdap.security.auth.context.MasterAuthenticationContext)1 AuthorizerInstantiator (co.cask.cdap.security.authorization.AuthorizerInstantiator)1 InMemoryAuthorizer (co.cask.cdap.security.authorization.InMemoryAuthorizer)1 Authorizer (co.cask.cdap.security.spi.authorization.Authorizer)1 ChannelPipelineModifier (co.cask.http.ChannelPipelineModifier)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 Before (org.junit.Before)1