Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OP-21860: Bugfix for platform service to cache UserGroups #463

Merged
merged 1 commit into from
Mar 11, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.List;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
Expand All @@ -37,6 +38,8 @@ public class BasicAuthProvider implements AuthenticationProvider {
private final PermissionService permissionService;
private final OesAuthorizationService oesAuthorizationService;

@Value("${services.platform.enabled:false}")
private boolean isPlatformEnabled;
private List<String> roles;
private String name;
private String password;
Expand Down Expand Up @@ -71,8 +74,11 @@ public Authentication authenticate(Authentication authentication) throws Authent
roles.stream().map(role -> new SimpleGrantedAuthority(role)).collect(Collectors.toList());
// Updating roles in fiat service
permissionService.loginWithRoles(name, roles);
log.info("Platform service enabled value :{}",isPlatformEnabled);
// Updating roles in platform service
if(isPlatformEnabled){
oesAuthorizationService.cacheUserGroups(roles, name);
}
}

return new UsernamePasswordAuthenticationToken(user, password, grantedAuthorities);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class DefaultProviderLookupService implements ProviderLookupService, AccountLook

private final AtomicReference<List<AccountDetails>> accountsCache = new AtomicReference<>([])

@Value('${gate.installation.mode}')
@Value('${gate.installation.mode:common}')
GateInstallationModes gateInstallationMode

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ import java.util.concurrent.TimeUnit
@ConfigurationProperties(prefix = "retrofit")
class RetrofitConfig {

Long connectTimeout
Long readTimeout
Long callTimeout
Long writeTimeout
Boolean retryOnConnectionFailure
Long connectTimeout = 60000
Long readTimeout = 60000
Long callTimeout = 60000
Long writeTimeout = 60000
Boolean retryOnConnectionFailure = true

@Bean
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.netflix.spinnaker.gate.services.UserInfoService
import com.netflix.spinnaker.gate.services.internal.OpsmxOesService
import com.netflix.spinnaker.security.AuthenticatedRequest
import com.netflix.spinnaker.security.User
import com.opsmx.spinnaker.gate.model.UserInfoDetailsModel
import groovy.util.logging.Slf4j
import io.swagger.annotations.ApiOperation
import org.springframework.beans.factory.annotation.Autowired
Expand Down Expand Up @@ -62,7 +63,7 @@ class AuthController {
@Autowired
UserInfoService userInfoService

@Autowired
@Autowired(required=false)
OpsmxOesService opsmxOesService

@Autowired
Expand Down Expand Up @@ -171,15 +172,19 @@ class AuthController {
@ApiOperation(value = "Get user Details with cloudAccounts")
@RequestMapping(value = "/userInfo", method = RequestMethod.GET)
Object userInfo(@ApiIgnore @SpinnakerUser User user) {
if (opsmxOesService != null) {
if (!user) {
throw new Exception("UnAuthorized User")
}
def fiatRoles = permissionService.getRoles(user.username)?.collect{ it.name }
def fiatRoles = permissionService.getRoles(user.username)?.collect { it.name }
if (fiatRoles) {
user.roles = fiatRoles
}
def response = opsmxOesService.getOesResponse5(
"accountsConfig", "v3", "spinnaker", "cloudProviderAccount", false, false)
return userInfoService.getAllInfoOfUser(user, response)
} else{
return new UserInfoDetailsModel();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ApplicationService {
@Autowired
ExecutorService executorService

@Value('${gate.installation.mode}')
@Value('${gate.installation.mode:common}')
GateInstallationModes gateInstallationMode


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

@Slf4j
@Configuration
@ConditionalOnExpression("${message-broker.enabled:true}")
@ConditionalOnExpression("${message-broker.enabled:false}")
public class CamelConfig {

@Autowired private UserActivityRouteBuilder userActivityRouteBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@Data
@Configuration
@ConfigurationProperties(prefix = "message-broker")
@ConditionalOnExpression("${message-broker.enabled:true}")
@ConditionalOnExpression("${message-broker.enabled:false}")
@EnableConfigurationProperties({
MessageBrokerProperties.class,
MessageBrokerProperties.Endpoint.class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnExpression("${message-broker.enabled:true}")
@ConditionalOnExpression("${message-broker.enabled:false}")
@ConditionalOnProperty(value = "message-broker.endpoint.name", havingValue = "rabbitmq")
public class RabbitMQConfig implements CamelRouteConfig {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnExpression("${message-broker.enabled:true}")
@ConditionalOnExpression("${message-broker.enabled:false}")
public class UserActivityRouteBuilder extends RouteBuilder {

private final String userActivity = "userActivity";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.stereotype.Component;


@ConditionalOnExpression("${services.auditservice.enabled:false}")
@Component
@EnableFeignClients(basePackageClasses = AuditService.class)
@ConditionalOnExpression("${services.auditservice.enabled:true}")
@Slf4j
public class AuditRestApiHandler implements AuditHandler {

@Autowired private AuditService auditService;
@Autowired(required = false) private AuditService auditService;
Gson gson = new Gson();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.camel.ProducerTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.security.AbstractAuthenticationAuditListener;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
Expand All @@ -37,10 +38,11 @@

@Slf4j
@Component
@ConditionalOnExpression("${services.auditservice.enabled:false}")
@EnableAsync
public class AuthenticationAuditListener extends AbstractAuthenticationAuditListener {

@Autowired private AuditHandler auditHandler;
@Autowired(required = false) private AuditHandler auditHandler;
@Autowired @Lazy private ProducerTemplate template;

Gson gson = new Gson();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.camel.ProducerTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Lazy;
Expand All @@ -37,6 +38,7 @@

@Slf4j
@Component
@ConditionalOnExpression("${services.auditservice.enabled:false}")
@EnableAsync
public class UserActivityAuditListener implements ApplicationListener {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.concurrent.TimeUnit;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.cache.CacheManager;
import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
Expand All @@ -28,6 +29,7 @@
import org.springframework.context.annotation.Primary;

@Configuration
@ConditionalOnExpression("${services.dashboard.enabled:false}")
public class OesCacheManager {

@Getter private CacheManager concurrentMapCacheManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Component;

@Slf4j
@ConditionalOnExpression("${services.dashboard.enabled:false}")
@Component
public class DatasourceCachingImpl implements DatasourceCaching {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
import com.opsmx.spinnaker.gate.model.DatasourceRequestModel;
import com.opsmx.spinnaker.gate.service.DatasourceCachingServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Slf4j
@ConditionalOnExpression("${services.dashboard.enabled:false}")
@RestController
@RequestMapping(value = "/datasource/cache")
public class DatasourceCachingController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import com.opsmx.spinnaker.gate.service.DashboardCachingService;
import com.opsmx.spinnaker.gate.service.DatasourceCachingServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Component;

@Component
@ConditionalOnExpression("${services.dashboard.enabled:false}")
public class DashboardCachingServiceBeanFactory {

@Autowired private DatasourceCachingServiceImpl datasourceCachingService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
import com.opsmx.spinnaker.gate.service.PlatformCachingService;
import com.opsmx.spinnaker.gate.util.CacheUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Component;

@Component
@ConditionalOnExpression("${services.platform.enabled:false}")
public class PlatformCachingServiceBeanFactory {

@Autowired private AdminAuthService adminAuthService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import com.opsmx.spinnaker.gate.cache.Constants;
import java.util.Map;

import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
import java.util.Set;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.cache.CacheManager;
import org.springframework.cache.caffeine.CaffeineCache;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@ConditionalOnExpression("${services.platform.enabled:false}")
public class AdminAuthService implements PlatformCachingService {

private Gson gson = new Gson();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.cache.CacheManager;
import org.springframework.cache.concurrent.ConcurrentMapCache;
import org.springframework.stereotype.Service;

@Slf4j
@ConditionalOnExpression("${services.dashboard.enabled:false}")
@Service
public class DatasourceCachingServiceImpl implements DashboardCachingService {

Expand All @@ -41,7 +43,7 @@ public class DatasourceCachingServiceImpl implements DashboardCachingService {

@Autowired private DatasourceCaching datasourceCaching;

@Autowired private DashboardClient dashboardClient;
@Autowired(required = false) private DashboardClient dashboardClient;

@Override
public void cacheResponse(Object response, String userName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package com.netflix.spinnaker.gate.services


import com.netflix.spinnaker.fiat.shared.FiatStatus

import com.netflix.spinnaker.gate.services.internal.ClouddriverService
import spock.lang.Specification
import spock.lang.Subject
import spock.lang.Unroll
Expand Down
Loading