forked from spinnaker/gate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request spinnaker#88 from OpsMx/OP-10250
Op 10250
- Loading branch information
Showing
13 changed files
with
337 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
gate-web/src/main/java/com/opsmx/spinnaker/gate/cache/platform/AuthorizationCaching.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2021 OpsMx, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.opsmx.spinnaker.gate.cache.platform; | ||
|
||
import java.util.Map; | ||
import org.springframework.cache.annotation.CachePut; | ||
import org.springframework.cache.annotation.Cacheable; | ||
|
||
public interface AuthorizationCaching { | ||
|
||
@CachePut(value = "adminAuth", key = "#userName", cacheManager = "caffeineCacheManager") | ||
Map<String, Object> populateAdminAuthCache(String userName, Map<String, Object> response); | ||
|
||
@Cacheable(value = "adminAuth", key = "#userName", cacheManager = "caffeineCacheManager") | ||
Map<String, Object> getRecordFromAdminAuthCache(String userName); | ||
} |
38 changes: 38 additions & 0 deletions
38
gate-web/src/main/java/com/opsmx/spinnaker/gate/cache/platform/AuthorizationCachingImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2021 OpsMx, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.opsmx.spinnaker.gate.cache.platform; | ||
|
||
import java.util.Map; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Slf4j | ||
@Component | ||
public class AuthorizationCachingImpl implements AuthorizationCaching { | ||
|
||
@Override | ||
public Map<String, Object> populateAdminAuthCache(String userName, Map<String, Object> response) { | ||
log.debug("populating admin auth cache"); | ||
return response; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> getRecordFromAdminAuthCache(String userName) { | ||
log.debug("getting record from admin auth cache"); | ||
return null; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...ain/java/com/opsmx/spinnaker/gate/factory/platform/PlatformCachingServiceBeanFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2021 OpsMx, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.opsmx.spinnaker.gate.factory.platform; | ||
|
||
import com.opsmx.spinnaker.gate.cache.Constants; | ||
import com.opsmx.spinnaker.gate.service.AdminAuthService; | ||
import com.opsmx.spinnaker.gate.service.PlatformCachingService; | ||
import com.opsmx.spinnaker.gate.util.CacheUtil; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class PlatformCachingServiceBeanFactory { | ||
|
||
@Autowired private AdminAuthService adminAuthService; | ||
|
||
public PlatformCachingService getBean(String path) { | ||
|
||
PlatformCachingService platformCachingService = null; | ||
path = CacheUtil.formatPath(path); | ||
switch (path) { | ||
case Constants.CHECK_IS_ADMIN_ENDPOINT: | ||
platformCachingService = adminAuthService; | ||
break; | ||
} | ||
return platformCachingService; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
gate-web/src/main/java/com/opsmx/spinnaker/gate/service/AdminAuthService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2021 OpsMx, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.opsmx.spinnaker.gate.service; | ||
|
||
import com.google.gson.Gson; | ||
import com.opsmx.spinnaker.gate.cache.OesCacheManager; | ||
import com.opsmx.spinnaker.gate.cache.platform.AuthorizationCaching; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.cache.CacheManager; | ||
import org.springframework.cache.caffeine.CaffeineCache; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Slf4j | ||
@Service | ||
public class AdminAuthService implements PlatformCachingService { | ||
|
||
private Gson gson = new Gson(); | ||
|
||
@Autowired private OesCacheManager oesCacheManager; | ||
|
||
@Autowired private AuthorizationCaching authorizationCaching; | ||
|
||
@Override | ||
public void cacheResponse(Object response, String userName) { | ||
|
||
String responseBody = gson.toJson(response); | ||
Map<String, Object> adminAuthResponse = gson.fromJson(responseBody, Map.class); | ||
authorizationCaching.populateAdminAuthCache(userName, adminAuthResponse); | ||
} | ||
|
||
@Override | ||
public boolean isCacheNotEmpty(String userName) { | ||
|
||
CacheManager cacheManager = oesCacheManager.getCaffeineCacheManager(); | ||
CaffeineCache caffeineCache = (CaffeineCache) cacheManager.getCache("adminAuth"); | ||
Set<Object> keySet = caffeineCache.getNativeCache().asMap().keySet(); | ||
return keySet.stream() | ||
.filter(key -> ((String) key).trim().contains(userName)) | ||
.findFirst() | ||
.isPresent(); | ||
} | ||
|
||
@Override | ||
public Object fetchResponseFromCache(String userName) { | ||
return authorizationCaching.getRecordFromAdminAuthCache(userName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
gate-web/src/main/java/com/opsmx/spinnaker/gate/service/PlatformCachingService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright 2021 OpsMx, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.opsmx.spinnaker.gate.service; | ||
|
||
public interface PlatformCachingService { | ||
|
||
void cacheResponse(Object response, String userName); | ||
|
||
boolean isCacheNotEmpty(String userName); | ||
|
||
Object fetchResponseFromCache(String userName); | ||
} |
Oops, something went wrong.