Skip to content

Commit

Permalink
Spring Security for profile not dev fix
Browse files Browse the repository at this point in the history
  • Loading branch information
siewrgrz committed Mar 17, 2020
1 parent 233064d commit 8de4fba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
36 changes: 18 additions & 18 deletions src/main/java/io/mixeway/fortifyscaapi/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig {

@Value("${allowed.users}")
private String commonNames;


@Profile("dev")
@Configuration
Expand All @@ -48,6 +47,9 @@ protected void configure(HttpSecurity http) throws Exception {
@Configuration
public static class ProdSecurityConfiguration extends WebSecurityConfigurerAdapter {

@Value("${allowed.users}")
private String commonNames;

@Override
protected void configure(HttpSecurity http) throws Exception {
System.out.println("Enabling production mode");
Expand All @@ -61,25 +63,23 @@ protected void configure(HttpSecurity http) throws Exception {
.subjectPrincipalRegex("CN=(.*?)(?:,|$)")
.userDetailsService(userDetailsService());
}
}


@Bean
public UserDetailsService userDetailsService() {
return new UserDetailsService() {
@Override
public UserDetails loadUserByUsername(String username) {
@Bean
public UserDetailsService userDetailsService() {
return username -> {
if (verifyCN(username)) {
return new User(username, "", AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
} else
throw new UsernameNotFoundException("User not found!");
}
};
}
private boolean verifyCN(String cn){
List<String> allowedCNs =
Stream.of(commonNames.split(","))
.collect(Collectors.toList());
return allowedCNs.contains(cn);
};
}
private boolean verifyCN(String cn){
List<String> allowedCNs =
Stream.of(commonNames.split(","))
.collect(Collectors.toList());
return allowedCNs.contains(cn);
}
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,11 @@ public void createScanProcess(CreateScanRequest createScanRequest, FortifyScan f
gitResponse = gitClient.pull(createScanRequest,project, path);
if (!gitResponse.getStatus())
throw new Exception("Some kind of error during pulling repo for " + project.getProjectName());
logger.info("Successfully fetched repo for {} commid id is {} branch {}",
project.getProjectName(),
gitResponse.getCommitId(),
project.getBranch() );

} else {
//git clone
gitResponse = gitClient.clone(createScanRequest,project, path);
if (!gitResponse.getStatus())
throw new Exception("Some kind of error during cloning repo for " + project.getProjectName());
logger.info("Successfully cloned repo for {} commit id is {}", project.getProjectName(),gitResponse.getCommitId());
}
fortifyScaClient.runTranslateForRequest(createScanRequest,project,fortifyScan);
}
Expand Down

0 comments on commit 8de4fba

Please sign in to comment.