Skip to content

Commit

Permalink
More working on listener & notification support.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaceccanti committed Nov 10, 2012
1 parent a604c4f commit 38e2a5b
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 22 deletions.
5 changes: 3 additions & 2 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Vincenzo Ciaschini <[email protected]>
Andrea Ceccanti <[email protected]>
Andrea Ceccanti <[email protected]>
Valerio Venturi <[email protected]>
Daniele Andreotti <[email protected]>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.italiangrid.voms.credential.LoadCredentialsEventListener;
import org.italiangrid.voms.credential.LoadCredentialsEventListener.LoadCredentialOutcome;
import org.italiangrid.voms.credential.LoadCredentialsStrategy;
import org.italiangrid.voms.credential.VOMSEnvironmentVariables;

import eu.emi.security.authn.x509.X509Credential;
import eu.emi.security.authn.x509.impl.KeystoreCredential;
Expand All @@ -20,20 +21,13 @@
* @author andreaceccanti
*
*/
public abstract class AbstractLoadCredentialsStrategy implements LoadCredentialsStrategy {
public abstract class AbstractLoadCredentialsStrategy implements LoadCredentialsStrategy, VOMSEnvironmentVariables {

/**
* The {@link LoadCredentialsEventListener} that is notified of load credentials outcome.
*/
LoadCredentialsEventListener listener;

/**
* Default constructor
*/
protected AbstractLoadCredentialsStrategy(){
this.listener = new LoggingCredentialNotificationListener();
}

/**
* Constructor that let client pass in a {@link LoadCredentialsEventListener}.
* @param listener the listener that is notified of load credential events from this {@link AbstractLoadCredentialsStrategy}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@
* </ul>
*
*/
public class DefaultLoadCredentialsStrategy extends AbstractLoadCredentialsStrategy
implements VOMSEnvironmentVariables {
public class DefaultLoadCredentialsStrategy extends AbstractLoadCredentialsStrategy {

public static final Logger log = LoggerFactory.getLogger(DefaultLoadCredentialsStrategy.class);

private static final String GLOBUS_PKCS12_CRED_PATH_SUFFIX = ".globus/usercred.p12";
private static final String GLOBUS_PEM_CERT_PATH_SUFFIX = ".globus/usercert.pem";
private static final String GLOBUS_PEM_KEY_PATH_SUFFIX = ".globus/userkey.pem";

private static final String HOME_PROPERTY = "user.home";
private static final String TMPDIR_PROPERTY = "java.io.tmpdir";
public static final String HOME_PROPERTY = "user.home";
public static final String TMPDIR_PROPERTY = "java.io.tmpdir";
public static final String TMPDIR_PATH = "/tmp";

private static final ProxyPathBuilder proxyPathBuilder = new DefaultProxyPathBuilder();

Expand All @@ -87,6 +87,10 @@ public DefaultLoadCredentialsStrategy() {
this(System.getProperty(HOME_PROPERTY), System.getProperty(TMPDIR_PROPERTY), new LoggingCredentialNotificationListener());
}

public DefaultLoadCredentialsStrategy(LoadCredentialsEventListener listener){
this(System.getProperty(HOME_PROPERTY), System.getProperty(TMPDIR_PROPERTY), listener);
}

/**
* Looks for the value of a given property in the environment or in the
* system properties
Expand Down Expand Up @@ -133,7 +137,7 @@ public X509Credential loadCredentials(PasswordFinder pf) {
}


private X509Credential loadProxyFromUID() throws KeyStoreException, CertificateException, FileNotFoundException, IOException{
protected X509Credential loadProxyFromUID(){
String uid = getFromEnvOrSystemProperty(VOMS_USER_ID);

if (uid != null){
Expand All @@ -143,7 +147,8 @@ private X509Credential loadProxyFromUID() throws KeyStoreException, CertificateE

return null;
}
private X509Credential loadProxyFromEnv() throws KeyStoreException, CertificateException, FileNotFoundException, IOException{

protected X509Credential loadProxyFromEnv() {

String proxyPath = getFromEnvOrSystemProperty(X509_USER_PROXY);
if (proxyPath != null)
Expand All @@ -152,7 +157,7 @@ private X509Credential loadProxyFromEnv() throws KeyStoreException, CertificateE
return null;
}

private X509Credential loadPEMCredentialFromEnv(PasswordFinder pf) throws KeyStoreException, CertificateException, FileNotFoundException, IOException{
protected X509Credential loadPEMCredentialFromEnv(PasswordFinder pf) {
String certPath = getFromEnvOrSystemProperty(X509_USER_CERT);
String keyPath = getFromEnvOrSystemProperty(X509_USER_KEY);

Expand All @@ -163,7 +168,7 @@ private X509Credential loadPEMCredentialFromEnv(PasswordFinder pf) throws KeySto
return null;
}

private X509Credential loadPKCS12CredentialFromEnv(PasswordFinder pf) throws KeyStoreException, IOException{
protected X509Credential loadPKCS12CredentialFromEnv(PasswordFinder pf) {
String pkcs12Path = getFromEnvOrSystemProperty(PKCS12_USER_CERT);

if (pkcs12Path != null){
Expand All @@ -174,15 +179,15 @@ private X509Credential loadPKCS12CredentialFromEnv(PasswordFinder pf) throws Key



private X509Credential loadPKCS12CredentialsFromGlobusDir(PasswordFinder pf) throws KeyStoreException, IOException {
protected X509Credential loadPKCS12CredentialsFromGlobusDir(PasswordFinder pf) {

String credPath = String.format("%s/%s", home, GLOBUS_PKCS12_CRED_PATH_SUFFIX);
return loadPKCS12Credential(credPath, pf);

}


private X509Credential loadPEMCredentialsFromGlobusDir(PasswordFinder pf) throws KeyStoreException, CertificateException, FileNotFoundException, IOException {
protected X509Credential loadPEMCredentialsFromGlobusDir(PasswordFinder pf) {

String certPath = String.format("%s/%s", home, GLOBUS_PEM_CERT_PATH_SUFFIX);
String keyPath = String.format("%s/%s", home, GLOBUS_PEM_KEY_PATH_SUFFIX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@ public interface VOMSESLookupStrategy {
* used to parse VOMSES information.
*/
public List<File> lookupVomsesInfo();

/**
* @return a {@link List} of the paths that have been looked up to find
* {@link File} objects that can be used to parse VOMSES information.
*/
public List<String> searchedPaths();
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package org.italiangrid.voms.request;

import java.util.List;

public interface VOMSServerInfoStoreListener {

public void noValidVomsesNotification(List<String> searchedPaths);
public void lookupNotification(String vomsesPath);
public void serverInfoLoaded(String vomsesPath, VOMSServerInfo info);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.italiangrid.voms.request.VOMSESLookupStrategy;
Expand Down Expand Up @@ -33,4 +34,8 @@ public List<File> lookupVomsesInfo() {
return vomsesPaths;
}

public List<String> searchedPaths() {
return Arrays.asList(checkedPaths);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,13 @@ private void initializeStore() {

List<File> vomsesPaths = lookupStrategy.lookupVomsesInfo();

if (vomsesPaths.isEmpty())
listener.noValidVomsesNotification(lookupStrategy.searchedPaths());

for (File f: vomsesPaths){

listener.lookupNotification(f.getAbsolutePath());

List<VOMSServerInfo> vomsServerInfo = vomsesParser.parse(f);
for (VOMSServerInfo si: vomsServerInfo){
addVOMSServerInfo(si, f.getAbsolutePath());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.italiangrid.voms.request.impl;

import java.util.List;

import org.italiangrid.voms.request.VOMSServerInfo;
import org.italiangrid.voms.request.VOMSServerInfoStoreListener;
import org.slf4j.Logger;
Expand All @@ -14,9 +16,20 @@ public class LoggingServerInfoStoreListener implements
public void serverInfoLoaded(String vomsesPath, VOMSServerInfo info) {

if (vomsesPath == null)
log.debug("Loaded %s", info);
log.debug("Loaded {}", info);
else
log.debug("Loaded %s from %s", info, vomsesPath);
log.debug("Loaded {} from {}", info, vomsesPath);
}


public void lookupNotification(String vomsesPath) {
log.debug("Looking for VOMSES information in {}", vomsesPath);

}

public void noValidVomsesNotification(List<String> searchedPaths) {
log.debug("No valid VOMSES information found on the local machine while looking in: "+searchedPaths);

}

}

0 comments on commit 38e2a5b

Please sign in to comment.