Skip to content

Commit

Permalink
Updated authorization strategy: authentication mandatory, authorizati…
Browse files Browse the repository at this point in the history
…on optional
  • Loading branch information
georgweiss committed Nov 13, 2023
1 parent ebc41df commit 6b594b1
Show file tree
Hide file tree
Showing 16 changed files with 237 additions and 212 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public String getDisplayName() {
public AppInstance create() {
List<ServiceAuthenticationProvider> authenticationProviders =
ServiceLoader.load(ServiceAuthenticationProvider.class).stream().map(Provider::get)
.filter(ServiceAuthenticationProvider::isActive).collect(Collectors.toList());
.collect(Collectors.toList());
try {
SecureStore secureStore = new SecureStore();
new CredentialsManagementStage(authenticationProviders, secureStore).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ public class Preferences {
@Preference
public static String default_snapshot_name_date_format;

@Preference
public static boolean authentication_enabled;

static
{
AnnotatedPreferences.initialize(Preferences.class, "/save_and_restore_preferences.properties");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,4 @@ public AuthenticationScope getAuthenticationScope(){
return AuthenticationScope.SAVE_AND_RESTORE;
}

@Override
public boolean isActive(){
return Preferences.authentication_enabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,3 @@ httpClient.readTimeout=1000

# Connect timeout in (ms) used by the Jersey client
httpClient.connectTimeout=1000

# Authentication/authorization enabled/disabled
authentication_enabled=false
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,4 @@ public interface ServiceAuthenticationProvider {
*/
AuthenticationScope getAuthenticationScope();

/**
* Indicates if a provider is active. Inactive providers suggest authentication is disabled or should
* not be accessible in the credentials management UI.
* @return <code>true</code> if the authentication provider is active, otherwise <code>false</code>.
*/
default boolean isActive(){
return true;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
@Conditional(AuthEnabledCondition.class)
@SuppressWarnings("unused")
public class WebSecurityConfig extends AnonymousWebSecurityConfig {
public class WebSecurityConfig {

/**
* Authentication implementation.
Expand Down Expand Up @@ -69,6 +68,74 @@ public class WebSecurityConfig extends AnonymousWebSecurityConfig {
@Value("${ldap.user.search.filter:invalid}")
String ldap_user_search_filter;

@Value("${role.user:sar-user}")
public String roleUser;

@Value("${role.admin:sar-admin}")
public String roleAdmin;

@Value("${demo.user:user}")
public String demoUser;

@Value("${demo.user.password:userPass}")
public String demoUserPassword;

@Value("${demo.admin:admin}")
public String demoAdmin;

@Value("${demo.admin.password:adminPass}")
public String demoAdminPassword;

@Value("${demo.readOnly:johndoe}")
public String demoReadOnly;

@Value("${demo.readOnly.password:1234}")
public String demoReadOnlyPassword;

@Bean
public String roleUser() {
return roleUser.toUpperCase();
}

@Bean
public String roleAdmin() {
return roleAdmin.toUpperCase();
}

@Bean
public String demoUser(){
return demoUser;
}

@Bean
public String demoUserPassword(){
return demoUserPassword;
}

@Bean
public String demoAdmin(){
return demoAdmin;
}

@Bean
public String demoAdminPassword(){
return demoAdminPassword;
}

@Bean
public String demoReadOnly(){
return demoReadOnly;
}

@Bean
public String demoReadOnlyPassword(){
return demoReadOnlyPassword;
}

@Bean
public String authenticationImplementation(){
return authenitcationImplementation;
}
@Bean
public WebSecurityCustomizer ignoringCustomizer() {
return web -> {
Expand All @@ -81,7 +148,12 @@ public WebSecurityCustomizer ignoringCustomizer() {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.csrf().disable();
http.authorizeRequests().anyRequest().authenticated();
if("none".equalsIgnoreCase(authenitcationImplementation.trim())){
http.authorizeRequests().antMatchers("/**").permitAll();
}
else{
http.authorizeRequests().anyRequest().authenticated();
}
http.httpBasic();

return http.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

@SuppressWarnings("unused")
@RestController
@Conditional(AuthEnabledCondition.class)
public class AuthenticationController extends BaseController {

@Autowired
Expand Down
Loading

0 comments on commit 6b594b1

Please sign in to comment.