Find by principal name.
@param principal name to search for
@return records for given principal
356257
@View(name = "by_principal",
        map = "function(doc) { if (doc.principal && doc.deviceFingerprint && doc.recordDate) { emit(doc.principal, doc) } }")
    public List<CouchDbMultifactorAuthenticationTrustRecord> findByPrincipal(final String principal) {
        val view = createQuery("by_principal").key(principal);
        return db.queryView(view, CouchDbMultifactorAuthenticationTrustRecord.class);
    }
1305723
@Transactional
    public List<E> find(E entity, SearchParameters sp) {
        if (sp.hasNamedQuery()) {
            return byNamedQueryUtil.findByNamedQuery(sp);
        }
        CriteriaBuilder builder = entityManager.getCriteriaBuilder();
        CriteriaQuery<E> criteriaQuery = builder.createQuery(type);
        if (sp.getDistinct()) {
            criteriaQuery.distinct(true);
        }
        Root<E> root = criteriaQuery.from(type);

        // predicate
        Predicate predicate = getPredicate(criteriaQuery, root, builder, entity, sp);
        if (predicate != null) {
            criteriaQuery = criteriaQuery.where(predicate);
        }

        // fetches
        fetches(sp, root);

        // order by
        criteriaQuery.orderBy(orderByUtil.buildJpaOrders(sp.getOrders(), root, builder, sp));

        TypedQuery<E> typedQuery = entityManager.createQuery(criteriaQuery);
        applyCacheHints(typedQuery, sp);
        jpaUtil.applyPagination(typedQuery, sp);
        List<E> entities = typedQuery.getResultList();
        log.fine("Returned " + entities.size() + " elements");

        return entities;
    }
795215
@Override
	public PrincipalUser getUser(String username, String password) {
		requireNotDisposed();

		PrincipalUser result = _userService.findUserByUsername(username);
		String isPrivileged= _config.getValue(Property.IS_PRIVILEGED.getName(), Property.IS_PRIVILEGED.getDefaultValue());

		if(result == null){
			result = new PrincipalUser(_userService.findAdminUser(), username, username+"@gmail.com");
		}
                DAILY_USERS.put(username, System.currentTimeMillis());
                MONTHLY_USERS.put(username, System.currentTimeMillis());
                _monitorService.updateCounter(MonitorService.Counter.DAILY_USERS, DAILY_USERS.size(), new HashMap<>(0));
                _monitorService.updateCounter(MonitorService.Counter.MONTHLY_USERS, MONTHLY_USERS.size(), new HashMap<>(0));
		_monitorService.updateCounter(MonitorService.Counter.UNIQUE_USERS, _userService.getUniqueUserCount(), new HashMap<String, String>(0));

		try{
			Method method = PrincipalUser.class.getDeclaredMethod("setPrivileged", boolean.class);
			method.setAccessible(true);
			method.invoke(result, Boolean.parseBoolean(isPrivileged));

		} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
			throw new SystemException("Failed to change privileged status.", e);
		}

		result = _userService.updateUser(result);
		return result;
	}
659312
public Record getMainRecord()
    {
        Record record = null;
        if (m_vRecordList != null)
            record = m_vRecordList.getMainRecord();
        if (record == null)
            if (m_taskParent instanceof RecordOwner)
                record = (Record)((RecordOwner)m_taskParent).getMainRecord(); // Look thru the parent window now
        return record;
    }
383973
@Override
	public SQLProperty findPropertyByName(String name) {
		name = name.toLowerCase();
		for (SQLProperty item : properties) {
			if (item.getName().toLowerCase().equals(name)) {
				return item;
			}
		}

		return null;
	}
