74 lines
2.4 KiB
Java
74 lines
2.4 KiB
Java
package org.gcube.application.framework.core.util;
|
|
|
|
import java.io.File;
|
|
|
|
import org.gcube.vomanagement.vomsapi.CredentialsManager;
|
|
import org.gcube.vomanagement.vomsapi.VOMSAdmin;
|
|
import org.gcube.vomanagement.vomsapi.impl.VOMSAPIConfiguration;
|
|
import org.gcube.vomanagement.vomsapi.impl.VOMSAPIFactory;
|
|
import org.gridforum.jgss.ExtendedGSSCredential;
|
|
|
|
/**
|
|
* @author Valia Tsagkalidou (NKUA)
|
|
*
|
|
*/
|
|
public class UserCredential {
|
|
/**
|
|
* Retrieves credential for users
|
|
* @param username the user name for which it will retrieve credential
|
|
* @param DLname DLname
|
|
* @return the GSS Credential
|
|
*/
|
|
public static ExtendedGSSCredential getCredential(String username, String DLname)
|
|
{
|
|
CredentialsManager man = null;
|
|
try {
|
|
String sharedDir = Settings.getInstance().getProperty("sharedDir");
|
|
System.out.println("file " + sharedDir + "/vomsAPI.properties exists: "+ new File(sharedDir + "/vomsAPI.properties").exists());
|
|
// man = new CredentialsManagerImpl(sharedDir + "/vomsAPI.properties");
|
|
|
|
VOMSAPIFactory factory = new VOMSAPIFactory(new VOMSAPIConfiguration(new File(sharedDir + "/vomsAPI.properties")));
|
|
VOMSAdmin vomsAdm = factory.getVOMSAdmin();
|
|
man = factory.getCredentialsManager();
|
|
} catch (Exception e1) {
|
|
e1.printStackTrace();
|
|
}
|
|
ExtendedGSSCredential cred = null;
|
|
try {
|
|
//TODO: put a real password there...
|
|
cred = man.getAttributedCredentials(username, "", DLname);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
return cred;
|
|
}
|
|
|
|
public static ExtendedGSSCredential getPlainCredential(String username, String password)
|
|
{
|
|
CredentialsManager man = null;
|
|
try {
|
|
String sharedDir = Settings.getInstance().getProperty("sharedDir");
|
|
System.out.println("file " + sharedDir + "/vomsAPI.properties exists: "+ new File(sharedDir + "/vomsAPI.properties").exists());
|
|
// man = new CredentialsManagerImpl(sharedDir + "/vomsAPI.properties");
|
|
|
|
VOMSAPIFactory factory = new VOMSAPIFactory(new VOMSAPIConfiguration(new File(sharedDir + "/vomsAPI.properties")));
|
|
VOMSAdmin vomsAdm = factory.getVOMSAdmin();
|
|
man = factory.getCredentialsManager();
|
|
} catch (Exception e1) {
|
|
e1.printStackTrace();
|
|
}
|
|
ExtendedGSSCredential cred = null;
|
|
try {
|
|
//TODO: put a real password there...
|
|
cred = man.getPlainCredentials(username, password);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
return cred;
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|