<commit_before>/**
 * Licensed to Apereo under one or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information regarding copyright ownership. Apereo
 * licenses this file to you 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 the
 * following location:
 *
 * <p>http://www.apache.org/licenses/LICENSE-2.0
 *
 * <p>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 org.apereo.portal.security.provider;

import static java.nio.charset.StandardCharsets.UTF_8;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apereo.portal.persondir.ILocalAccountDao;
import org.apereo.portal.persondir.ILocalAccountPerson;
import org.apereo.portal.security.IPortalPasswordService;
import org.apereo.portal.security.ISecurityContext;
import org.apereo.portal.security.PortalSecurityException;
import org.apereo.portal.spring.locator.LocalAccountDaoLocator;
import org.apereo.portal.spring.locator.PortalPasswordServiceLocator;

/**
 * This is an implementation of a SecurityContext that checks a user's credentials against an MD5
 * hashed password entry.
 */
public class SimpleSecurityContext extends ChainingSecurityContext implements ISecurityContext {

    private static final Log log = LogFactory.getLog(SimpleSecurityContext.class);

    private final int SIMPLESECURITYAUTHTYPE = 0xFF02;

    /* package-private */ SimpleSecurityContext() {}

    @Override
    public int getAuthType() {
        return this.SIMPLESECURITYAUTHTYPE;
    }

    /**
     * Authenticate user.
     *
     * @exception PortalSecurityException
     */
    @Override
    public synchronized void authenticate() throws PortalSecurityException {
        this.isauth = false;
        if (this.myPrincipal.UID != null && this.myOpaqueCredentials.credentialstring != null) {

            // Logs if an attempt is made to log into a local account
            StringBuilder msg = new StringBuilder();
            msg.append("An attempt to log into the local login has occurred. ");
            msg.append("user=" + this.myPrincipal.UID);
            if (log.isWarnEnabled()) log.warn(msg.toString()); 

            try {

                ILocalAccountDao accountStore = LocalAccountDaoLocator.getLocalAccountDao();
                IPortalPasswordService passwordService =
                        PortalPasswordServiceLocator.getPortalPasswordService();

                // retrieve the account from the local user store
                ILocalAccountPerson account = accountStore.getPerson(this.myPrincipal.UID);

                if (account != null) {

                    // get the account password as an ASCII string
                    String loginPassword =<commit_msg>Cleaned up code and moved message into if statement<commit_after>/**
 * Licensed to Apereo under one or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information regarding copyright ownership. Apereo
 * licenses this file to you 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 the
 * following location:
 *
 * <p>http://www.apache.org/licenses/LICENSE-2.0
 *
 * <p>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 org.apereo.portal.security.provider;

import static java.nio.charset.StandardCharsets.UTF_8;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apereo.portal.persondir.ILocalAccountDao;
import org.apereo.portal.persondir.ILocalAccountPerson;
import org.apereo.portal.security.IPortalPasswordService;
import org.apereo.portal.security.ISecurityContext;
import org.apereo.portal.security.PortalSecurityException;
import org.apereo.portal.spring.locator.LocalAccountDaoLocator;
import org.apereo.portal.spring.locator.PortalPasswordServiceLocator;

/**
 * This is an implementation of a SecurityContext that checks a user's credentials against an MD5
 * hashed password entry.
 */
public class SimpleSecurityContext extends ChainingSecurityContext implements ISecurityContext {

    private static final Log log = LogFactory.getLog(SimpleSecurityContext.class);

    private final int SIMPLESECURITYAUTHTYPE = 0xFF02;

    /* package-private */ SimpleSecurityContext() {}

    @Override
    public int getAuthType() {
        return this.SIMPLESECURITYAUTHTYPE;
    }

    /**
     * Authenticate user.
     *
     * @exception PortalSecurityException
     */
    @Override
    public synchronized void authenticate() throws PortalSecurityException {
        this.isauth = false;
        if (this.myPrincipal.UID != null && this.myOpaqueCredentials.credentialstring != null) {

            // Logs if an attempt is made to log into a local account
            if (log.isWarnEnabled())
                log.warn(
                        "An attempt to log into the local login has occurred. user="
                                + this.myPrincipal.UID);

            try {

                ILocalAccountDao accountStore = LocalAccountDaoLocator.getLocalAccountDao();
                IPortalPasswordService passwordService =
                        PortalPasswordServiceLocator.getPortalPasswordService();

                // retrieve the account from the local user store
                ILocalAccountPerson account = accountStore.getPerson(this.myPrincipal.UID);

                if (account != null) {

                    // get the account password as an ASCII string
                    String loginPassword =
{'fraction_non_alphanumeric': 0.07249159865578493, 'fraction_numerical': 0.0028804608737397984, 'mean_word_length': 3.1750167000668004, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5137309', 'n_tokens_mistral': 1589, 'n_tokens_neox': 1543, 'n_words': 520}