Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Nov 2, 2017
2 parents bd28f69 + 36d5c00 commit 5eb5406
Show file tree
Hide file tree
Showing 69 changed files with 1,819 additions and 353 deletions.
Expand Up @@ -30,8 +30,6 @@
import org.springframework.security.ldap.search.FilterBasedLdapUserSearch;
import org.springframework.security.ldap.userdetails.UserDetailsContextMapper;

import java.util.Arrays;

/**
* Created by Viliam Repan (lazyman).
*/
Expand Down Expand Up @@ -67,8 +65,16 @@ public LdapContextSource contextSource() {

@Bean
public MidPointLdapAuthenticationProvider midPointAuthenticationProvider(
@Qualifier("userDetailsService") UserDetailsContextMapper userDetailsContextMapper) {
@Qualifier("userDetailsService") UserDetailsContextMapper userDetailsContextMapper) {

MidPointLdapAuthenticationProvider provider = new MidPointLdapAuthenticationProvider(bindAuthenticator());
provider.setUserDetailsContextMapper(userDetailsContextMapper);

return provider;
}

@Bean
public BindAuthenticator bindAuthenticator() {
BindAuthenticator auth = new BindAuthenticator(contextSource());
if (StringUtils.isNotEmpty(ldapDnPattern)) {
auth.setUserDnPatterns(new String[]{ldapDnPattern});
Expand All @@ -77,10 +83,7 @@ public MidPointLdapAuthenticationProvider midPointAuthenticationProvider(
auth.setUserSearch(userSearch());
}

MidPointLdapAuthenticationProvider provider = new MidPointLdapAuthenticationProvider(auth);
provider.setUserDetailsContextMapper(userDetailsContextMapper);

return provider;
return auth;
}

@ConditionalOnProperty("auth.ldap.search.pattern")
Expand Down
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2010-2017 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.evolveum.midpoint.web.boot;

import org.springframework.context.annotation.Configuration;

/**
* Created by Viliam Repan (lazyman).
*/
@Configuration
public class WebConfig {

}
Expand Up @@ -21,7 +21,6 @@
import com.evolveum.midpoint.web.security.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down
Expand Up @@ -36,6 +36,7 @@
import com.evolveum.midpoint.web.security.WebApplicationConfiguration;
import com.evolveum.midpoint.xml.ns._public.common.api_types_3.ImportOptionsType;

import com.evolveum.midpoint.xml.ns._public.common.common_3.ModelExecuteOptionsType;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
Expand All @@ -58,6 +59,8 @@
import java.io.InputStream;
import java.util.List;

import static org.apache.commons.lang3.BooleanUtils.isTrue;

/**
* @author lazyman
* @author mserbak
Expand Down Expand Up @@ -93,6 +96,7 @@ public class PageImportObject extends PageAdminConfiguration {
private static final Integer INPUT_XML = 2;

private LoadableModel<ImportOptionsType> optionsModel;
private IModel<Boolean> fullProcessingModel;
private IModel<String> xmlEditorModel;

private String dataLanguage;
Expand All @@ -105,7 +109,8 @@ protected ImportOptionsType load() {
return MiscSchemaUtil.getDefaultImportOptions();
}
};
xmlEditorModel = new Model<String>(null);
fullProcessingModel = Model.of(Boolean.FALSE);
xmlEditorModel = new Model<>(null);

initLayout();
}
Expand All @@ -114,7 +119,7 @@ private void initLayout() {
Form mainForm = new Form(ID_MAIN_FORM);
add(mainForm);

ImportOptionsPanel importOptions = new ImportOptionsPanel(ID_IMPORT_OPTIONS, optionsModel);
ImportOptionsPanel importOptions = new ImportOptionsPanel(ID_IMPORT_OPTIONS, optionsModel, fullProcessingModel);
mainForm.add(importOptions);

final WebMarkupContainer input = new WebMarkupContainer(ID_INPUT);
Expand Down Expand Up @@ -336,7 +341,13 @@ private void savePerformed(boolean raw, String operationName, AjaxRequestTarget
Task task = createSimpleTask(operationName);
InputDescription inputDescription = getInputDescription(raw);
stream = inputDescription.inputStream;
getModelService().importObjectsFromStream(stream, inputDescription.dataLanguage, optionsModel.getObject(), task, result);
ImportOptionsType options = optionsModel.getObject();
if (isTrue(fullProcessingModel.getObject())) {
options.setModelExecutionOptions(new ModelExecuteOptionsType().raw(false));
} else {
options.setModelExecutionOptions(null);
}
getModelService().importObjectsFromStream(stream, inputDescription.dataLanguage, options, task, result);

result.recomputeStatus();
} catch (Exception ex) {
Expand Down
Expand Up @@ -60,6 +60,10 @@
<input wicket:id="validateStaticSchema" type="checkbox" name="optionsRadios" checked>
<wicket:message key="importOptionsPanel.validateStaticSchema"/>
</label>
<label class="col-lg-2 checkbox-inline">
<input wicket:id="fullProcessing" type="checkbox" name="optionsRadios" checked>
<wicket:message key="importOptionsPanel.fullProcessing"/>
</label>
</div>
</div>
</div>
Expand Down
Expand Up @@ -18,12 +18,12 @@

import com.evolveum.midpoint.xml.ns._public.common.api_types_3.ImportOptionsType;

import org.apache.commons.lang.Validate;
import org.apache.wicket.markup.html.form.CheckBox;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;
import org.jetbrains.annotations.NotNull;

/**
* @author lazyman
Expand All @@ -39,50 +39,33 @@ public class ImportOptionsPanel extends Panel {
private static final String ID_SUMMARIZE_SUCCESSES = "summarizeSuccesses";
private static final String ID_VALIDATE_DYNAMIC_SCHEMA = "validateDynamicSchema";
private static final String ID_VALIDATE_STATIC_SCHEMA = "validateStaticSchema";
private static final String ID_FULL_PROCESSING = "fullProcessing";
private static final String ID_ERRORS = "errors";

private IModel<ImportOptionsType> model;
private IModel<Boolean> fullProcessingModel;

public ImportOptionsPanel(String id, IModel<ImportOptionsType> model) {
public ImportOptionsPanel(String id, @NotNull IModel<ImportOptionsType> model, @NotNull IModel<Boolean> fullProcessingModel) {
super(id);
Validate.notNull(model);
this.model = model;
this.fullProcessingModel = fullProcessingModel;

setRenderBodyOnly(true);

initLayout();
}

private void initLayout() {
CheckBox protectedByEncryption = new CheckBox(ID_PROTECTED_BY_ENCRYPTION,
new PropertyModel<Boolean>(model, "encryptProtectedValues"));
add(protectedByEncryption);
CheckBox fetchResourceSchema = new CheckBox(ID_FETCH_RESOURCE_SCHEMA,
new PropertyModel<Boolean>(model, "fetchResourceSchema"));
add(fetchResourceSchema);
CheckBox keepOid = new CheckBox(ID_KEEP_OID,
new PropertyModel<Boolean>(model, "keepOid"));
add(keepOid);
CheckBox overwriteExistingObject = new CheckBox(ID_OVERWRITE_EXISTING_OBJECT,
new PropertyModel<Boolean>(model, "overwrite"));
add(overwriteExistingObject);
CheckBox referentialIntegrity = new CheckBox(ID_REFERENTIAL_INTEGRITY,
new PropertyModel<Boolean>(model, "referentialIntegrity"));
add(referentialIntegrity);
CheckBox summarizeErrors = new CheckBox(ID_SUMMARIZE_ERRORS,
new PropertyModel<Boolean>(model, "summarizeErrors"));
add(summarizeErrors);
CheckBox summarizeSuccesses = new CheckBox(ID_SUMMARIZE_SUCCESSES,
new PropertyModel<Boolean>(model, "summarizeSucceses"));
add(summarizeSuccesses);
CheckBox validateDynamicSchema = new CheckBox(ID_VALIDATE_DYNAMIC_SCHEMA,
new PropertyModel<Boolean>(model, "validateDynamicSchema"));
add(validateDynamicSchema);
CheckBox validateStaticSchema = new CheckBox(ID_VALIDATE_STATIC_SCHEMA,
new PropertyModel<Boolean>(model, "validateStaticSchema"));
add(validateStaticSchema);
TextField<Integer> errors = new TextField<Integer>(ID_ERRORS,
new PropertyModel<Integer>(model, "stopAfterErrors"));
add(errors);
add(new CheckBox(ID_PROTECTED_BY_ENCRYPTION, new PropertyModel<>(model, "encryptProtectedValues")));
add(new CheckBox(ID_FETCH_RESOURCE_SCHEMA, new PropertyModel<>(model, "fetchResourceSchema")));
add(new CheckBox(ID_KEEP_OID, new PropertyModel<>(model, "keepOid")));
add(new CheckBox(ID_OVERWRITE_EXISTING_OBJECT, new PropertyModel<>(model, "overwrite")));
add(new CheckBox(ID_REFERENTIAL_INTEGRITY, new PropertyModel<>(model, "referentialIntegrity")));
add(new CheckBox(ID_SUMMARIZE_ERRORS, new PropertyModel<>(model, "summarizeErrors")));
add(new CheckBox(ID_SUMMARIZE_SUCCESSES, new PropertyModel<>(model, "summarizeSucceses")));
add(new CheckBox(ID_VALIDATE_DYNAMIC_SCHEMA, new PropertyModel<>(model, "validateDynamicSchema")));
add(new CheckBox(ID_VALIDATE_STATIC_SCHEMA, new PropertyModel<>(model, "validateStaticSchema")));
add(new CheckBox(ID_FULL_PROCESSING, fullProcessingModel));
add(new TextField<Integer>(ID_ERRORS, new PropertyModel<>(model, "stopAfterErrors")));
}
}
Expand Up @@ -32,6 +32,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.RegistrationsPolicyType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityPolicyType;

import org.apache.commons.lang.StringUtils;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
Expand Down Expand Up @@ -141,8 +142,12 @@ protected void onConfigure() {
return;
}

String key = ex.getMessage() != null ? ex.getMessage() : "web.security.provider.unavailable";
error(getString(key));
String msg = ex.getMessage();
if (StringUtils.isEmpty(msg)) {
msg = getString("web.security.provider.unavailable");
}

error(msg);

httpSession.removeAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);

Expand Down
Expand Up @@ -17,6 +17,9 @@
package com.evolveum.midpoint.web.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.MessageSourceAware;
import org.springframework.context.support.MessageSourceAccessor;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.AuthenticationServiceException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
Expand All @@ -36,10 +39,17 @@
* @author lazyman
* @author Radovan Semancik
*/
public class MidPointAuthenticationProvider implements AuthenticationProvider {
public class MidPointAuthenticationProvider implements AuthenticationProvider, MessageSourceAware {

private static final Trace LOGGER = TraceManager.getTrace(MidPointAuthenticationProvider.class);

private MessageSourceAccessor messages;

@Override
public void setMessageSource(MessageSource messageSource) {
this.messages = new MessageSourceAccessor(messageSource);
}

@Autowired
private transient AuthenticationEvaluator<PasswordAuthenticationContext> passwordAuthenticationEvaluator;

Expand All @@ -59,7 +69,7 @@ public Authentication authenticate(Authentication authentication) throws Authent
token = passwordAuthenticationEvaluator.authenticateUserPreAuthenticated(connEnv, enteredUsername);
} else {
LOGGER.error("Unsupported authentication {}", authentication);
throw new AuthenticationServiceException("web.security.provider.unavailable");
throw new AuthenticationServiceException(messages.getMessage("web.security.provider.unavailable"));
}

MidPointPrincipal principal = (MidPointPrincipal)token.getPrincipal();
Expand Down
Expand Up @@ -389,6 +389,7 @@ importOptionsPanel.summarizeErrors=Summarize errors
importOptionsPanel.summarizeSuccesses=Summarize successes
importOptionsPanel.validateDynamicSchema=Validate dynamic schema
importOptionsPanel.validateStaticSchema=Validate static schema (XML only)
importOptionsPanel.fullProcessing=Full processing
ItemApprovalPanel.approvalSchema=Approval schema
ItemApprovalPanel.currentWorkItems=Current work items
ItemApprovalPanel.nextStages=Following stages
Expand Down Expand Up @@ -3091,6 +3092,13 @@ web.security.ldap.locked=User is locked, please wait.
web.security.ldap.password.bad=User doesn't have defined password.
web.security.ldap.password.encoding=Couldn't authenticate user, reason: couldn't encode password.
web.security.ldap.unavailable=Currently we are unable to process your request. Kindly try again later.
LdapAuthenticationProvider.badCredentials=Invalid username and/or password.
LdapAuthenticationProvider.emptyUsername=Empty username.
LdapAuthentication.incorrect.value=MidPoint principal type doesn't match.
LdapAuthentication.bad.user=Unknown user.
UserProfileServiceImpl.unknownUser=Couldn''t find user with name ''{0}'', reason: {1}.
AbstractLdapAuthenticationProvider.emptyPassword=Empty password.
BindAuthenticator.badCredentials=Invalid username and/or password.
WfDeltasPanel.label.deltaIn=Process input: delta(s) to be approved
WfDeltasPanel.label.deltaOutListEmpty=(none)
WfDeltasPanel.label.deltaOut=Process output: delta(s) resulting from the approval
Expand Down
@@ -0,0 +1,74 @@
/*
* Copyright (c) 2010-2017 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.evolveum.midpoint.common;

import org.apache.commons.lang.Validate;
import org.springframework.context.MessageSource;
import org.springframework.context.MessageSourceResolvable;
import org.springframework.context.NoSuchMessageException;

import java.util.Locale;

/**
* Created by Viliam Repan (lazyman).
*/
public class LocalizationMessageSource implements MessageSource {

private LocalizationService localizationService;

public LocalizationMessageSource(LocalizationService localizationService) {
this.localizationService = localizationService;
}

@Override
public String getMessage(String code, Object[] args, String defaultMessage, Locale locale) {
String msg = localizationService.translate(code, args, locale);
if (msg == null) {
return defaultMessage;
}

return msg;
}

@Override
public String getMessage(String code, Object[] args, Locale locale) throws NoSuchMessageException {
String msg = localizationService.translate(code, args, locale);
if (msg == null) {
throw new NoSuchMessageException("Message code '" + code + "' was not found");
}

return msg;
}

@Override
public String getMessage(MessageSourceResolvable resolvable, Locale locale) throws NoSuchMessageException {
Validate.notNull(resolvable, "Message source resolvable must not be null");

for (String code : resolvable.getCodes()) {
String msg = localizationService.translate(code, resolvable.getArguments(), locale);
if (msg != null) {
return msg;
}
}

if (resolvable.getDefaultMessage() != null) {
return resolvable.getDefaultMessage();
}

throw new NoSuchMessageException("Can't resolve message: " + resolvable);
}
}
Expand Up @@ -48,6 +48,11 @@ public void init() {
sources.add(buildSource(SchemaConstants.BUNDLE_NAME, classLoader));
sources.add(buildSource("localization/Midpoint", null));
sources.add(buildSource(SchemaConstants.SCHEMA_LOCALIZATION_PROPERTIES_RESOURCE_BASE_PATH, null));

// spring security messages as a fallback
ResourceBundleMessageSource springSecurity = new ResourceBundleMessageSource();
springSecurity.setBasename("org.springframework.security.messages");
sources.add(springSecurity);
}

@Override
Expand Down

0 comments on commit 5eb5406

Please sign in to comment.