/** * Copyright (C) 2013 Open WhisperSystems * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ package org.whispersystems.textsecuregcm.auth; import com.sun.jersey.api.model.Parameter; import com.sun.jersey.core.spi.component.ComponentContext; import com.sun.jersey.core.spi.component.ComponentScope; import com.sun.jersey.spi.inject.Injectable; import com.sun.jersey.spi.inject.InjectableProvider; import com.yammer.dropwizard.auth.Auth; import com.yammer.dropwizard.auth.Authenticator; import com.yammer.dropwizard.auth.basic.BasicAuthProvider; import com.yammer.dropwizard.auth.basic.BasicCredentials; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class MultiBasicAuthProvider implements InjectableProvider { private final Logger logger = LoggerFactory.getLogger(MultiBasicAuthProvider.class); private final BasicAuthProvider provider1; private final BasicAuthProvider provider2; private final Class clazz1; private final Class clazz2; public MultiBasicAuthProvider(Authenticator authenticator1, Class clazz1, Authenticator authenticator2, Class clazz2, String realm) { this.provider1 = new BasicAuthProvider(authenticator1, realm); this.provider2 = new BasicAuthProvider(authenticator2, realm); this.clazz1 = clazz1; this.clazz2 = clazz2; } @Override public ComponentScope getScope() { return ComponentScope.PerRequest; } @Override public Injectable getInjectable(ComponentContext componentContext, Auth auth, Parameter parameter) { if (parameter.getParameterClass().equals(clazz1)) { return this.provider1.getInjectable(componentContext, auth, parameter); } else { return this.provider2.getInjectable(componentContext, auth, parameter); } } }