Spring Security manual authentication

asked 2015-02-15 16:28:37 +0800

Arsen gravatar image Arsen
382 5

I have my own login form and I want to make authentication in Composer event listener. Here is application-context

 <http auto-config="true" use-expressions="true">
    <intercept-url pattern="/zkau/**" access="permitAll"/>
    <intercept-url pattern="/public/**" access="permitAll"/>
    <intercept-url pattern="/images/**" access="permitAll"/>
    <intercept-url pattern="/css/**" access="permitAll"/>
    <intercept-url pattern="/js/**" access="permitAll"/>
    <intercept-url pattern="/help/**" access="permitAll"/>
    <intercept-url pattern="/personal/**" access="isAuthenticated()"/>
    <intercept-url pattern="/**" access="isAuthenticated()"/>

    <form-login login-page="/public/#login"/>

    <logout logout-success-url="/public" invalidate-session="true"/>

And my Java code from composer

  protected String readText(Textbox textbox, String errorMessage) {
        String value = textbox.getValue();
        if (StringUtils.isTrimedEmpty(value)) {
            throw new WrongValueException(textbox, errorMessage);
        } else {
            return value;

     * Tries to authorize user with specified login and password
    public void authorize() {
        String login = readText(loginText, "Необходимо ввести логин");
        String password = readText(passwordText, "Необходимо ввести пароль");

        try {
            Authentication authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(login, password));
            SecurityContext context = SecurityContextHolder.getContext();
            session.setAttribute("SPRING_SECURITY_CONTEXT", context);
            sessionAuthenticationStrategy.onAuthentication(authentication, (HttpServletRequest) execution.getNativeRequest(), (HttpServletResponse) execution.getNativeResponse());

But when is redirected to index.zul current session is not authenticated and Spring redirects back to /public#login

delete flag offensive retag edit

1 Answer

Sort by » oldest newest most voted

answered 2015-02-21 19:15:22 +0800

Darksu gravatar image Darksu
1991 1 4

Hello Arsen,

Please look at the following example:


Best Regards,


link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

1 follower



Asked: 2015-02-15 16:28:37 +0800

Seen: 37 times

Last updated: Feb 21 '15

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More