protected static void handlePatchPostPut(Service service, Operation op) { AuthCredentialsServiceState body = op.getBody(AuthCredentialsServiceState.class); // Credentials with SYSTEM scope need the password in plain text or they can't be used to // login into Xenon! boolean isSystemScope = (body.customProperties != null) && CredentialsScope.SYSTEM.toString().equals( body.customProperties.get(CUSTOM_PROP_CREDENTIALS_SCOPE)); if (!isSystemScope) { body.privateKey = EncryptionUtils.encrypt(body.privateKey); op.setBodyNoCloning(body); } }
public static DeferredResult<Void> handlePatchPostPut(Service service, Operation op) { AuthCredentialsServiceState body = op.getBody(AuthCredentialsServiceState.class); // Credentials with SYSTEM scope need the password in plain text or they can't be used to // login into Admiral! boolean isSystemScope = (body.customProperties != null) && AuthConfigProvider.CredentialsScope.SYSTEM.toString().equals( body.customProperties.get(AuthConfigProvider.PROPERTY_SCOPE)); if (!isSystemScope) { body.privateKey = EncryptionUtils.encrypt(body.privateKey); op.setBodyNoCloning(body); } return null; }
/** * Sets read/write permissions only to the owner of the encryption file. */ private void setEncryptionFilePermissions() throws Throwable { String encFileParam = System.getProperty(EncryptionUtils.ENCRYPTION_KEY); if (encFileParam == null) { return; } File f = new File(encFileParam); File parent = f.getParentFile(); // create parent folder if it does not exist if (!parent.exists() && !parent.mkdirs()) { log(Level.SEVERE, "Cannot create folders %s for encryption file.", parent.getAbsolutePath()); throw new IOException("Cannot create " + parent.getAbsolutePath()); } // dummy call to initialize the EncryptionUtils and create the encryption file EncryptionUtils.encrypt(null); try { // set file permissions setPermissionsToOwner(f); } catch (Throwable e) { log(Level.SEVERE, "Cannot change permissions of file %s. Error: %s", encFileParam, e.getMessage()); throw e; } }
@Override public void handleCreate(Operation op) { if (PhotonModelUtils.isFromMigration(op)) { op.complete(); return; } if (checkForValid(op)) { SessionState body = op.getBody(SessionState.class); body.externalToken = EncryptionUtils.encrypt(body.externalToken); super.handleCreate(op); } }