Example usage for com.mongodb DBObject get

List of usage examples for com.mongodb DBObject get

Introduction

In this page you can find the example usage for com.mongodb DBObject get.

Prototype

Object get(String key);

Source Link

Document

Gets a field from this object by a given name.

Usage

From source file:com.ccoe.build.alerts.devx.DevxReportJob.java

License:Apache License

private DBObject getDataObjFromDB(DB db, String collectionName, Condition current) {
    DBCollection dbc = Connector.connectCollection(db, collectionName);
    DBObject totaldbo = Connector.getLastRecord(dbc, current.getStartDate(), current.getEndDate());
    System.out.println("collectionName: " + collectionName + " start " + current.getStartDate() + " end "
            + current.getEndDate());//from  www  . ja  va2  s  .com

    if (totaldbo != null) {
        return (DBObject) totaldbo.get("Data");
    } else {
        return null;
    }
}

From source file:com.ccoe.build.alerts.devx.DevxReportJob.java

License:Apache License

private double getValueFromDataObj(DBObject dbo, String fieldName) {
    Set<String> keyset = dbo.keySet();

    for (String keyname : keyset) {
        if (fieldName.equals(keyname)) {
            Object keyvalue = dbo.get(keyname);
            if (keyvalue instanceof Integer) {
                int k1 = (Integer) keyvalue;
                return Double.parseDouble("" + k1);
            } else if (keyvalue instanceof Double) {
                return (Double) keyvalue;
            }//from  w  ww. ja v  a 2  s . c o m
        }
    }
    return -1;
}

From source file:com.cedac.security.acls.mongo.MongoAclService.java

License:Apache License

@Override
@SuppressWarnings("unchecked")
public Acl readAclById(ObjectIdentity object, List<Sid> sids) throws NotFoundException {
    LOG.trace(ACL, "Reading ACL for object identity {}", object);

    Acl acl = aclCache.getFromCache(object);
    if (acl != null && acl.isSidLoaded(sids)) {
        LOG.debug(ACL, "ACL for id {} found in cache: {}", object, acl);

        return acl;
    } else {/*  w w w  . ja  v  a2  s .  co m*/
        LOG.trace(ACL, "No ACL found in cache for id {}: looking into backend.", object);

        DBObject result = getAclCollection().findOne(queryByObjectIdentity(object));
        if (result == null) {
            LOG.warn(ACL, "No ACL found for object identity {}", object);

            throw new NotFoundException("No ACL found for object identity " + object);
        }

        LOG.trace(ACL, "Trying to loading parent ACL if needed.");

        Acl parentAcl = null;
        DBObject parentDbo = (DBObject) result.get(parentObjectFieldName);
        if (parentDbo != null) {
            parentAcl = readAclById(toObjectIdentity(parentDbo));
        }

        LOG.trace(ACL, "Extracting loaded SIDs");

        List<DBObject> entries = (List<DBObject>) result.get(entriesFieldName);
        Set<Sid> loadedSids = new HashSet<Sid>();
        if (sids != null) {
            loadedSids.addAll(sids);
        }
        if (entries != null) {
            for (DBObject entry : entries) {
                loadedSids.add(toSid((DBObject) entry.get(sidFieldName)));
            }
        }

        Sid owner = toSid((DBObject) result.get(ownerFieldName));

        AclImpl loadedAcl = new AclImpl(object, result.get("_id").toString(), aclAuthorizationStrategy,
                permissionGrantingStrategy, parentAcl, new ArrayList<Sid>(loadedSids),
                (Boolean) result.get(entriesInheritingFieldName), owner);
        if (entries != null) {
            List<AccessControlEntry> aces = new ArrayList<AccessControlEntry>();
            for (int i = 0; i < entries.size(); i++) {
                aces.add(toAccessControlEntry(i, loadedAcl, entries.get(i)));
            }
            try {
                acesField.set(loadedAcl, new ArrayList<AccessControlEntry>(aces));
            } catch (Exception ex) {
                throw new IllegalStateException("Unable to set ACEs.", ex);
            }
        }
        aclCache.putInCache(loadedAcl);
        return loadedAcl;
    }
}

From source file:com.cedac.security.acls.mongo.MongoAclService.java

License:Apache License

protected final AccessControlEntry toAccessControlEntry(int id, Acl acl, DBObject dbo) {
    Sid sid = toSid((DBObject) dbo.get(sidFieldName));
    Permission permission = permissionFactory
            .buildFromMask(Number.class.cast(dbo.get(maskFieldName)).intValue());
    boolean granting = (Boolean) dbo.get(grantingFieldName);
    Boolean auditSuccess = (Boolean) dbo.get(auditSuccessFieldName);
    if (auditSuccess == null) {
        auditSuccess = Boolean.FALSE;
    }//from   w ww.jav  a  2s  .c  o  m
    Boolean auditFailure = (Boolean) dbo.get(auditFailureFieldName);
    if (auditFailure == null) {
        auditFailure = Boolean.FALSE;
    }
    return new AccessControlEntryImpl(id, acl, sid, permission, granting, auditSuccess, auditFailure);
}

From source file:com.cedac.security.acls.mongo.MongoAclService.java

License:Apache License

protected final Sid toSid(DBObject dbo) {
    final boolean principal = (Boolean) dbo.get(principalFieldName);
    final String sid = (String) dbo.get(sidFieldName);
    if (principal) {
        return new PrincipalSid(sid);
    } else {/* ww  w .  ja  v a2  s.co  m*/
        return new GrantedAuthoritySid(sid);
    }
}

