protected String getActualKey(final AnyDAO<?> dao, final String pretendingKey) { String actualKey = pretendingKey; if (!SyncopeConstants.UUID_PATTERN.matcher(pretendingKey).matches()) { actualKey = dao.findKey(pretendingKey); if (actualKey == null) { throw new NotFoundException("User, Group or Any Object for " + pretendingKey); } } return actualKey; }
@PreAuthorize("isAuthenticated()") public String schema(final String schema) { synchronized (MONITOR) { if (SCHEMAS == null) { init(); } } String found = SCHEMA_MAP.get(schema); if (found == null) { throw new NotFoundException("Schema " + schema + " not found"); } return found; }
@PreAuthorize("hasRole('" + StandardEntitlement.LOG_READ + "') and authentication.details.domain == " + "T(org.apache.syncope.common.lib.SyncopeConstants).MASTER_DOMAIN") @Transactional(readOnly = true) public LoggerTO readLog(final String name) { return listLogs().stream(). filter(logger -> logger.getKey().equals(name)).findFirst(). orElseThrow(() -> new NotFoundException("Logger " + name)); }
@PreAuthorize("hasRole('" + StandardEntitlement.CONNECTOR_HISTORY_LIST + "')") @Transactional(readOnly = true) public List<ConnInstanceHistoryConfTO> list(final String key) { ConnInstance connInstance = connInstanceDAO.find(key); if (connInstance == null) { throw new NotFoundException("Connector '" + key + "'"); } return connInstanceHistoryConfDAO.findByEntity(connInstance).stream(). map(binder::getConnInstanceHistoryConfTO).collect(Collectors.toList()); }
@PreAuthorize("hasRole('" + StandardEntitlement.REMEDIATION_READ + "')") @Transactional(readOnly = true) public RemediationTO read(final String key) { Remediation remediation = remediationDAO.find(key); if (remediation == null) { LOG.error("Could not find remediation '" + key + "'"); throw new NotFoundException(key); } return binder.getRemediationTO(remediation); }
@PreAuthorize("hasRole('" + StandardEntitlement.REPORT_TEMPLATE_READ + "')") @Transactional(readOnly = true) public ReportTemplateTO read(final String key) { ReportTemplate reportTemplate = reportTemplateDAO.find(key); if (reportTemplate == null) { LOG.error("Could not find report template '" + key + "'"); throw new NotFoundException(key); } return getReportTemplateTO(key); }
@PreAuthorize("hasRole('" + StandardEntitlement.DYNREALM_READ + "')") @Transactional(readOnly = true) public DynRealmTO read(final String key) { DynRealm dynRealm = dynRealmDAO.find(key); if (dynRealm == null) { LOG.error("Could not find dynamic realm '" + key + "'"); throw new NotFoundException(key); } return binder.getDynRealmTO(dynRealm); }
@PreAuthorize("hasRole('" + StandardEntitlement.ANYTYPE_READ + "')") @Transactional(readOnly = true) public AnyTypeTO read(final String key) { AnyType anyType = anyTypeDAO.find(key); if (anyType == null) { LOG.error("Could not find anyType '" + key + "'"); throw new NotFoundException(key); } return binder.getAnyTypeTO(anyType); }
@PreAuthorize("hasRole('" + StandardEntitlement.ROLE_READ + "')") @Transactional(readOnly = true) public RoleTO read(final String key) { Role role = roleDAO.find(key); if (role == null) { LOG.error("Could not find role '" + key + "'"); throw new NotFoundException(key); } return binder.getRoleTO(role); }
@PreAuthorize("hasRole('" + StandardEntitlement.DOMAIN_READ + "') and authentication.details.domain == " + "T(org.apache.syncope.common.lib.SyncopeConstants).MASTER_DOMAIN") @Transactional(readOnly = true) public DomainTO read(final String key) { Domain domain = domainDAO.find(key); if (domain == null) { LOG.error("Could not find domain '" + key + "'"); throw new NotFoundException(key); } return binder.getDomainTO(domain); }
@PreAuthorize("hasRole('" + StandardEntitlement.RELATIONSHIPTYPE_READ + "')") @Transactional(readOnly = true) public RelationshipTypeTO read(final String key) { RelationshipType relationshipType = relationshipTypeDAO.find(key); if (relationshipType == null) { LOG.error("Could not find relationshipType '" + key + "'"); throw new NotFoundException(key); } return binder.getRelationshipTypeTO(relationshipType); }
@PreAuthorize("hasRole('" + StandardEntitlement.RESOURCE_READ + "')") @Transactional(readOnly = true) public ResourceTO read(final String key) { ExternalResource resource = resourceDAO.authFind(key); if (resource == null) { throw new NotFoundException("Resource '" + key + "'"); } return binder.getResourceTO(resource); }
@PreAuthorize("isAuthenticated()") @Transactional(readOnly = true) public List<RealmTO> list(final String fullPath) { Realm realm = realmDAO.findByFullPath(fullPath); if (realm == null) { LOG.error("Could not find realm '" + fullPath + "'"); throw new NotFoundException(fullPath); } final boolean admin = AuthContextUtils.getAuthorizations().keySet().contains(StandardEntitlement.REALM_LIST); return realmDAO.findDescendants(realm).stream(). map(descendant -> binder.getRealmTO(descendant, admin)).collect(Collectors.toList()); }
@PreAuthorize("hasRole('" + StandardEntitlement.REMEDIATION_DELETE + "')") public void delete(final String key) { Remediation remediation = remediationDAO.find(key); if (remediation == null) { LOG.error("Could not find remediation '" + key + "'"); throw new NotFoundException(key); } remediationDAO.delete(remediation); }
@PreAuthorize("hasRole('" + StandardEntitlement.RESOURCE_HISTORY_DELETE + "')") public void delete(final String key) { ExternalResourceHistoryConf resourceHistoryConf = resourceHistoryConfDAO.find(key); if (resourceHistoryConf == null) { throw new NotFoundException("Resource History Conf '" + key + "'"); } resourceHistoryConfDAO.delete(key); }
@PreAuthorize("hasRole('" + StandardEntitlement.CONNECTOR_READ + "')") @Transactional(readOnly = true) public ConnInstanceTO read(final String key, final String lang) { CurrentLocale.set(StringUtils.isBlank(lang) ? Locale.ENGLISH : new Locale(lang)); ConnInstance connInstance = connInstanceDAO.authFind(key); if (connInstance == null) { throw new NotFoundException("Connector '" + key + "'"); } return binder.getConnInstanceTO(connInstance); }
@PreAuthorize("hasRole('" + StandardEntitlement.TASK_READ + "')") @Override public Pair<Integer, List<ExecTO>> listExecutions( final String key, final int page, final int size, final List<OrderByClause> orderByClauses) { Task task = taskDAO.find(key); if (task == null) { throw new NotFoundException("Task " + key); } Integer count = taskExecDAO.count(key); List<ExecTO> result = taskExecDAO.findAll(task, page, size, orderByClauses).stream(). map(taskExec -> binder.getExecTO(taskExec)).collect(Collectors.toList()); return Pair.of(count, result); }
@PreAuthorize("hasRole('" + StandardEntitlement.SECURITY_QUESTION_DELETE + "')") public SecurityQuestionTO delete(final String key) { SecurityQuestion securityQuestion = securityQuestionDAO.find(key); if (securityQuestion == null) { LOG.error("Could not find security question '" + key + "'"); throw new NotFoundException(key); } SecurityQuestionTO deleted = binder.getSecurityQuestionTO(securityQuestion); securityQuestionDAO.delete(key); return deleted; }
@PreAuthorize("isAnonymous() or hasRole('" + StandardEntitlement.ANONYMOUS + "')") @Transactional public void confirmPasswordReset(final String token, final String password) { User user = userDAO.findByToken(token); if (user == null) { throw new NotFoundException("User with token " + token); } provisioningManager.confirmPasswordReset(user.getKey(), token, password); }
@PreAuthorize("hasRole('" + StandardEntitlement.AUDIT_READ + "')") @Transactional(readOnly = true) public LoggerTO readAudit(final String name) { return listAudits().stream(). filter(logger -> logger.toLoggerName().equals(name)).findFirst(). map(logger -> { LoggerTO loggerTO = new LoggerTO(); loggerTO.setKey(logger.toLoggerName()); loggerTO.setLevel(LoggerLevel.DEBUG); return loggerTO; }).orElseThrow(() -> new NotFoundException("Audit " + name)); }