Search in sources :

Example 6 with BaseConfig

use of org.nzbhydra.config.BaseConfig in project nzbhydra2 by theotherp.

the class HttpBasicAuthTest method shouldAllowChangingUserRolesAtRuntime.

@Test
public void shouldAllowChangingUserRolesAtRuntime() throws Exception {
    checkMainStatsAndConfig("u", "u", 200, 403, 403);
    baseConfig.getAuth().getUsers().get(0).setMaySeeStats(true);
    baseConfig.getAuth().getUsers().get(0).setMaySeeAdmin(true);
    userDetailsManager.handleConfigChangedEvent(new ConfigChangedEvent(this, new BaseConfig(), baseConfig));
    checkMainStatsAndConfig("u", "u", 200, 200, 200);
}
Also used : BaseConfig(org.nzbhydra.config.BaseConfig) ConfigChangedEvent(org.nzbhydra.config.ConfigChangedEvent) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with BaseConfig

use of org.nzbhydra.config.BaseConfig in project nzbhydra2 by theotherp.

the class Experiments method createSimpleYaml.

@Test
@Ignore
public void createSimpleYaml() throws IOException, InterruptedException {
    ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
    objectMapper.registerModule(new Jdk8Module());
    IndexerConfig indexerConfig = new IndexerConfig();
    indexerConfig.setCategoryMapping(new IndexerCategoryConfig());
    BaseConfig baseConfig = new BaseConfig();
    baseConfig.setIndexers(Arrays.asList(indexerConfig));
    String s = objectMapper.writeValueAsString(baseConfig);
    System.out.println(s);
    objectMapper.readValue(s, BaseConfig.class);
}
Also used : Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) IndexerConfig(org.nzbhydra.config.IndexerConfig) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) IndexerCategoryConfig(org.nzbhydra.config.IndexerCategoryConfig) BaseConfig(org.nzbhydra.config.BaseConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with BaseConfig

use of org.nzbhydra.config.BaseConfig in project nzbhydra2 by theotherp.

the class SecurityConfig method configure.

@Override
protected void configure(HttpSecurity http) throws Exception {
    BaseConfig baseConfig = configProvider.getBaseConfig();
    if (configProvider.getBaseConfig().getMain().isUseCsrf()) {
        http.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
    } else {
        http.csrf().disable();
    }
    http.headers().frameOptions().disable();
    if (baseConfig.getAuth().getAuthType() == AuthType.BASIC) {
        http = http.httpBasic().authenticationDetailsSource(new WebAuthenticationDetailsSource() {

            @Override
            public WebAuthenticationDetails buildDetails(HttpServletRequest context) {
                return new HydraWebAuthenticationDetails(context);
            }
        }).and().logout().logoutUrl("/logout").and();
    } else if (baseConfig.getAuth().getAuthType() == AuthType.FORM) {
        http = http.authorizeRequests().antMatchers("/internalapi/userinfos").permitAll().and().formLogin().loginPage("/login.html").loginProcessingUrl("/login").permitAll().authenticationDetailsSource(new WebAuthenticationDetailsSource() {

            @Override
            public WebAuthenticationDetails buildDetails(HttpServletRequest context) {
                return new HydraWebAuthenticationDetails(context);
            }
        }).and().logout().permitAll().logoutUrl("/logout").deleteCookies("rememberMe").and();
    }
    if (baseConfig.getAuth().isAuthConfigured()) {
        enableAnonymousAccessIfConfigured(http);
        if (baseConfig.getAuth().isRememberUsers()) {
            JdbcTokenRepositoryImpl tokenRepository = new JdbcTokenRepositoryImpl();
            tokenRepository.setDataSource(dataSource());
            http = http.rememberMe().alwaysRemember(true).tokenValiditySeconds(configProvider.getBaseConfig().getAuth().getRememberMeValidityDays() * SECONDS_PER_DAY).tokenRepository(tokenRepository).and();
        }
        http.logout().logoutUrl("/logout").logoutSuccessUrl("/").deleteCookies("rememberMe");
    }
    http.exceptionHandling().accessDeniedHandler(authAndAccessEventHandler);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebAuthenticationDetails(org.springframework.security.web.authentication.WebAuthenticationDetails) JdbcTokenRepositoryImpl(org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl) BaseConfig(org.nzbhydra.config.BaseConfig) WebAuthenticationDetailsSource(org.springframework.security.web.authentication.WebAuthenticationDetailsSource)

Example 9 with BaseConfig

use of org.nzbhydra.config.BaseConfig in project nzbhydra2 by theotherp.

the class HttpBasicAuthTest method setup.

@Before
public void setup() {
    mvc = MockMvcBuilders.webAppContextSetup(context).apply(SecurityMockMvcConfigurers.springSecurity()).build();
    baseConfig.getAuth().getUsers().get(0).setMaySeeStats(false);
    baseConfig.getAuth().getUsers().get(0).setMaySeeAdmin(false);
    userDetailsManager.handleConfigChangedEvent(new ConfigChangedEvent(this, new BaseConfig(), baseConfig));
}
Also used : BaseConfig(org.nzbhydra.config.BaseConfig) ConfigChangedEvent(org.nzbhydra.config.ConfigChangedEvent) Before(org.junit.Before)

Example 10 with BaseConfig

use of org.nzbhydra.config.BaseConfig in project nzbhydra2 by theotherp.

the class NzbsOrgTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    BaseConfig baseConfig = new BaseConfig();
    baseConfig.setSearching(new SearchingConfig());
    when(configProviderMock.getBaseConfig()).thenReturn(baseConfig);
}
Also used : SearchingConfig(org.nzbhydra.config.SearchingConfig) BaseConfig(org.nzbhydra.config.BaseConfig) Before(org.junit.Before)

Aggregations

BaseConfig (org.nzbhydra.config.BaseConfig)13 Before (org.junit.Before)7 Test (org.junit.Test)3 ConfigChangedEvent (org.nzbhydra.config.ConfigChangedEvent)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 SearchingConfig (org.nzbhydra.config.SearchingConfig)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)1 Jdk8Module (com.fasterxml.jackson.datatype.jdk8.Jdk8Module)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Ignore (org.junit.Ignore)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 CategoriesConfig (org.nzbhydra.config.CategoriesConfig)1 Category (org.nzbhydra.config.Category)1 IndexerCategoryConfig (org.nzbhydra.config.IndexerCategoryConfig)1 IndexerConfig (org.nzbhydra.config.IndexerConfig)1 UserAuthConfig (org.nzbhydra.config.UserAuthConfig)1 NewznabXmlRoot (org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot)1