use of com.emc.storageos.db.exceptions.DatabaseException in project coprhd-controller by CoprHD.
the class DbCli method queryAndPrintRecords.
/**
* Query for records with the given ids and type, and print the contents in human readable format
*
* @param ids
* @param clazz
* @param <T>
*/
private <T extends DataObject> int queryAndPrintRecords(List<URI> ids, Class<T> clazz) throws Exception {
Iterator<T> objects;
BeanInfo bInfo;
int countLimit = 0;
int countAll = 0;
String input;
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
try {
objects = _dbClient.queryIterativeObjects(clazz, ids);
bInfo = Introspector.getBeanInfo(clazz);
while (objects.hasNext()) {
T object = (T) objects.next();
printBeanProperties(bInfo.getPropertyDescriptors(), object);
countLimit++;
countAll++;
if (!turnOnLimit || countLimit != listLimit) {
continue;
}
System.out.println(String.format("Read %s rows ", countAll));
do {
System.out.println("\nPress 'ENTER' to continue or 'q<ENTER>' to quit...");
input = buf.readLine();
if (input.isEmpty()) {
countLimit = 0;
break;
}
if (input.equalsIgnoreCase(QUITCHAR)) {
return countAll;
}
} while (!input.isEmpty());
}
} catch (DatabaseException ex) {
log.error("Error querying from db: " + ex);
System.out.println("Error querying from db: " + ex);
throw ex;
} catch (IntrospectionException ex) {
log.error("Unexpected exception getting bean info", ex);
throw new RuntimeException("Unexpected exception getting bean info", ex);
} finally {
buf.close();
}
return countAll;
}
use of com.emc.storageos.db.exceptions.DatabaseException in project coprhd-controller by CoprHD.
the class DBClient method queryAndPrintRecords.
/**
* Query for records with the given ids and type, and print the contents in human readable format
*
* @param ids
* @param clazz
* @param <T>
*/
private <T extends DataObject> int queryAndPrintRecords(List<URI> ids, Class<T> clazz, Map<String, String> criterias) throws Exception {
int countLimit = 0;
int countAll = 0;
String input;
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
boolean isPrint = true;
try {
Iterator<URI> uriIter = ids.iterator();
while (uriIter.hasNext()) {
URI uri = uriIter.next();
T object = (T) _dbClient.queryObject(uri);
if (object == null) {
continue;
}
isPrint = printBeanProperties(clazz, object, criterias);
if (isPrint) {
countLimit++;
countAll++;
}
if (!turnOnLimit || countLimit != listLimit) {
continue;
}
System.out.println(String.format("Read %s rows ", countAll));
do {
System.out.println("\nPress 'ENTER' to continue or 'q<ENTER>' to quit...");
input = buf.readLine();
if (input.isEmpty()) {
countLimit = 0;
break;
}
if (input.equalsIgnoreCase(QUITCHAR)) {
return countAll;
}
} while (!input.isEmpty());
}
} catch (DatabaseException ex) {
log.error("Error querying from db: " + ex);
System.err.println("Error querying from db: " + ex);
throw ex;
} finally {
buf.close();
}
return countAll;
}
use of com.emc.storageos.db.exceptions.DatabaseException in project coprhd-controller by CoprHD.
the class DBClient method queryForCustomDayAudits.
/**
* Query audit
*
* @param dateTime
*/
public void queryForCustomDayAudits(DateTime dateTime, String filename) {
System.out.println("\n\n -> Querying Audits");
ExecutorService executor = Executors.newFixedThreadPool(100);
AuditQueryResult result = new AuditQueryResult(filename);
try {
_dbClient.queryTimeSeries(AuditLogTimeSeries.class, dateTime, TimeSeriesMetadata.TimeBucket.HOUR, result, executor);
System.out.println(" --- Job Exceution for Querying Audits completed ---\n\n");
return;
} catch (DatabaseException e) {
System.err.println("Exception Query " + e);
log.error("Exception Query ", e);
}
}
use of com.emc.storageos.db.exceptions.DatabaseException in project coprhd-controller by CoprHD.
the class UserInfoPage method getMyInfo.
/**
* This call returns the list of tenants that the user maps to including the details of the mappings.
* It also returns a list of the virtual data center roles and tenant roles assigned to this user.
*
* @brief Show my Tenant and assigned roles
* @prereq none
* @return List of tenants user mappings,VDC role and tenant role of the user.
*/
@GET
@Path("/whoami")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public UserInfo getMyInfo() {
Principal principal = sc.getUserPrincipal();
if (!(principal instanceof StorageOSUser)) {
throw APIException.forbidden.invalidSecurityContext();
}
StorageOSUser user = (StorageOSUser) principal;
UserInfo info = new UserInfo();
info.setCommonName(user.getName());
// To Do - fix Distinguished name - for now setting it to name
info.setDistinguishedName(user.getName());
info.setTenant(user.getTenantId());
info.setTenantName(_permissionsHelper.getTenantNameByID(user.getTenantId()));
info.setVdcRoles(new ArrayList<String>());
info.setHomeTenantRoles(new ArrayList<String>());
info.setSubTenantRoles(new ArrayList<SubTenantRoles>());
// special check: root in geo scenario
boolean isLocalVdcSingleSite = VdcUtil.isLocalVdcSingleSite();
boolean isRootInGeo = user.getName().equalsIgnoreCase("root") && (!isLocalVdcSingleSite);
// add Vdc Roles
if (user.getRoles() != null) {
for (String role : user.getRoles()) {
// geo scenario, return RESTRICTED_*_ADMIN for root, instead of *_ADMIN
if (isRootInGeo) {
if (role.equalsIgnoreCase(Role.SYSTEM_ADMIN.toString())) {
role = Role.RESTRICTED_SYSTEM_ADMIN.toString();
}
if (role.equalsIgnoreCase(Role.SECURITY_ADMIN.toString())) {
role = Role.RESTRICTED_SECURITY_ADMIN.toString();
}
}
info.getVdcRoles().add(role);
}
}
// geo scenario, skip adding tenant roles for root
if (isRootInGeo) {
return info;
}
try {
Set<String> tenantRoles = _permissionsHelper.getTenantRolesForUser(user, URI.create(user.getTenantId()), false);
if (tenantRoles != null) {
for (String role : tenantRoles) {
info.getHomeTenantRoles().add(role);
}
}
Map<String, Collection<String>> subTenantRoles = _permissionsHelper.getSubtenantRolesForUser(user);
if (subTenantRoles != null) {
for (Entry<String, Collection<String>> entry : subTenantRoles.entrySet()) {
SubTenantRoles subRoles = new SubTenantRoles();
subRoles.setTenant(entry.getKey());
subRoles.setTenantName(_permissionsHelper.getTenantNameByID(entry.getKey()));
subRoles.setRoles(new ArrayList<String>(entry.getValue()));
info.getSubTenantRoles().add(subRoles);
}
}
} catch (DatabaseException ex) {
throw SecurityException.fatals.failedReadingTenantRoles(ex);
}
return info;
}
use of com.emc.storageos.db.exceptions.DatabaseException in project coprhd-controller by CoprHD.
the class UserFromRequestHelper method parseOldFormat.
/**
* This method parses the userContext information using the "old" format
* ( "user,user@domain.com;group,group2")
* TODO: once AD integration is complete and attribute release is only
* available through that channel, this old format should be removed. For
* now, keeping for backwards compatibility and so that authz testing can
* continue without AD servers.
*
* @param userContext
* @return a UserFromRequest pojo
*/
private StorageOSUser parseOldFormat(String userContext) {
StorageOSUser user = null;
if (!StringUtils.isBlank(userContext)) {
String[] userInfo = userContext.split(";");
String[] userAttributes = userInfo[0].split(",");
String name = userAttributes[0];
String[] parts = name.split("@");
String domain = "";
if (parts.length > 1) {
domain = parts[1];
}
URI tenant = null;
boolean local = false;
if (userAttributes.length > 1 && null != userAttributes[1] && !StringUtils.isBlank(userAttributes[1])) {
String[] attrKV = userAttributes[1].split("=");
if (attrKV[0].equals(USERDETAILS_LOCALUSER)) {
if (attrKV.length > 1 && Boolean.valueOf(attrKV[1])) {
local = true;
}
} else {
UserMapping mapping = new UserMapping();
mapping.setDomain(domain);
if (attrKV.length > 1) {
if (attrKV[0].equalsIgnoreCase("group")) {
mapping.setGroups(Collections.singletonList(attrKV[1]));
} else {
UserMappingAttribute tenantAttribute = new UserMappingAttribute();
tenantAttribute.setKey(attrKV[0]);
tenantAttribute.setValues(Collections.singletonList(attrKV[1]));
}
try {
tenant = _permissionsHelper.lookupTenant(mapping);
} catch (DatabaseException e) {
_logger.error("Failed to query for tenant with attribute: {}. Exception {} ", mapping.toString(), e);
}
}
}
} else if (!domain.isEmpty()) {
UserMapping mapping = new UserMapping();
mapping.setDomain(domain);
try {
tenant = _permissionsHelper.lookupTenant(mapping);
} catch (DatabaseException e) {
_logger.error("Failed to query for tenant with attribute: {}. Exception {} ", mapping.toString(), e);
}
}
if (null == tenant) {
tenant = _permissionsHelper.getRootTenant().getId();
}
user = new StorageOSUser(name, tenant.toString());
user.setIsLocal(local);
if (userInfo.length > 1) {
String[] groups = org.springframework.util.StringUtils.commaDelimitedListToStringArray(userInfo[1]);
if (groups.length > 0) {
for (String group : groups) {
user.addGroup(group);
}
}
}
return user;
}
return null;
}
Aggregations