Search in sources :

Example 66 with RestartResponseException

use of org.apache.wicket.RestartResponseException in project midpoint by Evolveum.

the class PageEmailNonse method getMailNoncePolicy.

private NonceCredentialsPolicyType getMailNoncePolicy(PrismObject<UserType> user) {
    SecurityPolicyType securityPolicy = resolveSecurityPolicy(user);
    LOGGER.trace("Found security policy: {}", securityPolicy);
    if (securityPolicy == null) {
        getSession().error(getString("PageForgotPassword.send.nonce.failed"));
        LOGGER.error("No security policy, cannot process nonce credential");
        // we do not want to provide any information to the attacker.
        throw new RestartResponseException(PageEmailNonse.class);
    }
    if (securityPolicy.getCredentials() == null) {
        getSession().error(getString("PageForgotPassword.send.nonce.failed"));
        LOGGER.error("No credential for security policy, cannot process nonce credential");
        // we do not want to provide any information to the attacker.
        throw new RestartResponseException(PageEmailNonse.class);
    }
    if (securityPolicy.getCredentials().getNonce() == null) {
        getSession().error(getString("PageForgotPassword.send.nonce.failed"));
        LOGGER.error("No nonce credential for security policy, cannot process nonce credential");
        // we do not want to provide any information to the attacker.
        throw new RestartResponseException(PageEmailNonse.class);
    }
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    if (!(authentication instanceof MidpointAuthentication)) {
        getSession().error(getString("PageForgotPassword.send.nonce.failed"));
        LOGGER.error("Bad type of authentication, support only MidpointAuthentication, but is " + authentication != null ? authentication.getClass().getName() : null);
        throw new RestartResponseException(PageEmailNonse.class);
    }
    ModuleAuthentication moduleAuthentication = ((MidpointAuthentication) authentication).getProcessingModuleAuthentication();
    if (!(moduleAuthentication instanceof CredentialModuleAuthentication) && !AuthenticationModuleNameConstants.MAIL_NONCE.equals(moduleAuthentication.getNameOfModuleType())) {
        getSession().error(getString("PageForgotPassword.send.nonce.failed"));
        LOGGER.error("Bad type of module authentication, support only EmailNonceModuleAuthentication, but is " + moduleAuthentication != null ? moduleAuthentication.getClass().getName() : null);
        throw new RestartResponseException(PageEmailNonse.class);
    }
    CredentialModuleAuthentication nonceAuth = (CredentialModuleAuthentication) moduleAuthentication;
    String credentialName = nonceAuth.getCredentialName();
    if (credentialName == null) {
        getSession().error(getString("PageForgotPassword.send.nonce.failed"));
        LOGGER.error("EmailNonceModuleAuthentication " + nonceAuth.getNameOfModule() + " haven't define name of credential");
        throw new RestartResponseException(PageEmailNonse.class);
    }
    NonceCredentialsPolicyType credentialByName = null;
    for (NonceCredentialsPolicyType credential : securityPolicy.getCredentials().getNonce()) {
        if (credentialName != null && credentialName.equals(credential.getName())) {
            credentialByName = credential;
        }
    }
    if (credentialByName == null) {
        getSession().error(getString("PageForgotPassword.send.nonce.failed"));
        LOGGER.error("Couldn't find nonce credentials by name " + credentialName);
        throw new RestartResponseException(PageEmailNonse.class);
    }
    return credentialByName;
}
Also used : CredentialModuleAuthentication(com.evolveum.midpoint.authentication.api.config.CredentialModuleAuthentication) CredentialModuleAuthentication(com.evolveum.midpoint.authentication.api.config.CredentialModuleAuthentication) ModuleAuthentication(com.evolveum.midpoint.authentication.api.config.ModuleAuthentication) RestartResponseException(org.apache.wicket.RestartResponseException) CredentialModuleAuthentication(com.evolveum.midpoint.authentication.api.config.CredentialModuleAuthentication) ModuleAuthentication(com.evolveum.midpoint.authentication.api.config.ModuleAuthentication) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication) Authentication(org.springframework.security.core.Authentication) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)

Example 67 with RestartResponseException

