0

Spring Security manual authentication

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

Arsen gravatar image Arsen
381 2

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"/>
</http>

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();
            context.setAuthentication(authentication);
            session.setAttribute("SPRING_SECURITY_CONTEXT", context);
            sessionAuthenticationStrategy.onAuthentication(authentication, (HttpServletRequest) execution.getNativeRequest(), (HttpServletResponse) execution.getNativeResponse());
 Executions.getCurrent().sendRedirect("/index.zul");

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
0

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

Darksu gravatar image Darksu
1991 1 4

Hello Arsen,

Please look at the following example:

http://emrpms.blogspot.in/2013/03/zk-spring-security-login-formpart-2.html

Best Regards,

Darksu

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

Follow
1 follower

RSS

Stats

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

Seen: 34 times

Last updated: Feb 21 '15

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