Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class FossologyHandler implements FossologyService.Iface {

boolean reportStep = false;

@Autowired

public FossologyHandler(
FossologyRestConfig fossologyRestConfig,
FossologyRestClient fossologyRestClient, AttachmentConnector attachmentConnector) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@Controller
public class FossologyServlet extends SpringTServlet {

@Autowired

public FossologyServlet(FossologyHandler fossologyHandler) throws MalformedURLException {
// Create a service processor using the provided handler
super(new FossologyService.Processor<>(fossologyHandler), new TCompactProtocol.Factory());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class FossologyRestConfig {

private static final String BASEURL_VERSION_SUFFIX = "/api/v2";

@Autowired

public FossologyRestConfig(ConfigContainerRepository repository) throws SW360Exception {
this.repository = repository;
// eager loading (or initial insert)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public class FossologyRestClient {

private final String expectedVersionPrefix = "2.";

@Autowired

public FossologyRestClient(ObjectMapper objectMapper, FossologyRestConfig restConfig, RestTemplate restTemplate) {
this.objectMapper = objectMapper;
this.restConfig = restConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,22 @@ public class OAuthClientController {
*/
public static final String UNUSED_REDIRECT_URI = "https://localhost/unused-redirect";

@Autowired
private PasswordEncoder passwordEncoder;

private final PasswordEncoder passwordEncoder;

@Value("${security.oauth2.resource.id}")
private String resourceId;

@Autowired
private OAuthClientRepository repo;

@Autowired
private Sw360UserMirrorService userMirrorService;
private final OAuthClientRepository repo;

private final Sw360UserMirrorService userMirrorService;

OAuthClientController(PasswordEncoder passwordEncoder, OAuthClientRepository oAuthClientRepository, Sw360UserMirrorService sw360UserMirrorService) {
this.passwordEncoder = passwordEncoder;
this.repo = oAuthClientRepository;
this.userMirrorService = sw360UserMirrorService;
}

/**
* Normalize a caller-supplied {@code scope} set to the canonical
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ public class Sw360ClientDetailsService implements RegisteredClientRepository {
@Value("${security.refreshtoken.validity:360}")
private Integer defaultRefreshTokenValiditySeconds;

@Autowired
private OAuthClientRepository clientRepo;
private final OAuthClientRepository clientRepo;

Sw360ClientDetailsService(OAuthClientRepository oAuthClientRepository) {
this.clientRepo = oAuthClientRepository;
}

@Override
public RegisteredClient findByClientId(@Nonnull String clientId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
* for all READ-only users on <em>all</em> endpoints — not just admin endpoints.</p>
*/
@BasePathAwareController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@RestController
@SecurityRequirement(name = "tokenAuth")
@SecurityRequirement(name = "basic")
Expand All @@ -63,6 +62,11 @@ public class CacheAdminController implements RepresentationModelProcessor<Reposi
@NonNull
private final ApiResponseCacheManager cacheManager;

CacheAdminController(RestControllerHelper restControllerHelper, ApiResponseCacheManager apiResponseCacheManager) {
this.cacheManager = apiResponseCacheManager;
this.restControllerHelper = restControllerHelper;
}

@Override
public RepositoryLinksResource process(RepositoryLinksResource resource) {
resource.add(linkTo(CacheAdminController.class).slash("api" + CACHE_ADMIN_URL).withRel("cacheAdmin"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public class ChangeLogController implements RepresentationModelProcessor<Reposit
private static final Logger log = LogManager.getLogger(ChangeLogController.class);

public static final String CHANGE_LOG_URL = "/changelog";
@Autowired
private Sw360ChangeLogService sw360ChangeLogService;

private final Sw360ChangeLogService sw360ChangeLogService;

@NonNull
private final RestControllerHelper restControllerHelper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public class ClearingRequestController implements RepresentationModelProcessor<R

private static final Logger log = LogManager.getLogger(ClearingRequestController.class);

@Autowired
private Sw360ClearingRequestService sw360ClearingRequestService;

private final Sw360ClearingRequestService sw360ClearingRequestService;

@NonNull
private final RestControllerHelper restControllerHelper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public class ModerationRequestController implements RepresentationModelProcessor
private static final String REQUESTING_USER = "requestingUser";
public static final String MODERATION_REQUEST_URL = "/moderationrequest";

@Autowired
private Sw360ModerationRequestService sw360ModerationRequestService;

private final Sw360ModerationRequestService sw360ModerationRequestService;

@NonNull
private final RestControllerHelper restControllerHelper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public class SearchController implements RepresentationModelProcessor<Repository

public static final String SEARCH_URL = "/search";

@Autowired
private Sw360SearchService sw360SearchService;

private final Sw360SearchService sw360SearchService;

@NonNull
private final RestControllerHelper restControllerHelper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ public class Sw360JWTAccessTokenConverter extends AbstractSw360JwtAuthentication
@Value("${jwt.auth.converter.principle-attribute:email}")
private String principleAttribute;

@Autowired
private Sw360UserService userService;

public Sw360JWTAccessTokenConverter() {
private final Sw360UserService userService;

public Sw360JWTAccessTokenConverter(Sw360UserService sw360UserService) {
super(new JwtGrantedAuthoritiesConverter(),
Sw360GrantedAuthoritiesCalculator.CONFIG_WRITE_ACCESS_USERGROUP,
Sw360GrantedAuthoritiesCalculator.CONFIG_ADMIN_ACCESS_USERGROUP);

this.userService = sw360UserService;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class Sw360JWTAccessTokenConverterTest {

@BeforeEach
public void setUp() {
converter = new Sw360JWTAccessTokenConverter();
converter = new Sw360JWTAccessTokenConverter(userService);
ReflectionTestUtils.setField(converter, "userService", userService);
ReflectionTestUtils.setField(converter, "principleAttribute", "email");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ public class Sw360OidcUserInfoService {
public static final String USER_GROUP = "userGroup";
public static final String DEPARTMENT = "department";
public static final String PRIMARY_ROLES = "primaryRoles";
@Autowired
private Sw360UserDetailsProvider sw360UserDetailsProvider;

private final Sw360UserDetailsProvider sw360UserDetailsProvider;

Sw360OidcUserInfoService(Sw360UserDetailsProvider sw360UserDetailsProvider) {
this.sw360UserDetailsProvider = sw360UserDetailsProvider;
}

public OidcUserInfo loadUser(String username) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ public class Sw360UserDetailsService implements UserDetailsService {

private final Logger log = LogManager.getLogger(this.getClass());

@Autowired
private Sw360UserDetailsProvider userProvider;
private final Sw360UserDetailsProvider userProvider;

@Autowired
private Sw360GrantedAuthoritiesCalculator authoritiesCalculator;

private final Sw360GrantedAuthoritiesCalculator authoritiesCalculator;

Sw360UserDetailsService(Sw360UserDetailsProvider sw360UserDetailsProvider, Sw360GrantedAuthoritiesCalculator sw360GrantedAuthoritiesCalculator) {
this.userProvider = sw360UserDetailsProvider;
this.authoritiesCalculator = sw360GrantedAuthoritiesCalculator;
}

/**
* @param username the username identifying the user whose data is required.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ public class Sw360TokenCustomizerConfig {
public static final String SUB = "sub";
public static final String SCOPE = "scope";
public static final String SW360_REST_API = "sw360-REST-API";
@Autowired
private Sw360OidcUserInfoService sw360OidcUserInfoService;

private final Sw360OidcUserInfoService sw360OidcUserInfoService;

Sw360TokenCustomizerConfig(Sw360OidcUserInfoService sw360OidcUserInfoService) {
this.sw360OidcUserInfoService = sw360OidcUserInfoService;
}

@Bean
public OAuth2TokenCustomizer<JwtEncodingContext> tokenCustomizer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package org.eclipse.sw360.rest.common.security.authproviders;

import org.eclipse.sw360.rest.common.client.service.Sw360UserDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
Expand All @@ -23,11 +22,14 @@
@Service
public class Sw360UserAuthenticationProvider implements AuthenticationProvider {

@Autowired
private Sw360UserDetailsService userDetailsService;
private final Sw360UserDetailsService userDetailsService;

@Autowired
private PasswordEncoder passwordEncoder;
private final PasswordEncoder passwordEncoder;

public Sw360UserAuthenticationProvider(PasswordEncoder passwordEncoder, Sw360UserDetailsService sw360UserDetailsService) {
this.passwordEncoder = passwordEncoder;
this.userDetailsService = sw360UserDetailsService;
}

/**
* @param authentication the authentication request object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ public class Sw360UserAuthenticationProviderTest {

@Test
public void shouldAddPasswordFactorAuthority_onSuccessfulAuthentication() {
Sw360UserAuthenticationProvider provider = new Sw360UserAuthenticationProvider();

Sw360UserDetailsService userDetailsService = mock(Sw360UserDetailsService.class);
PasswordEncoder passwordEncoder = mock(PasswordEncoder.class);

Sw360UserAuthenticationProvider provider = new Sw360UserAuthenticationProvider(passwordEncoder, userDetailsService);

ReflectionTestUtils.setField(provider, "userDetailsService", userDetailsService);
ReflectionTestUtils.setField(provider, "passwordEncoder", passwordEncoder);

Expand Down