use of org.apache.wicket.RestartResponseException in project midpoint by Evolveum.

the class PageForgotPassword method createDynamicFormQuery.

private ObjectQuery createDynamicFormQuery(Form form) {
    DynamicFormPanel<UserType> userDynamicPanel = (DynamicFormPanel<UserType>) form.get(createComponentPath(ID_DYNAMIC_LAYOUT, ID_DYNAMIC_FORM));
    List<ItemPath> filledItems = userDynamicPanel.getChangedItems();
    PrismObject<UserType> user;
    try {
        user = userDynamicPanel.getObject();
    } catch (SchemaException e1) {
        getSession().error(getString("pageForgetPassword.message.usernotfound"));
        throw new RestartResponseException(PageForgotPassword.class);
    }
    List<EqualFilter> filters = new ArrayList<>();
    QueryFactory queryFactory = getPrismContext().queryFactory();
    for (ItemPath path : filledItems) {
        PrismProperty<?> property = user.findProperty(path);
        EqualFilter filter = queryFactory.createEqual(path, property.getDefinition(), null);
        filter.setValue(property.getAnyValue().clone());
        filters.add(filter);
    }
    return queryFactory.createQuery(queryFactory.createAnd((List) filters));
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QueryFactory(com.evolveum.midpoint.prism.query.QueryFactory) ArrayList(java.util.ArrayList) DynamicFormPanel(com.evolveum.midpoint.web.component.prism.DynamicFormPanel) RestartResponseException(org.apache.wicket.RestartResponseException) EqualFilter(com.evolveum.midpoint.prism.query.EqualFilter) List(java.util.List) ArrayList(java.util.ArrayList) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 68 with RestartResponseException

use of org.apache.wicket.RestartResponseException in project midpoint by Evolveum.

the class OrgTreeProvider method size.

public long size(TreeSelectableBean<OrgType> node) {
    Task task = getPageBase().createSimpleTask(LOAD_ORG_UNITS);
    OperationResult result = task.getResult();
    String nodeOid = null;
    if (node != null) {
        nodeOid = node.getValue().getOid();
    } else {
        nodeOid = rootOid.getObject();
    }
    Integer orgs = null;
    try {
        ObjectQuery query = getPageBase().getPrismContext().queryFor(OrgType.class).isDirectChildOf(nodeOid).build();
        orgs = getModelService().countObjects(OrgType.class, query, null, task, result);
        LOGGER.debug("Found {} sub-orgs.", orgs);
    } catch (CommonException | RuntimeException ex) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load children", ex);
        result.recordFatalError(getPageBase().createStringResource("OrgTreeProvider.message.getChildren.fatalError").getString(), ex);
    } finally {
        result.computeStatus();
    }
    if (WebComponentUtil.showResultInPage(result)) {
        getPageBase().showResult(result);
        throw new RestartResponseException(PageOrgTree.class);
    }
    return orgs == null ? 0 : orgs.longValue();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) RestartResponseException(org.apache.wicket.RestartResponseException) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CommonException(com.evolveum.midpoint.util.exception.CommonException)

Example 69 with RestartResponseException

use of org.apache.wicket.RestartResponseException in project midpoint by Evolveum.

the class OrgTreeProvider method getChildren.

