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);
}
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);
}
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);
}
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));
}
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);
}
Aggregations