/**
* OLAT - Online Learning and Training<br>
* http://www.olat.org
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.
* <p>
*/
package org.olat.shibboleth;
import org.olat.basesecurity.Authentication;
import org.olat.core.gui.components.form.Form;
import org.olat.core.gui.formelements.PasswordElement;
import org.olat.core.gui.formelements.StaticTextElement;
import org.olat.core.gui.translator.Translator;
import org.olat.core.logging.Tracing;
import org.olat.core.util.Encoder;
import org.olat.login.LoginModule;
/**
* Initial Date: 09.08.2004
*
* @author Mike Stock
*
* Comment:
*
*/
public class ShibbolethMigrationForm extends Form {
private Authentication authentication;
private StaticTextElement login;
private PasswordElement password;
/**
* @param formName
* @param authentication
*/
public ShibbolethMigrationForm(String formName, Translator translator, Authentication authentication) {
super(formName, translator);
this.authentication = authentication;
init();
}
/**
* @see org.olat.core.gui.components.Form#validate(org.olat.core.gui.UserRequest)
*/
public boolean validate() {
String credential = authentication.getCredential();
if (credential == null) return false;
if (!credential.equals(Encoder.encrypt(password.getValue()))) {
if (LoginModule.registerFailedLoginAttempt(login.getValue())) {
password.setErrorKey("smf.error.blocked");
Tracing.logAudit("Too many failed login attempts for " + login.getValue() + ". Login blocked.", this.getClass());
} else {
password.setErrorKey("smf.error.password");
Tracing.logAudit("Invalid password in ShibbolethMigration for login: " + login.getValue(), this.getClass());
}
return false;
}
return true;
}
/**
* Initialize form.
*/
private void init() {
login = new StaticTextElement("smf.login", authentication.getIdentity().getName());
addFormElement("smf_login", login);
password = new PasswordElement("smf.password", 255);
addFormElement("smf_password", password);
addSubmitKey("save");
setCancelButton();
}
/**
* @return Authentication
*/
protected Authentication getAuthentication() { return authentication; }
}