use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class SecurityGroupRuleDaoImpl method remove.
@Override
@DB
public boolean remove(Long id) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
SecurityGroupRuleVO entry = findById(id);
if (entry != null) {
_tagsDao.removeByIdAndType(id, ResourceObjectType.SecurityGroupRule);
}
boolean result = super.remove(id);
txn.commit();
return result;
}
use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class ProjectDaoImpl method remove.
@Override
@DB
public boolean remove(Long projectId) {
boolean result = false;
TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
ProjectVO projectToRemove = findById(projectId);
projectToRemove.setName(null);
if (!update(projectId, projectToRemove)) {
s_logger.warn("Failed to reset name for the project id=" + projectId + " as a part of project remove");
return false;
}
_tagsDao.removeByIdAndType(projectId, ResourceObjectType.Project);
result = super.remove(projectId);
txn.commit();
return result;
}
use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class HostTagsDaoImpl method deleteTags.
@Override
public void deleteTags(long hostId) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
SearchCriteria<HostTagVO> sc = HostSearch.create();
sc.setParameters("hostId", hostId);
expunge(sc);
txn.commit();
}
use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class FirewallRulesDaoImpl method remove.
@Override
@DB
public boolean remove(Long id) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
FirewallRuleVO entry = findById(id);
if (entry != null) {
if (entry.getPurpose() == Purpose.LoadBalancing) {
_tagsDao.removeByIdAndType(id, ResourceObjectType.LoadBalancer);
} else if (entry.getPurpose() == Purpose.PortForwarding) {
_tagsDao.removeByIdAndType(id, ResourceObjectType.PortForwardingRule);
} else if (entry.getPurpose() == Purpose.Firewall) {
_tagsDao.removeByIdAndType(id, ResourceObjectType.FirewallRule);
} else if (entry.getPurpose() == Purpose.NetworkACL) {
_tagsDao.removeByIdAndType(id, ResourceObjectType.NetworkACL);
}
}
boolean result = super.remove(id);
txn.commit();
return result;
}
use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class ConsoleProxyServlet method verifyRequest.
// copied and modified from ApiServer.java.
// TODO need to replace the whole servlet with a API command
private boolean verifyRequest(Map<String, Object[]> requestParameters) {
try {
String apiKey = null;
String secretKey = null;
String signature = null;
String unsignedRequest = null;
// - build a request string with sorted params, make sure it's all lowercase
// - sign the request, verify the signature is the same
List<String> parameterNames = new ArrayList<String>();
for (Object paramNameObj : requestParameters.keySet()) {
// put the name in a list that we'll sort later
parameterNames.add((String) paramNameObj);
}
Collections.sort(parameterNames);
for (String paramName : parameterNames) {
// parameters come as name/value pairs in the form String/String[]
String paramValue = ((String[]) requestParameters.get(paramName))[0];
if ("signature".equalsIgnoreCase(paramName)) {
signature = paramValue;
} else {
if ("apikey".equalsIgnoreCase(paramName)) {
apiKey = paramValue;
}
if (unsignedRequest == null) {
unsignedRequest = paramName + "=" + URLEncoder.encode(paramValue, "UTF-8").replaceAll("\\+", "%20");
} else {
unsignedRequest = unsignedRequest + "&" + paramName + "=" + URLEncoder.encode(paramValue, "UTF-8").replaceAll("\\+", "%20");
}
}
}
// if api/secret key are passed to the parameters
if ((signature == null) || (apiKey == null)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("expired session, missing signature, or missing apiKey -- ignoring request...sig: " + signature + ", apiKey: " + apiKey);
}
// no signature, bad request
return false;
}
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
User user = null;
// verify there is a user with this api key
Pair<User, Account> userAcctPair = _accountMgr.findUserByApiKey(apiKey);
if (userAcctPair == null) {
s_logger.debug("apiKey does not map to a valid user -- ignoring request, apiKey: " + apiKey);
return false;
}
user = userAcctPair.first();
Account account = userAcctPair.second();
if (!user.getState().equals(Account.State.enabled) || !account.getState().equals(Account.State.enabled)) {
s_logger.debug("disabled or locked user accessing the api, userid = " + user.getId() + "; name = " + user.getUsername() + "; state: " + user.getState() + "; accountState: " + account.getState());
return false;
}
// verify secret key exists
secretKey = user.getSecretKey();
if (secretKey == null) {
s_logger.debug("User does not have a secret key associated with the account -- ignoring request, username: " + user.getUsername());
return false;
}
unsignedRequest = unsignedRequest.toLowerCase();
Mac mac = Mac.getInstance("HmacSHA1");
SecretKeySpec keySpec = new SecretKeySpec(secretKey.getBytes(), "HmacSHA1");
mac.init(keySpec);
mac.update(unsignedRequest.getBytes());
byte[] encryptedBytes = mac.doFinal();
String computedSignature = Base64.encodeBase64String(encryptedBytes);
boolean equalSig = ConstantTimeComparator.compareStrings(signature, computedSignature);
if (!equalSig) {
s_logger.debug("User signature: " + signature + " is not equaled to computed signature: " + computedSignature);
}
if (equalSig) {
requestParameters.put("userid", new Object[] { String.valueOf(user.getId()) });
requestParameters.put("account", new Object[] { account.getAccountName() });
requestParameters.put("accountobj", new Object[] { account });
}
return equalSig;
} catch (Exception ex) {
s_logger.error("unable to verifty request signature", ex);
}
return false;
}
Aggregations