admin 管理员组文章数量: 887021
2024年2月7日发(作者:哪里找免费网站)
public class CasRealm extends AuthorizingRealm{ public CasRealm() { validationProtocol = "CAS"; rememberMeAttributeName = "longTermAuthenticationRequestTokenUsed"; setAuthenticationTokenClass(org/apache/shiro/cas/CasToken); } protected void onInit() { (); ensureTicketValidator(); } protected TicketValidator ensureTicketValidator() { if(ticketValidator == null) ticketValidator = createTicketValidator(); return ticketValidator; } protected TicketValidator createTicketValidator() { String urlPrefix = getCasServerUrlPrefix(); if("saml".equalsIgnoreCase(getValidationProtocol())) return new Saml11TicketValidator(urlPrefix); else return new Cas20ServiceTicketValidator(urlPrefix); } protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { CasToken casToken = (CasToken)token; if(token == null) return null; String ticket = (String)dentials(); if(!t(ticket)) return null; TicketValidator ticketValidator = ensureTicketValidator(); try { Assertion casAssertion = te(ticket, getCasService()); AttributePrincipal casPrincipal = ncipal(); String userId = e(); ("Validate ticket : {} in CAS server : {} to retrieve user : {}", new Object[] { ticket, getCasServerUrlPrefix(), userId }); Map attributes = ributes(); rId(userId); String rememberMeAttributeName = getRememberMeAttributeName(); String rememberMeStringValue = (String)(rememberMeAttributeName); boolean isRemembered = rememberMeStringValue != null && oolean(rememberMeStringValue); if(isRemembered) emberMe(true); List principals = (new Object[] { userId, attributes }); PrincipalCollection principalCollection = new SimplePrincipalCollection(principals, getName()); return new SimpleAuthenticationInfo(principalCollection, ticket); } catch(TicketValidationException e) { throw new CasAuthenticationException((new StringBuilder()).append("Unable to validate ticket [").append(ticket).append("]").toString(), e);
throw new CasAuthenticationException((new StringBuilder()).append("Unable to validate ticket [").append(ticket).append("]").toString(), e); } } protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { SimplePrincipalCollection principalCollection = (SimplePrincipalCollection)principals; List listPrincipals = (); Map attributes = (Map)(1); SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo(); addRoles(simpleAuthorizationInfo, split(defaultRoles)); addPermissions(simpleAuthorizationInfo, split(defaultPermissions)); List attributeNames = split(roleAttributeNames); String value; for(Iterator i$ = or(); i$.hasNext(); addRoles(simpleAuthorizationInfo, split(value))) { String attributeName = (String)i$.next(); value = (String)(attributeName); } attributeNames = split(permissionAttributeNames); String value; for(Iterator i$ = or(); i$.hasNext(); addPermissions(simpleAuthorizationInfo, split(value))) { String attributeName = (String)i$.next(); value = (String)(attributeName); } return simpleAuthorizationInfo; } private List split(String s) { List list = new ArrayList(); String elements[] = (s, ','); if(elements != null && > 0) { String arr$[] = elements; int len$ = arr$.length; for(int i$ = 0; i$ < len$; i$++) { String element = arr$[i$]; if(t(element)) (()); } } return list; } private void addRoles(SimpleAuthorizationInfo simpleAuthorizationInfo, List roles) { String role; for(Iterator i$ = or(); i$.hasNext(); e(role)) role = (String)i$.next(); } private void addPermissions(SimpleAuthorizationInfo simpleAuthorizationInfo, List permissions) { String permission; for(Iterator i$ = or(); i$.hasNext(); ingPermission(permission)) permission = (String)i$.next(); }
public String getCasServerUrlPrefix() { return casServerUrlPrefix; } public void setCasServerUrlPrefix(String casServerUrlPrefix) { verUrlPrefix = casServerUrlPrefix; } public String getCasService() { return casService; } public void setCasService(String casService) { vice = casService; } public String getValidationProtocol() { return validationProtocol; } public void setValidationProtocol(String validationProtocol) { tionProtocol = validationProtocol; } public String getRememberMeAttributeName() { return rememberMeAttributeName; } public void setRememberMeAttributeName(String rememberMeAttributeName) { erMeAttributeName = rememberMeAttributeName; } public String getDefaultRoles() { return defaultRoles; } public void setDefaultRoles(String defaultRoles) { tRoles = defaultRoles; } public String getDefaultPermissions() { return defaultPermissions; } public void setDefaultPermissions(String defaultPermissions) { tPermissions = defaultPermissions; } public String getRoleAttributeNames() { return roleAttributeNames; }
版权声明:本文标题:shiro安全框架扩展教程--整合cas框架扩展自定义CasRealm 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1707299705h514056.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论