LINUX.ORG.RU

j_security_check 404

 , ,


0

1

Решил сделать аутентификацию в своем ангулар приложении, стандартные аутентификаторы не покатили решил свой написать.

Взял за основу томкатовский BasicAuthentificator и выпилил из него все лишнее (в идеале хочу чтобы он работал как рест-сервис, те json возвращал).

В итоге при обращении к j_security_check вылетает 404, хотя аутентификация проходит и сессия заполняется.

Стал копать, выяснил, что ошибку дает DefaultServlet в этих строках:

        CacheEntry cacheEntry = resources.lookupCache(path);
        if (!cacheEntry.exists) {

Вопрос: что это такое?

web.xml:

    <!-- j_security_check -->
    <security-constraint>
        <display-name>User</display-name>
        <auth-constraint>
            <role-name>user</role-name>
        </auth-constraint>
    </security-constraint>
    <login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>default</realm-name>
    </login-config>
    <security-role>
        <role-name>user</role-name>
    </security-role>

context.xml:

<Valve className="com.example.authentificator.BasicAuthenticator" />

BasicAuthenticator:

public class BasicAuthenticator
    extends AuthenticatorBase {
    private static final Log log = LogFactory.getLog(BasicAuthenticator.class);

    /**
     * Descriptive information about this implementation.
     */
    protected static final String info =
        "com.example.authentificator.BasicAuthenticator/1.0";


    @Override
    public String getInfo() {

        return (info);

    }

    @Override
    public boolean authenticate(Request request, HttpServletResponse response, LoginConfig config) throws IOException {
        Principal principal = request.getUserPrincipal();
        String ssoId = (String) request.getNote(Constants.REQ_SSOID_NOTE);
        if (principal != null) {
            if (log.isDebugEnabled())
                log.debug("Already authenticated '" + principal.getName() + "'");
            // Associate the session with any existing SSO session
            if (ssoId != null)
                associate(ssoId, request.getSessionInternal(true));
            return (true);
        }

        // Is there an SSO session against which we can try to reauthenticate?
        if (ssoId != null) {
            if (log.isDebugEnabled()) {
                log.debug("SSO Id " + ssoId + " set; attempting reauthentication");
            }
            if (reauthenticateFromSSO(ssoId, request)) {
                return true;
            }
        }

        String username = request.getParameter(Constants.FORM_USERNAME);
        String password = request.getParameter(Constants.FORM_PASSWORD);

        principal = context.getRealm().authenticate(username, password);
        if (principal != null) {
            register(request, response, principal,
                    HttpServletRequest.BASIC_AUTH, username, password);
            response.sendError(HttpServletResponse.SC_OK);
            return true;
        }

        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return false;

    }


    @Override
    protected String getAuthMethod() {
        return HttpServletRequest.BASIC_AUTH;
    }
}



Последнее исправление: Klymedy (всего исправлений: 1)

Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.