@Override
public Iterator<? extends TreeSelectableBean<OrgType>> getChildren(TreeSelectableBean<OrgType> node) {
    LOGGER.debug("Getting children for {}", node.getValue());
    String nodeOid = node.getValue().getOid();
    List<TreeSelectableBean<OrgType>> children;
    long currentTime = System.currentTimeMillis();
    if (currentTime > lastFetchOperation + EXPIRATION_AFTER_LAST_FETCH_OPERATION) {
        childrenCache.clear();
    }
    if (childrenCache.containsKey(nodeOid)) {
        LOGGER.debug("Using cached children for {}", node.getValue());
        children = childrenCache.get(nodeOid);
    } else {
        LOGGER.debug("Loading fresh children for {}", node.getValue());
        OperationResult result = new OperationResult(LOAD_ORG_UNITS);
        try {
            ObjectQuery query = getPageBase().getPrismContext().queryFor(OrgType.class).isDirectChildOf(nodeOid).build();
            ObjectFilter customFilter = getCustomFilter();
            if (customFilter != null) {
                query.addFilter(customFilter);
            }
            Task task = getPageBase().createSimpleTask(LOAD_ORG_UNITS);
            ObjectPaging paging = createPaging(node);
            query.setPaging(paging);
            List<PrismObject<OrgType>> orgs = getModelService().searchObjects(OrgType.class, query, null, task, result);
            LOGGER.debug("Found {} sub-orgs.", orgs.size());
            children = new ArrayList<>();
            for (PrismObject<OrgType> org : orgs) {
                children.add(createObjectWrapper(node, org));
            }
            childrenCache.put(nodeOid, children);
        } catch (CommonException | RuntimeException ex) {
            LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load children", ex);
            result.recordFatalError(getPageBase().createStringResource("OrgTreeProvider.message.getChildren.fatalError").getString(), ex);
            children = new ArrayList<>();
        } finally {
            result.computeStatus();
        }
        if (WebComponentUtil.showResultInPage(result)) {
            getPageBase().showResult(result);
            throw new RestartResponseException(PageOrgTree.class);
        }
        children.forEach(orgUnit -> {
            getAvailableData().putIfAbsent(orgUnit.getValue().getOid(), orgUnit);
        });
    }
    LOGGER.debug("Finished getting children.");
    lastFetchOperation = System.currentTimeMillis();
    return children.iterator();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismObject(com.evolveum.midpoint.prism.PrismObject) RestartResponseException(org.apache.wicket.RestartResponseException) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) TreeSelectableBean(com.evolveum.midpoint.web.component.util.TreeSelectableBean) CommonException(com.evolveum.midpoint.util.exception.CommonException)

Example 70 with RestartResponseException

use of org.apache.wicket.RestartResponseException in project midpoint by Evolveum.

the class PageAdminObjectDetails method createObjectWrapper.

private PrismObjectWrapper<O> createObjectWrapper(PrismObject<O> object, boolean isReadonly, Task task, OperationResult result) {
    ItemStatus itemStatus = computeWrapperStatus();
    PrismObjectWrapperFactory<O> factory = getRegistry().getObjectWrapperFactory(object.getDefinition());
    WrapperContext context = new WrapperContext(task, result);
    context.setCreateIfEmpty(ItemStatus.ADDED == itemStatus);
    context.setDetailsPageTypeConfiguration(getDetailsPanelsConfiguration(object));
    // Boolean instead of boolean isReadonly
    if (isReadonly) {
        context.setReadOnly(isReadonly);
    }
    try {
        PrismObjectWrapper<O> wrapper = factory.createObjectWrapper(object, itemStatus, context);
        result.recordSuccess();
        return wrapper;
    } catch (Exception ex) {
        result.recordFatalError(getString("PageAdminObjectDetails.message.loadObjectWrapper.fatalError"), ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load object", ex);
        showResult(result, false);
        throw new RestartResponseException(getRestartResponsePage());
    }
}
Also used : ItemStatus(com.evolveum.midpoint.gui.api.prism.ItemStatus) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) RestartResponseException(org.apache.wicket.RestartResponseException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) AuthorizationException(com.evolveum.midpoint.util.exception.AuthorizationException) RestartResponseException(org.apache.wicket.RestartResponseException)

Aggregations

RestartResponseException (org.apache.wicket.RestartResponseException)73 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)36 Task (com.evolveum.midpoint.task.api.Task)27 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)20 ArrayList (java.util.ArrayList)10 PrismObject (com.evolveum.midpoint.prism.PrismObject)8 CommonException (com.evolveum.midpoint.util.exception.CommonException)8 SecurityPolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityPolicyType)8 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)6 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)6 WrapperContext (com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext)5 PageBase (com.evolveum.midpoint.gui.api.page.PageBase)5 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)5 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)5 PageError (com.evolveum.midpoint.web.page.error.PageError)5 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)4 Collection (java.util.Collection)4 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)4 IModel (org.apache.wicket.model.IModel)4 StringValue (org.apache.wicket.util.string.StringValue)4