Skip to content

Commit

Permalink
Correct thread-safe caching in CmdbOwnerService and several other fixes
Browse files Browse the repository at this point in the history
Removed IdentityProvider from places where it is unused.

Corrected the way of handling provider.emails property.
  • Loading branch information
fid-cyfronet committed Sep 15, 2017
1 parent f737240 commit 0c87ce6
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 47 deletions.
2 changes: 1 addition & 1 deletion docker/indigo-slam.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ java -Dserver.address=0.0.0.0 \
-Dunity.server.clientId=$IAM_CLIENT_ID \
-Dunity.server.clientSecret=$IAM_CLIENT_SECRET \
-Dcmdb.url=$CMDB_URL \
-Dprovider.email=$PROVIDER_EMAIL \
-Dprovider.emails=$PROVIDER_EMAIL \
-Djdbc.url=$JDBC_URL \
-Djdbc.username=$MYSQL_USER \
-Djdbc.password=$MYSQL_PASSWORD \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package pl.cyfronet.bazaar.engine.extension.constraint.action.impl;

import com.agreemount.bean.document.Document;
import com.agreemount.bean.identity.provider.IdentityProvider;
import com.agreemount.slaneg.action.ActionContext;
import com.agreemount.slaneg.constraint.action.impl.QualifierImpl;
import com.google.common.base.Preconditions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
Expand All @@ -21,9 +19,6 @@
@Scope("prototype")
public class HasAnyOfMetricsImpl extends QualifierImpl<HasAnyOfMetrics,ActionContext> {

@Autowired
private IdentityProvider identityProvider;

@Override
public boolean isAvailable() {
String alias = getConstraintDefinition().getDocumentAlias();
Expand All @@ -46,4 +41,4 @@ public boolean isAvailable() {

return result;
}
}
}
9 changes: 0 additions & 9 deletions src/main/java/pl/cyfronet/ltos/controller/LegacyMethods.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package pl.cyfronet.ltos.controller;

import com.agreemount.bean.identity.provider.IdentityProvider;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
Expand All @@ -12,7 +10,6 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.view.RedirectView;
import pl.cyfronet.ltos.bean.User;
import pl.cyfronet.ltos.repository.UserRepository;
import pl.cyfronet.ltos.security.UserInfo;

import javax.servlet.http.HttpSession;
Expand All @@ -22,12 +19,6 @@
@Log4j
public class LegacyMethods {

@Autowired
private UserRepository userRepository;

@Autowired
private IdentityProvider identityProvider;

@RequestMapping(value = "user/get", method = RequestMethod.GET)
@Transactional
public ResponseEntity<User> getUser() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
import org.springframework.security.oauth2.client.OAuth2RestOperations;
import org.springframework.stereotype.Service;
import pl.cyfronet.ltos.bean.User;
import pl.cyfronet.ltos.repository.CmdbRepository;
import pl.cyfronet.ltos.repository.UserRepository;
import pl.cyfronet.ltos.security.AuthenticationProviderDev.UserOperations;

import javax.net.ssl.HttpsURLConnection;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
import java.util.stream.Collectors;

@Service
Expand All @@ -41,10 +42,7 @@ public class AuthenticationService {
private UserOperations userOperations;

@Autowired
IdentityProvider identityProvider;

@Autowired
private CmdbRepository cmdbRepository;
private IdentityProvider identityProvider;

@Autowired
private PortalUserFactory portalUserFactory;
Expand Down
12 changes: 3 additions & 9 deletions src/main/java/pl/cyfronet/ltos/security/CmdbOwnerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,14 @@ public CmdbOwnerService(
this.refreshInterval = refreshInterval;
}

public Set<String> getOwnedProviders(String email) {
public synchronized Set<String> getOwnedProviders(String email) {
if (isCacheInvalid()) {
synchronized (this) {
// If entering critical section after waiting on lock, the cache may already have
// been refreshed. So check again.
if (isCacheInvalid()) {
doRefresh();
}
}
doRefresh();
}
return ownerEmailToProviders.getOrDefault(email, Collections.EMPTY_SET);
}

public void invalidateCache() {
public synchronized void invalidateCache() {
lastRefresh = 0L;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package pl.cyfronet.ltos.security;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.Authentication;
Expand All @@ -17,7 +11,10 @@
import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;

import com.agreemount.bean.identity.provider.IdentityProvider;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
* Created by km on 04.08.16.
Expand All @@ -27,9 +24,6 @@ public class OpenIDConnectAuthenticationFilter extends AbstractAuthenticationPro
@Value("${unity.unauthorizedAction}")
private String unauthorizedAction;

@Autowired
IdentityProvider identityProvider;

@Autowired
private AuthenticationService authenticationService;

Expand Down
10 changes: 4 additions & 6 deletions src/main/java/pl/cyfronet/ltos/security/PortalUserImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,17 @@ public static class Data {

private final Data data;

private Set<? extends GrantedAuthority> authorities = null;

@Autowired
private CmdbOwnerService cmdbOwnerService;

//development variable, users whose email matches this will have provider role assigned
@Value("${provider.email:null}")
private Set<String> devProviderEmails;

public PortalUserImpl(Data data) {
this.data = data;
}

/// development variable, users whose email matches this will have provider role assigned
@Value("${provider.emails:}")
private String devProviderEmails;

@Override
public String getName() {
return data.name;
Expand Down

0 comments on commit 0c87ce6

Please sign in to comment.