use of com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType in project midpoint by Evolveum.
the class ChangePasswordPanel method initLayout.
private void initLayout(final boolean oldPasswordVisible) {
model = (LoadableModel<MyPasswordsDto>) getModel();
Label oldPasswordLabel = new Label(ID_OLD_PASSWORD_LABEL, createStringResource("PageSelfCredentials.oldPasswordLabel"));
add(oldPasswordLabel);
oldPasswordLabel.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible() {
return oldPasswordVisible;
}
});
Label passwordLabel = new Label(ID_PASSWORD_LABEL, createStringResource("PageSelfCredentials.passwordLabel1"));
add(passwordLabel);
PasswordTextField oldPasswordField = new PasswordTextField(ID_OLD_PASSWORD_FIELD, new PropertyModel<String>(model, MyPasswordsDto.F_OLD_PASSWORD));
oldPasswordField.setRequired(false);
oldPasswordField.setResetPassword(false);
add(oldPasswordField);
oldPasswordField.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
public boolean isVisible() {
return oldPasswordVisible;
}
;
});
PasswordPanel passwordPanel = new PasswordPanel(ID_PASSWORD_PANEL, new PropertyModel<ProtectedStringType>(model, MyPasswordsDto.F_PASSWORD));
passwordPanel.getBaseFormComponent().add(new AttributeModifier("autofocus", ""));
add(passwordPanel);
WebMarkupContainer accountContainer = new WebMarkupContainer(ID_ACCOUNTS_CONTAINER);
List<IColumn<PasswordAccountDto, String>> columns = initColumns();
ListDataProvider<PasswordAccountDto> provider = new ListDataProvider<PasswordAccountDto>(this, new PropertyModel<List<PasswordAccountDto>>(model, MyPasswordsDto.F_ACCOUNTS));
TablePanel accounts = new TablePanel(ID_ACCOUNTS_TABLE, provider, columns);
accounts.setItemsPerPage(30);
accounts.setShowPaging(false);
if (model.getObject().getPropagation() != null && model.getObject().getPropagation().equals(CredentialsPropagationUserControlType.MAPPING)) {
accountContainer.setVisible(false);
}
accountContainer.add(accounts);
AjaxLink help = new AjaxLink(ID_BUTTON_HELP) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
showHelpPerformed(target);
}
};
accountContainer.add(help);
add(accountContainer);
}
use of com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType in project midpoint by Evolveum.
the class PageAbstractSelfCredentials method setEncryptedPasswordData.
protected void setEncryptedPasswordData(EncryptedDataType data) {
MyPasswordsDto dto = model.getObject();
ProtectedStringType password = dto.getPassword();
if (password != null) {
password.setEncryptedData(data);
}
}
use of com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType in project midpoint by Evolveum.
the class PageAccountActivation method propagatePassword.
private void propagatePassword(AjaxRequestTarget target, Form<?> form) {
List<ShadowType> shadowsToActivate = getShadowsToActivate();
PasswordTextField passwordPanel = (PasswordTextField) form.get(createComponentPath(ID_PASSWORD));
String value = passwordPanel.getModelObject();
ConnectionEnvironment connEnv = ConnectionEnvironment.create(SchemaConstants.CHANNEL_GUI_USER_URI);
UsernamePasswordAuthenticationToken token;
try {
token = authenticationEvaluator.authenticate(connEnv, new PasswordAuthenticationContext(userModel.getObject().getName().getOrig(), value));
} catch (Exception ex) {
LOGGER.error("Failed to authenticate user, reason ", ex.getMessage());
getSession().error(getString("PageAccountActivation.authentication.failed"));
throw new RestartResponseException(PageAccountActivation.class, getPageParameters());
}
if (token == null) {
LOGGER.error("Failed to authenticate user");
getSession().error(getString("PageAccountActivation.authentication.failed"));
throw new RestartResponseException(PageAccountActivation.class, getPageParameters());
}
ProtectedStringType passwordValue = new ProtectedStringType();
passwordValue.setClearValue(value);
Collection<ObjectDelta<ShadowType>> passwordDeltas = new ArrayList<>(shadowsToActivate.size());
for (ShadowType shadow : shadowsToActivate) {
ObjectDelta<ShadowType> shadowDelta = ObjectDelta.createModificationReplaceProperty(ShadowType.class, shadow.getOid(), SchemaConstants.PATH_PASSWORD_VALUE, getPrismContext(), passwordValue);
shadowDelta.addModificationReplaceProperty(ShadowType.F_LIFECYCLE_STATE, SchemaConstants.LIFECYCLE_PROPOSED);
passwordDeltas.add(shadowDelta);
}
OperationResult result = runPrivileged(new Producer<OperationResult>() {
@Override
public OperationResult run() {
OperationResult result = new OperationResult(OPERATION_ACTIVATE_SHADOWS);
Task task = createAnonymousTask(OPERATION_ACTIVATE_SHADOWS);
WebModelServiceUtils.save((Collection) passwordDeltas, null, result, task, PageAccountActivation.this);
return result;
}
});
result.recomputeStatus();
if (!result.isSuccess()) {
getSession().error(getString("PageAccountActivation.account.activation.failed"));
LOGGER.error("Failed to acitvate accounts, reason: {} ", result.getMessage());
target.add(getFeedbackPanel());
} else {
getSession().success(getString("PageAccountActivation.account.activation.successful"));
target.add(getFeedbackPanel());
activated = true;
}
target.add(PageAccountActivation.this);
}
use of com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType in project midpoint by Evolveum.
the class ModelInteractionServiceImpl method collectDeltasForGeneratedValuesIfNeeded.
private <O extends ObjectType> void collectDeltasForGeneratedValuesIfNeeded(PrismObject<O> object, PolicyItemDefinitionType policyItemDefinition, Collection<PropertyDelta<?>> deltasToExecute, ItemPath path, PrismPropertyDefinition<?> itemDef) throws SchemaException {
Object value = policyItemDefinition.getValue();
if (ProtectedStringType.COMPLEX_TYPE.equals(itemDef.getTypeName())) {
ProtectedStringType pst = new ProtectedStringType();
pst.setClearValue((String) value);
value = pst;
} else if (PolyStringType.COMPLEX_TYPE.equals(itemDef.getTypeName())) {
value = new PolyString((String) value);
}
PropertyDelta<?> propertyDelta = PropertyDelta.createModificationReplaceProperty(path, object.getDefinition(), value);
// in bulk actions we need to modify original objects - hope that REST is OK with this
propertyDelta.applyTo(object);
if (BooleanUtils.isTrue(policyItemDefinition.isExecute())) {
deltasToExecute.add(propertyDelta);
}
}
use of com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType in project midpoint by Evolveum.
the class ModelInteractionServiceImpl method validateValue.
private <T, O extends ObjectType> boolean validateValue(PrismObject<O> object, ValuePolicyType policy, PolicyItemDefinitionType policyItemDefinition, Task task, OperationResult parentResult) throws ExpressionEvaluationException, SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, PolicyViolationException {
ValuePolicyType stringPolicy = resolveValuePolicy(policyItemDefinition, policy, task, parentResult);
RawType rawValue = (RawType) policyItemDefinition.getValue();
String valueToValidate = null;
List<String> valuesToValidate = new ArrayList<>();
PolicyItemTargetType target = policyItemDefinition.getTarget();
ItemPath path = null;
if (target != null) {
path = target.getPath().getItemPath();
}
if (rawValue != null) {
valueToValidate = rawValue.getParsedRealValue(String.class);
valuesToValidate.add(valueToValidate);
} else {
if (target == null || target.getPath() == null) {
LOGGER.error("Target item path must be defined");
parentResult.recordFatalError("Target item path must be defined");
throw new SchemaException("Target item path must be defined");
}
path = target.getPath().getItemPath();
PrismProperty<T> property = object.findProperty(path);
if (property == null || property.isEmpty()) {
LOGGER.error("Attribute {} has no value. Nothing to validate.", property);
parentResult.recordFatalError("Attribute " + property + " has no value. Nothing to validate");
throw new SchemaException("Attribute " + property + " has no value. Nothing to validate");
}
PrismPropertyDefinition<T> itemToValidateDefinition = property.getDefinition();
QName definitionName = itemToValidateDefinition.getTypeName();
if (!isSupportedType(definitionName)) {
LOGGER.error("Trying to validate string policy on the property of type {} failed. Unsupported type.", itemToValidateDefinition);
parentResult.recordFatalError("Trying to validate string policy on the property of type " + itemToValidateDefinition + " failed. Unsupported type.");
throw new SchemaException("Trying to validate string policy on the property of type " + itemToValidateDefinition + " failed. Unsupported type.");
}
if (itemToValidateDefinition.isSingleValue()) {
if (definitionName.equals(PolyStringType.COMPLEX_TYPE)) {
valueToValidate = ((PolyString) property.getRealValue()).getOrig();
} else if (definitionName.equals(ProtectedStringType.COMPLEX_TYPE)) {
ProtectedStringType protectedString = ((ProtectedStringType) property.getRealValue());
valueToValidate = getClearValue(protectedString);
} else {
valueToValidate = (String) property.getRealValue();
}
valuesToValidate.add(valueToValidate);
} else {
if (definitionName.equals(DOMUtil.XSD_STRING)) {
valuesToValidate.addAll(property.getRealValues(String.class));
} else if (definitionName.equals(ProtectedStringType.COMPLEX_TYPE)) {
for (ProtectedStringType protectedString : property.getRealValues(ProtectedStringType.class)) {
valuesToValidate.add(getClearValue(protectedString));
}
} else {
for (PolyString val : property.getRealValues(PolyString.class)) {
valuesToValidate.add(val.getOrig());
}
}
}
}
for (String newValue : valuesToValidate) {
OperationResult result = parentResult.createSubresult(OPERATION_VALIDATE_VALUE + ".value");
if (path != null)
result.addParam("path", path);
result.addParam("valueToValidate", newValue);
if (!policyProcessor.validateValue(newValue, stringPolicy, object, "validate value " + (path != null ? "for " + path : "") + " for " + object + " value " + valueToValidate, task, result)) {
result.recordFatalError("Validation for value " + newValue + " against policy " + stringPolicy + " failed");
LOGGER.error("Validation for value {} against policy {} failed", newValue, stringPolicy);
}
result.computeStatusIfUnknown();
}
parentResult.computeStatus();
policyItemDefinition.setResult(parentResult.createOperationResultType());
return parentResult.isAcceptable();
}
Aggregations