Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ subprojects {
key = project.getProperties().get('bintrayKey')
publications = ['mavenJava']
publish = true
dryRun = true
pkg {
repo = 'maven'
name = 'mms-' + project.name
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.openmbee.sdvc.localuser.config;

import org.openmbee.sdvc.localuser.security.UserDetailsServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
public class AuthProviderConfig {

private static Logger logger = LoggerFactory.getLogger(LocalUserSecurityConfig.class);

private UserDetailsServiceImpl userDetailsService;
private PasswordEncoder passwordEncoder;

@Value("${sdvc.admin.username}")
private String adminUsername;
@Value("${sdvc.admin.password}")
private String adminPassword;

@Autowired
public void setUserDetailsService(UserDetailsServiceImpl userDetailsService) {
this.userDetailsService = userDetailsService;
}

@Autowired
public void setPasswordEncoder(PasswordEncoder passwordEncoder) {
this.passwordEncoder = passwordEncoder;
}

@Bean
public DaoAuthenticationProvider daoAuthenticationProvider() {
try {
userDetailsService.loadUserByUsername(adminUsername);
} catch (UsernameNotFoundException e) {
userDetailsService.register(adminUsername, adminPassword, true);
logger.info(String.format("Creating root user: %s with specified password.",
adminUsername));
}
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
authProvider.setUserDetailsService(userDetailsService);
authProvider.setPasswordEncoder(passwordEncoder);
return authProvider;
}
}
Original file line number Diff line number Diff line change
@@ -1,67 +1,22 @@
package org.openmbee.sdvc.localuser.config;
;
import org.openmbee.sdvc.localuser.security.UserDetailsServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class LocalUserSecurityConfig {

private static Logger logger = LoggerFactory.getLogger(LocalUserSecurityConfig.class);
@Autowired
public UserDetailsServiceImpl userDetailsService;
@Value("${sdvc.admin.username}")
private String adminUsername;
@Value("${sdvc.admin.password}")
private String adminPassword;

public LocalUserSecurityConfig() {
}

@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder(){
//Turn off warnings for null/empty passwords
@Override
public boolean matches(CharSequence rawPassword, String encodedPassword) {
if (encodedPassword == null || encodedPassword.length() == 0) {
return false;
}
return super.matches(rawPassword, encodedPassword);
}
};
}

@Autowired
public void configureDaoAuth(AuthenticationManagerBuilder auth) {
auth.authenticationProvider(authenticationProvider());
}

@Bean
public DaoAuthenticationProvider authenticationProvider() {
try {
userDetailsService.loadUserByUsername(adminUsername);
} catch (UsernameNotFoundException e) {
userDetailsService.register(adminUsername, adminPassword, true);
logger.info(String.format("Creating root user: %s with specified password.",
adminUsername));
}
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
authProvider.setUserDetailsService(userDetailsService);
authProvider.setPasswordEncoder(passwordEncoder());
return authProvider;
public void configureDaoAuth(AuthenticationManagerBuilder auth,
DaoAuthenticationProvider daoAuthenticationProvider) {
auth.authenticationProvider(daoAuthenticationProvider);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.openmbee.sdvc.localuser.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
public class PasswordEncoderConfig {

@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder(){
//Turn off warnings for null/empty passwords
@Override
public boolean matches(CharSequence rawPassword, String encodedPassword) {
if (encodedPassword == null || encodedPassword.length() == 0) {
return false;
}
return super.matches(rawPassword, encodedPassword);
}
};
}
}