* @param userName - generate or get keys for this user
* @return - SQSKeys object
* @throws MessageBoxAdminException- if fails to get SQSKeys
*/
public SQSKeys getSQSKeys(String userName) throws MessageBoxAdminException {
Registry registry =
CarbonContext.getCurrentContext().getRegistry(RegistryType.SYSTEM_GOVERNANCE);
String loggedInUser = CarbonContext.getCurrentContext().getUsername();
String accessKeyId = null;
String secretAccessKeyId = null;
Collection userCollection;
try {
if (registry.resourceExists(RegistryConstants.PROFILES_PATH + userName)) {
userCollection = (Collection) registry.get(RegistryConstants.PROFILES_PATH + userName);
accessKeyId = userCollection.getProperty(MessageBoxConstants.ACCESS_KEY_ID);
secretAccessKeyId = userCollection.getProperty(MessageBoxConstants.SECRET_ACCESS_KEY_ID);
}
if (accessKeyId == null || secretAccessKeyId == null ||
(!registry.resourceExists(RegistryConstants.PROFILES_PATH + userName))) {
// generate keys
accessKeyId = UUID.randomUUID().toString();
secretAccessKeyId = UUID.fromString(accessKeyId).toString().
concat(UUID.randomUUID().toString()).replaceAll("-", "").substring(24);
accessKeyId = accessKeyId.replaceAll("-", "").substring(12);
// store keys in registry
userCollection = registry.newCollection();
registry.put(RegistryConstants.PROFILES_PATH + userName, userCollection);
userCollection.addProperty(MessageBoxConstants.ACCESS_KEY_ID, accessKeyId);
userCollection.addProperty(MessageBoxConstants.SECRET_ACCESS_KEY_ID, secretAccessKeyId);
registry.put(RegistryConstants.PROFILES_PATH + userName, userCollection);
// store user/access key in registry
String accessKeyIndexPath = MessageBoxConstants.REGISTRY_ACCESS_KEY_INDEX_PATH;
if (!registry.resourceExists(accessKeyIndexPath)) {
userCollection = registry.newCollection();
registry.put(accessKeyIndexPath, userCollection);
}
userCollection = (Collection) registry.get(accessKeyIndexPath);
userCollection.addProperty(accessKeyId, userName);
registry.put(accessKeyIndexPath, userCollection);
}
// we only allow user and admin to see the secret keys
try {
if (!(loggedInUser.equals(userName) || Utils.isAdmin(loggedInUser))) {