diff --git a/src/main/java/com/cognifide/secureaem/tests/DefaultPasswordsTest.java b/src/main/java/com/cognifide/secureaem/tests/DefaultPasswordsTest.java index f86b0e5..46dfea0 100644 --- a/src/main/java/com/cognifide/secureaem/tests/DefaultPasswordsTest.java +++ b/src/main/java/com/cognifide/secureaem/tests/DefaultPasswordsTest.java @@ -6,6 +6,7 @@ import java.util.ArrayList; import java.util.List; + import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.auth.AuthenticationException; @@ -28,54 +29,54 @@ */ public class DefaultPasswordsTest extends AbstractTest implements AuthorTest, PublishTest { - private static final String LOGIN_PATH = "/libs/granite/core/content/login.html/j_security_check"; - private static final String USERNAME_FORM_PARAM_NAME = "j_username"; - private static final String PASSWORD_FORM_PARAM_NAME = "j_password"; - private static final String IS_VALIDATE_FORM_PARAM_NAME = "j_validate"; + private static final String LOGIN_PATH = "/libs/granite/core/content/login.html/j_security_check"; + private static final String USERNAME_FORM_PARAM_NAME = "j_username"; + private static final String PASSWORD_FORM_PARAM_NAME = "j_password"; + private static final String IS_VALIDATE_FORM_PARAM_NAME = "j_validate"; - public DefaultPasswordsTest(Configuration config) { - super(config); - } + public DefaultPasswordsTest(Configuration config) { + super(config); + } - @Override - public boolean doTest(String url, String instanceName) throws Exception { - String loginUrl = url + LOGIN_PATH; - boolean ok = true; - String[] users = config.getStringList("users"); - for (String user : users) { - String[] split = UserHelper.splitUser(user); - if (split[1] != null && remoteUserExists(split, loginUrl)) { - addErrorMessage("User %s exists on %s", user, instanceName); - ok = false; - } else { - addInfoMessage("User %s doesn't exists on %s", user, instanceName); - } + @Override + public boolean doTest(String url, String instanceName) throws Exception { + String loginUrl = url + LOGIN_PATH; + boolean ok = true; + String[] users = config.getStringList("users"); + for (String user : users) { + String[] split = UserHelper.splitUser(user); + if (split[1] != null && remoteUserExists(split, loginUrl)) { + addErrorMessage("User %s exists on %s", user, instanceName); + ok = false; + } else { + addInfoMessage("User %s doesn't exists on %s", user, instanceName); + } + } + return ok; } - return ok; - } - private boolean remoteUserExists(String[] user, String url) throws URISyntaxException, - IOException, AuthenticationException { - DefaultHttpClient authorizedClient = new DefaultHttpClient(); + private boolean remoteUserExists(String[] user, String url) throws URISyntaxException, + IOException, AuthenticationException { + DefaultHttpClient authorizedClient = new DefaultHttpClient(); - HttpPost httpPost = new HttpPost(url); - List params = getPostParamsList(user); - httpPost.setEntity(new UrlEncodedFormEntity(params)); + HttpPost httpPost = new HttpPost(url); + List params = getPostParamsList(user); + httpPost.setEntity(new UrlEncodedFormEntity(params)); - HttpResponse response = authorizedClient.execute(httpPost); - EntityUtils.consume(response.getEntity()); - int code = response.getStatusLine().getStatusCode(); - return code != HttpURLConnection.HTTP_FORBIDDEN; - } + HttpResponse response = authorizedClient.execute(httpPost); + EntityUtils.consume(response.getEntity()); + int code = response.getStatusLine().getStatusCode(); + return code != HttpURLConnection.HTTP_FORBIDDEN; + } - private List getPostParamsList(String[] user) { - List params = new ArrayList<>(); + private List getPostParamsList(String[] user) { + List params = new ArrayList<>(); - params.add(new BasicNameValuePair(USERNAME_FORM_PARAM_NAME, user[0])); - params.add(new BasicNameValuePair(PASSWORD_FORM_PARAM_NAME, user[1])); - params.add(new BasicNameValuePair(IS_VALIDATE_FORM_PARAM_NAME, "true")); + params.add(new BasicNameValuePair(USERNAME_FORM_PARAM_NAME, user[0])); + params.add(new BasicNameValuePair(PASSWORD_FORM_PARAM_NAME, user[1])); + params.add(new BasicNameValuePair(IS_VALIDATE_FORM_PARAM_NAME, "true")); - return params; - } + return params; + } }