|
| 1 | +/* |
| 2 | + * Password Management Servlets (PWM) |
| 3 | + * http://www.pwm-project.org |
| 4 | + * |
| 5 | + * Copyright (c) 2006-2009 Novell, Inc. |
| 6 | + * Copyright (c) 2009-2019 The PWM Project |
| 7 | + * |
| 8 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | + * you may not use this file except in compliance with the License. |
| 10 | + * You may obtain a copy of the License at |
| 11 | + * |
| 12 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | + * |
| 14 | + * Unless required by applicable law or agreed to in writing, software |
| 15 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | + * See the License for the specific language governing permissions and |
| 18 | + * limitations under the License. |
| 19 | + */ |
| 20 | + |
| 21 | +package password.pwm.config.function; |
| 22 | + |
| 23 | +import password.pwm.bean.UserIdentity; |
| 24 | +import password.pwm.config.Configuration; |
| 25 | +import password.pwm.config.PwmSetting; |
| 26 | +import password.pwm.config.SettingUIFunction; |
| 27 | +import password.pwm.config.stored.StoredConfigurationImpl; |
| 28 | +import password.pwm.config.value.X509CertificateValue; |
| 29 | +import password.pwm.error.PwmUnrecoverableException; |
| 30 | +import password.pwm.http.PwmRequest; |
| 31 | +import password.pwm.http.PwmSession; |
| 32 | +import password.pwm.i18n.Message; |
| 33 | +import password.pwm.svc.email.EmailServerUtil; |
| 34 | +import password.pwm.util.java.JavaHelper; |
| 35 | + |
| 36 | +import java.security.cert.X509Certificate; |
| 37 | +import java.util.List; |
| 38 | + |
| 39 | +public class SmtpCertImportFunction implements SettingUIFunction |
| 40 | +{ |
| 41 | + @Override |
| 42 | + public String provideFunction( |
| 43 | + final PwmRequest pwmRequest, |
| 44 | + final StoredConfigurationImpl storedConfiguration, |
| 45 | + final PwmSetting setting, |
| 46 | + final String profile, |
| 47 | + final String extraData |
| 48 | + ) |
| 49 | + throws PwmUnrecoverableException |
| 50 | + { |
| 51 | + final PwmSession pwmSession = pwmRequest.getPwmSession(); |
| 52 | + |
| 53 | + final Configuration configuration = new Configuration( storedConfiguration ); |
| 54 | + final List<X509Certificate> certs = EmailServerUtil.readCertificates( configuration, profile ); |
| 55 | + if ( !JavaHelper.isEmpty( certs ) ) |
| 56 | + { |
| 57 | + final UserIdentity userIdentity = pwmSession.isAuthenticated() ? pwmSession.getUserInfo().getUserIdentity() : null; |
| 58 | + storedConfiguration.writeSetting( PwmSetting.EMAIL_SERVER_CERTS, profile, new X509CertificateValue( certs ), userIdentity ); |
| 59 | + } |
| 60 | + |
| 61 | + return Message.getLocalizedMessage( pwmSession.getSessionStateBean().getLocale(), Message.Success_Unknown, pwmRequest.getConfig() ); |
| 62 | + } |
| 63 | + |
| 64 | +} |
0 commit comments