355918
@JsonIgnore
    protected Map<String, List<Object>> getCachedPrincipalAttributes(final Principal principal, final RegisteredService registeredService) {
        try {
            val cache = getCacheInstanceFromApplicationContext();
            return cache.getCachedAttributesFor(registeredService, this, principal);
        } catch (final Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
        return new HashMap<>(0);
    }
1283710
public I_CmsPrincipal lookupPrincipal(CmsRequestContext context, CmsUUID principalId) {

        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
        I_CmsPrincipal result = null;
        try {
            result = m_driverManager.lookupPrincipal(dbc, principalId);
        } finally {
            dbc.clear();
        }
        return result;
    }
367822
@View(name = "by_surrogate_principal", map = "function(doc) { if(doc.surrogate && doc.principal) { emit([doc.principal, doc.surrogate], doc) } }")
    public List<CouchDbSurrogateAuthorization> findBySurrogatePrincipal(final String surrogate, final String principal) {
        return queryView("by_surrogate_principal", ComplexKey.of(principal, surrogate));
    }
146869
public static Collection<SimplePrincipalProvider> getSimplePrincipals(
            Collection<PrincipalProvider<?>> principalProviders) {
        Collection<SimplePrincipalProvider> principals = new ArrayList<>();
        for (PrincipalProvider<?> principal : principalProviders) {
            if (principal instanceof SimplePrincipalProvider) {
                principals.add((SimplePrincipalProvider) principal);
            }
        }
        return principals;
    }
1121678
@View(name = "by_type_for_principal_id_since", map = "function(doc) { emit([doc.type, doc.principal, doc.creationTime], doc) }")
    public Collection<CouchDbCasEvent> findByTypeForPrincipalSince(final String type, final String principalId, final LocalDateTime localDeateTime) {
        val view = createQuery("by_type_for_principal_id_since").startKey(ComplexKey.of(type, principalId, localDeateTime))
            .endKey(ComplexKey.of(type, principalId, LocalDateTime.now()));
        return db.queryView(view, CouchDbCasEvent.class);
    }
711304
@Programmatic
    public ApplicationRole findByNameCached(final String name) {
        return queryResultsCache.execute(new Callable<ApplicationRole>() {
            @Override public ApplicationRole call() throws Exception {
                return findByName(name);
            }
        }, ApplicationRoleRepository.class, "findByNameCached", name);
    }
889405
public Record getMainRecord()
    {
        Record record = m_vRecordList.getMainRecord();
        if (record == null)
            record = super.getMainRecord();   // Look thru the parent window now
        return record;
    }
1315954
@Override
    public List<String> getRoles(String name, String... domain) {
        if (domain.length == 1) {
            name = domain[0] + "::" + name;
        } else if (domain.length > 1) {
            throw new Error("error: domain should be 1 parameter");
        }

        if (!hasRole(name)) {
            throw new Error("error: name does not exist");
        }

        List<String> roles = createRole(name).getRoles();
        if (domain.length == 1) {
            for (int i = 0; i < roles.size(); i ++) {
                roles.set(i, roles.get(i).substring(domain[0].length() + 2, roles.get(i).length()));
            }
        }
        return roles;
    }
799977
@Nullable
    public static List<String> resolveARecord(String rootDomainName) {
        if (isLocalOrIp(rootDomainName)) {
            return null;
        }
        try {
            Attributes attrs = getDirContext().getAttributes(rootDomainName, new String[]{A_RECORD_TYPE, CNAME_RECORD_TYPE});
            Attribute aRecord = attrs.get(A_RECORD_TYPE);
            Attribute cRecord = attrs.get(CNAME_RECORD_TYPE);
            if (aRecord != null && cRecord == null) {
                List<String> result = new ArrayList<>();
                NamingEnumeration<String> entries = (NamingEnumeration<String>) aRecord.getAll();
                while (entries.hasMore()) {
                    result.add(entries.next());
                }
                return result;
            }
        } catch (Exception e) {
            logger.warn("Cannot load A-record for eureka server address {}", rootDomainName, e);
            return null;
        }
        return null;
    }
821349
@ReadOperation
    public List<ConfigurationMetadataSearchResult> search(@Selector final String name) {
        val allProps = repository.getRepository().getAllProperties();

        if (StringUtils.isNotBlank(name) && RegexUtils.isValidRegex(name)) {
            val names = StreamSupport.stream(RelaxedPropertyNames.forCamelCase(name).spliterator(), false)
                .map(Object::toString)
                .collect(Collectors.joining("|"));
            val pattern = RegexUtils.createPattern(names);
            return allProps.entrySet()
                .stream()
                .filter(propEntry -> RegexUtils.find(pattern, propEntry.getKey()))
                .map(propEntry -> new ConfigurationMetadataSearchResult(propEntry.getValue(), repository))
                .sorted()
                .collect(Collectors.toList());
        }
        return new ArrayList<>();
    }
176573
public Touple<SQLProperty, String, SQLiteEntity, SQLRelationType> findRelationByParentProperty(
			String parentFieldName) {
		for (Touple<SQLProperty, String, SQLiteEntity, SQLRelationType> item : relations) {
			if (item.value0.getName().equals(parentFieldName)) {
				return item;
			}
		}

		return null;
	}
1160774
@JsonIgnore
    protected Map<String, List<Object>> getPrincipalAttributes(final Principal principal) {
        if (ignoreResolvedAttributes) {
            return new HashMap<>(0);
        }
        return convertPrincipalAttributesToPersonAttributes(principal.getAttributes());
    }