From source file:com.cedac.security.acls.mongo.MongoAclService.java

License:Apache License

protected final ObjectIdentity toObjectIdentity(DBObject dbo) {
    final String type = dbo.get(classFieldName).toString();
    final String identity = dbo.get(identityFieldName).toString();
    return new ObjectIdentityImpl(type, identity);
}

From source file:com.cedac.security.oauth2.provider.approval.MongoApprovalStore.java

License:Apache License

@Override
public List<Approval> getApprovals(String userName, String clientId) {
    BasicDBObject query = new BasicDBObject(userIdFieldName, userName).append(clientIdFieldName, clientId);
    DBCursor cursor = null;/* w  w w. j  a  va 2s.com*/
    try {
        List<Approval> approvals = new ArrayList<Approval>();
        cursor = getApprovalsCollection().find(query);
        while (cursor.hasNext()) {
            DBObject dbo = cursor.next();
            approvals.add(new Approval((String) dbo.get(userIdFieldName), (String) dbo.get(clientIdFieldName),
                    (String) dbo.get(scopeFieldName), (Date) dbo.get(expiresAtFieldName),
                    Approval.ApprovalStatus.valueOf((String) dbo.get(statusFieldName)),
                    (Date) dbo.get(lastModifiedAtFieldName)));
        }
        return approvals;
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

From source file:com.cedac.security.oauth2.provider.client.MongoClientDetailsService.java

License:Apache License

@SuppressWarnings("unchecked")
private ClientDetails toClientDetails(DBObject dbo) {
    final String clientId = (String) dbo.get(clientIdFieldName);
    final String resourceIds = collectionToCommaDelimitedString((Collection) dbo.get(resourceIdsFieldName));
    final String scopes = collectionToCommaDelimitedString((Collection) dbo.get(scopeFieldName));
    final String grantTypes = collectionToCommaDelimitedString(
            (Collection) dbo.get(authorizedGrantTypesFieldName));
    final String authorities = collectionToCommaDelimitedString((Collection) dbo.get(authoritiesFieldName));
    final String redirectUris = collectionToCommaDelimitedString(
            (Collection) dbo.get(registeredRedirectUrisFieldName));
    BaseClientDetails clientDetails = new BaseClientDetails(clientId, resourceIds, scopes, grantTypes,
            authorities, redirectUris);//from   w w w .ja va  2 s .  c  om
    clientDetails.setClientSecret((String) dbo.get(clientSecretFieldName));
    clientDetails.setAccessTokenValiditySeconds((Integer) dbo.get(accessTokenValidityFieldName));
    clientDetails.setRefreshTokenValiditySeconds((Integer) dbo.get(refreshTokenValidityFieldName));
    Object autoApprove = dbo.get(autoApproveFieldName);
    if (autoApprove != null) {
        if (autoApprove instanceof String) {
            clientDetails.setAutoApproveScopes(Collections.singleton((String) autoApprove));
        } else {
            clientDetails.setAutoApproveScopes((Collection<String>) dbo.get(autoApproveFieldName));
        }
    }
    DBObject additionalInfo = (DBObject) dbo.get(additionalInformationFieldName);
    if (additionalInfo != null) {
        for (String key : additionalInfo.keySet()) {
            clientDetails.addAdditionalInformation(key, additionalInfo.get(key));
        }
    }
    return clientDetails;
}

From source file:com.cedac.security.oauth2.provider.code.MongoAuthorizationCodeServices.java

License:Apache License

public OAuth2Authentication remove(String code) {
    OAuth2Authentication authentication = null;

    DBObject query = new BasicDBObject(codeFieldName, code);
    DBObject authCode = getAuthCodeCollection().findOne(query);
    if (authCode != null) {
        authentication = SerializationUtils.deserialize((byte[]) authCode.get(authenticationFieldName));
        if (authentication != null) {
            getAuthCodeCollection().remove(authCode);
        }/*  w  w  w .  ja va 2s . co  m*/
    }

    return authentication;
}

From source file:com.cedac.security.oauth2.provider.token.store.MongoTokenStore.java

License:Apache License

public OAuth2AccessToken getAccessToken(OAuth2Authentication authentication) {
    OAuth2AccessToken accessToken = null;

    String key = authenticationKeyGenerator.extractKey(authentication);
    try {/* w ww .j av  a  2 s. c  om*/
        DBObject query = new BasicDBObject(authenticationIdFieldName, key);
        DBObject projection = new BasicDBObject(tokenFieldName, 1);
        DBObject token = getAccessTokenCollection().findOne(query, projection);
        if (token != null) {
            accessToken = deserializeAccessToken((byte[]) token.get(tokenFieldName));
        } else {
            LOG.debug("Failed to find access token for authentication {}", authentication);
        }
    } catch (IllegalArgumentException e) {
        LOG.error("Could not extract access token for authentication " + authentication, e);
    }

    if (accessToken != null
            && !key.equals(authenticationKeyGenerator.extractKey(readAuthentication(accessToken.getValue())))) {
        removeAccessToken(accessToken.getValue());
        // Keep the store consistent (maybe the same user is represented by this authentication but the details have
        // changed)
        storeAccessToken(accessToken, authentication);
    }
    return accessToken;
}