package com.github.ganity.oauth2.shiro;

import com.github.ganity.oauth2.AuthzCallback;
import com.github.ganity.oauth2.OAuth2AccessToken;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;

import java.util.Map;

public class ShiroAuthzCallback implements AuthzCallback {
    @Override
    public void callback(OAuth2AccessToken accessToken, Map<String, String> principal) {
        Subject subject = SecurityUtils.getSubject();

        UsernamePasswordToken token = new UsernamePasswordToken(principal.get(PRINCIPAL), principal.get(PRINCIPAL).toCharArray());
        token.setRememberMe(false);
        try {
            if (subject.isAuthenticated()) {
                subject.logout();
            }
            subject.login(token);

            Session session = subject.getSession();
            session.setAttribute(AUTH_ACCESS_TOKEN, accessToken);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

@@ -1054,11 +1054,519 @@
  %7D%0A    %7D
+%0A%0A    @Override%0A    public OAuth2AccessToken logout() %7B%0A%0A        Subject subject = SecurityUtils.getSubject();%0A%0A        try %7B%0A            Session session = subject.getSession();%0A            OAuth2AccessToken accessToken = (OAuth2AccessToken)session.getAttribute(AUTH_ACCESS_TOKEN);%0A            if (subject.isAuthenticated()) %7B%0A                subject.logout();%0A            %7D%0A            return accessToken;%0A        %7D catch (Exception e) %7B%0A            e.printStackTrace();%0A        %7D%0A        return null;%0A    %7D
 %0A%7D%0A

add logout