Package com.github.zhangkaitao.shiro.chapter15.realm

Source Code of com.github.zhangkaitao.shiro.chapter15.realm.MyCasRealm

package com.github.zhangkaitao.shiro.chapter15.realm;

import com.github.zhangkaitao.shiro.chapter15.service.UserService;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.cas.CasRealm;
import org.apache.shiro.subject.PrincipalCollection;

/**
* <p>User: Zhang Kaitao
* <p>Date: 14-2-13
* <p>Version: 1.0
*/
public class MyCasRealm extends CasRealm {

    private UserService userService;

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
        String username = (String)principals.getPrimaryPrincipal();

        SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
        authorizationInfo.setRoles(userService.findRoles(username));
        authorizationInfo.setStringPermissions(userService.findPermissions(username));

        return authorizationInfo;
    }
}
TOP

Related Classes of com.github.zhangkaitao.shiro.chapter15.realm.MyCasRealm

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.