Magentix2
2.1.1
|
Public Member Functions | |
boolean | generateAllProcessCertificate (String Agentname, Properties propSecurityUser) |
Static Public Member Functions | |
static SecurityTools | GetInstance () |
Package Attributes | |
FileWriter | fichero = null |
PrintWriter | pw = null |
Static Package Attributes | |
static Logger | logger = Logger.getLogger(SecurityTools.class) |
This class provides support to work in secure mode
Definition at line 53 of file SecurityTools.java.
boolean es.upv.dsic.gti_ia.secure.SecurityTools.generateAllProcessCertificate | ( | String | Agentname, |
Properties | propSecurityUser | ||
) |
This class is responsible for request the agent certificate if this not exists or is not valid.
Agentname | This is a name of agent |
propSecurityUser |
Definition at line 93 of file SecurityTools.java.
{ String name = Agentname; String path = propSecurityUser.getProperty("KeyStorePath"); String pass = propSecurityUser.getProperty("KeyStorePassword"); String alias = propSecurityUser.getProperty("alias"); //String key = propSecurityUser.getProperty("key"); String type = propSecurityUser.getProperty("type"); try { // String connection with the MMS service. String target = propSecurityUser.getProperty("protocol") + "://" + propSecurityUser.getProperty("host") + ":" + propSecurityUser.getProperty("port") + propSecurityUser.getProperty("path"); //Loaded the user keystore. KeyStore keystoreUser = this.getKeyStore(path, pass); //If not exist, will be create a new Keystore. if (keystoreUser == null) keystoreUser = this.createKeyStore(path, pass); //Check if agent has a valid certificate. if (getExistAliasAndIsValidPeriod(keystoreUser, name)) { //If agent not has or is not valid, a new certificate is created. //This is sends to MMS service. The MMS services is responsible to be signs the certificate. // create the client stub System.out.println("Connecting to " + target); // To be able to load the client configuration from axis2.xml ConfigurationContext ctx = ConfigurationContextFactory .createConfigurationContextFromFileSystem( "./configuration/client-repo", null); MMSStub stub = new MMSStub(ctx, target); stub._getServiceClient().engageModule("rampart"); // We configure the security Rampart module. Policy rampartConfig = getRampartConfig(alias,type, propSecurityUser); stub._getServiceClient().getAxisService().getPolicySubject().attachPolicy(rampartConfig); //We make the private/public key pair, the MMS only has that sign the certificates. KeyPair kp = generateKeyPair("RSA", 1024); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); ObjectOutputStream os = new ObjectOutputStream(outStream); //Send the public key. PublicKey pbk = kp.getPublic(); Object p = pbk; os.writeObject(p); os.close(); DataSource dataSource = new ByteArrayDataSource(outStream .toByteArray(), "application/octet-stream"); DataHandler dataHandler = new DataHandler(dataSource); //Call service is created. DataHandler re = stub.mMS(name, dataHandler); //re is a result of service request. try { InputStream inputDataHandler = re.getInputStream(); byte[] arrayByte = IOUtils.toByteArray(inputDataHandler); ByteArrayInputStream bis = new ByteArrayInputStream(arrayByte); ObjectInputStream ois = new ObjectInputStream(bis); Certificate[] certificates = (Certificate[]) ois.readObject(); ois.close(); //The signed certificate is added in keystore. setKeyEntry(name, propSecurityUser, kp, certificates); //Todo ha ido correctamente. return true; } catch(Exception e) { //El MMS le ha denegado la emision del certificado. logger.error("MMS is not available now or the user not has the permissions to acquire the name " + Agentname); return false; } } else //Tiene un certificado emitido por el MMS valido. return true; } catch (Exception e) { logger.error(e); return false; } }
static SecurityTools es.upv.dsic.gti_ia.secure.SecurityTools.GetInstance | ( | ) | [static] |
Returns an instance of the SecurityTools class.
Definition at line 75 of file SecurityTools.java.
{
return sec;
}
FileWriter es.upv.dsic.gti_ia.secure.SecurityTools.fichero = null [package] |
Definition at line 56 of file SecurityTools.java.
Logger es.upv.dsic.gti_ia.secure.SecurityTools.logger = Logger.getLogger(SecurityTools.class) [static, package] |
Definition at line 60 of file SecurityTools.java.
PrintWriter es.upv.dsic.gti_ia.secure.SecurityTools.pw = null [package] |
Definition at line 57 of file SecurityTools.java.