Skip to content

Commit

Permalink
Merge pull request #18 from diging/develop
Browse files Browse the repository at this point in the history
[GECO-32] fix issue with duplicate adminUserDetailsService
  • Loading branch information
jdamerow authored Jan 20, 2017
2 parents 02d1d58 + eb6eb9b commit 7e45650
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 33 deletions.
1 change: 1 addition & 0 deletions giles-eco/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<db.user></db.user>
<db.password></db.password>
<giles.file.tmp.dir></giles.file.tmp.dir>
<digilib.url></digilib.url>
<jars.url>http://diging.asu.edu/jars</jars.url>
<jars.file.url>/resource/get/?uri={giles}/rest/files/{fileId}/content</jars.file.url>
<metadata.upload.add>/resource/create/giles/callback/</metadata.upload.add>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
Expand All @@ -23,6 +24,7 @@

import edu.asu.diging.gilesecosystem.util.properties.IPropertiesManager;
import edu.asu.diging.gilesecosystem.web.service.properties.Properties;
import edu.asu.diging.gilesecosystem.web.users.IAdminUserDetailsService;
import edu.asu.diging.gilesecosystem.web.users.LocalUserDetailsService;
import edu.asu.diging.gilesecosystem.web.users.SimpleSocialUserDetailsService;
import edu.asu.diging.gilesecosystem.web.users.impl.AdminUserDetailsService;
Expand All @@ -33,6 +35,10 @@ public class SecurityContext extends WebSecurityConfigurerAdapter {

@Autowired
private IPropertiesManager propertiesManager;

@Autowired
@Qualifier("adminDetailsService")
private IAdminUserDetailsService adminUserDetailsService;

@Override
public void configure(WebSecurity web) throws Exception {
Expand Down Expand Up @@ -112,7 +118,7 @@ public boolean matches(HttpServletRequest arg0) {
@Override
protected void configure(AuthenticationManagerBuilder auth)
throws Exception {
auth.userDetailsService(adminDetailsService()).passwordEncoder(
auth.userDetailsService(adminUserDetailsService).passwordEncoder(
passwordEncoder());
auth.userDetailsService(userDetailsService()).passwordEncoder(
passwordEncoder());
Expand All @@ -128,10 +134,10 @@ public SocialUserDetailsService socialUserDetailsService() {
return new SimpleSocialUserDetailsService(userDetailsService());
}

@Bean(name = "adminDetailsService")
public UserDetailsService adminDetailsService() {
return new AdminUserDetailsService();
}
// @Bean(name = "adminDetailsService")
// public UserDetailsService adminDetailsService() {
// return new AdminUserDetailsService();
// }

@Bean
public UserDetailsService userDetailsService() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import java.util.List;

import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

public interface IAdminUserDetailsService {
public interface IAdminUserDetailsService extends UserDetailsService {

public abstract UserDetails loadUserByUsername(String arg0)
throws UsernameNotFoundException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCrypt;
import org.springframework.stereotype.Service;
Expand All @@ -33,8 +32,8 @@
* @author jdamerow
*
*/
@Service("adminUserService")
public class AdminUserDetailsService implements UserDetailsService, IAdminUserDetailsService {
@Service("adminDetailsService")
public class AdminUserDetailsService implements IAdminUserDetailsService {

private final Logger logger = LoggerFactory.getLogger(getClass());

Expand Down Expand Up @@ -109,6 +108,7 @@ public boolean changePassword(String username, String password) {
logger.error("Could not store properties.", e);
return false;
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,52 @@
public class AdminUserManager implements IAdminUserManager {

@Autowired
@Qualifier("adminUserService")
@Qualifier("adminDetailsService")
private IAdminUserDetailsService adminDetailsService;

/* (non-Javadoc)
* @see edu.asu.diging.gilesecosystem.web.users.IAdminUserManager#getAdministrators()

/*
* (non-Javadoc)
*
* @see
* edu.asu.diging.gilesecosystem.web.users.IAdminUserManager#getAdministrators
* ()
*/
@Override
public List<UserDetails> getAdministrators() {
return adminDetailsService.getAllAdmins();
}

/* (non-Javadoc)
* @see edu.asu.diging.gilesecosystem.web.users.IAdminUserManager#isPasswordValid(java.lang.String, java.lang.String)

/*
* (non-Javadoc)
*
* @see
* edu.asu.diging.gilesecosystem.web.users.IAdminUserManager#isPasswordValid
* (java.lang.String, java.lang.String)
*/
@Override
public boolean isPasswordValid(String username, String password) {
return adminDetailsService.isPasswordValid(username, password);
}

/* (non-Javadoc)
* @see edu.asu.diging.gilesecosystem.web.users.IAdminUserManager#updatePassword(java.lang.String, java.lang.String)

/*
* (non-Javadoc)
*
* @see
* edu.asu.diging.gilesecosystem.web.users.IAdminUserManager#updatePassword
* (java.lang.String, java.lang.String)
*/
@Override
public boolean updatePassword(String username, String oldPassword, String newPassword) throws BadPasswordException, UnauthorizedException {
public boolean updatePassword(String username, String oldPassword, String newPassword)
throws BadPasswordException, UnauthorizedException {
boolean valid = isPasswordValid(username, oldPassword);
if (!valid) {
throw new UnauthorizedException("Provided password is not valid.");
}

if (newPassword == null || newPassword.trim().isEmpty()) {
throw new BadPasswordException("Password cannot be empty.");
}
return adminDetailsService.changePassword(username, newPassword);
}

}
11 changes: 0 additions & 11 deletions giles-eco/src/main/resources/config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ mitreid_client_id=${mitreid.clientId}
mitreid_secret=${mitreid.secret}
mitreid_server_url=${mitreid.server.url}

registered_apps_client_ids=${registered.apps.client.ids}
jwt_signing_secret=${jwt.signing.secret}
jwt_signing_secret_apps=${jwt.signing.secret.apps}

Expand All @@ -26,16 +25,6 @@ giles_file_content_suffix=/content
giles_files_tmp_dir=${giles.file.tmp.dir}

buildNumber=${buildNumber}
pdf_to_image_dpi=${pdf.conversion.dpi}
# possible image types:
# ARGB (Alpha, Red, Green, Blue)
# BINARY (Black or white)
# GRAY (Shades of gray)
# RGB (Red, Green, Blue)
pdf_to_image_type=${pdf.conversion.type}
pdf_to_image_format=${pdf.conversion.format}
#true or false
pdf_extract_text=true

jars_url=${jars.url}
jars_file_url=${jars.file.url}
Expand Down

0 comments on commit 7e45650

Please sign in to comment.