Skip to content

Commit

Permalink
Fixed a bug on the authorization of the users. (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
KFilippopolitis authored Mar 5, 2024
1 parent 783bfe1 commit 59ca41f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


@Configuration
@EnableJpaRepositories("hbp.mip.repositories")
@EnableJpaRepositories(basePackages = {"hbp.mip.experiment", "hbp.mip.user"})
public class PersistenceConfiguration {

@Primary
Expand All @@ -33,7 +33,8 @@ public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
emfb.setDataSource(portalDataSource());
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
emfb.setJpaVendorAdapter(vendorAdapter);
emfb.setPackagesToScan("hbp.mip.models.DAOs");
emfb.setPackagesToScan("hbp.mip.experiment", "hbp.mip.user");

return emfb;
}

Expand Down
12 changes: 7 additions & 5 deletions src/main/java/hbp/mip/configurations/SecurityConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
import org.springframework.security.web.csrf.XorCsrfTokenRequestAttributeHandler;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

@Configuration
Expand Down Expand Up @@ -115,11 +112,16 @@ SecurityFilterChain clientSecurityFilterChain(HttpSecurity http, ClientRegistrat
@RequiredArgsConstructor
static class GrantedAuthoritiesMapperImpl implements GrantedAuthoritiesMapper {
private static Collection<GrantedAuthority> extractAuthorities(Map<String, Object> claims) {
return ((Collection<String>) claims.get("authorities")).stream()
Collection<String> authorities = (Collection<String>) claims.get("authorities");
if (authorities == null) {
return Collections.emptyList(); // or throw a more informative exception if appropriate
}
return authorities.stream()
.map(SimpleGrantedAuthority::new)
.collect(Collectors.toList());
}


@Override
public Collection<? extends GrantedAuthority> mapAuthorities(Collection<? extends GrantedAuthority> authorities) {
Set<GrantedAuthority> mappedAuthorities = new HashSet<>();
Expand Down

0 comments on commit 59ca41f

Please sign in to comment.