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;
}
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));
}
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();
}
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();
}
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());
}
}
Aggregations