我使用Tapestry,安全,它使用的Apache四郎四郎授權填充授權遠程角色
我有處理授權和認證的自定義境界。我們的認證技術上是使用遠程服務發生的,遠程服務返回一個用戶名和一組角色。我只是將用戶名傳遞給我的自定義AuthenticationToken,它允許我查詢我們的本地數據庫並設置SimpleAuthenticationInfo。
我無法弄清楚如何填充使用角色列表中AuthorizationInfo doGetAuthorizationInfo方法從我們的遠程服務還給我。以下是我用來填充領域的代碼。
Login.class
//Remote authentication service
RemoteLoginClient client = new RemoteLoginClient();
RemoteSubject authenticate = client.authenticate(username, password);
//tapestry security authentication
Subject currentUser = SecurityUtils.getSubject();
CustomAuthenticationToken token = new
CustomAuthenticationToken(authenticate.getUsername());
System.out.println("roles" + authenticate.getRoles());
currentUser.login(token);
customRealm 公共類CustomRealm內AuthorizationInfo方法擴展AuthorizingRealm {
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
CustomAuthenticationToken upToken = (CustomAuthenticationToken) token;
String email = upToken.getUsername();
ApplicationUser applicationUser = (ApplicationUser) session.createCriteria(ApplicationUser.class)
.add(Restrictions.like("email", email + "%"))
.uniqueResult();
if (applicationUser == null) {
throw new UnknownAccountException("User doesn't exist in EPRS database");
}
return buildAuthenticationInfo(applicationUser.getId());
}
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
//Not sure how to populate the principle or
//read the principle to populate the SimpleAuthorizationInfo
return new SimpleAuthorizationInfo(roleNames);
}
幾個星期前,我記下了如何處理四郎和吉斯。但是,您可否檢查「實施領域」一節是否會涵蓋您的問題 - http://readyareyou.blogspot.de/2012/03/guice-jersey-shiro.html? – PepperBob
@PepperBob感謝您的回覆,在我看來,您提供的鏈接中的示例仍然使用數據庫來查找用戶角色。在我的場景中,角色在登錄時從我們的Web服務列表中提供給我。我會如何將這個角色列表傳遞到SimpleAuthorizationInfo,這是我目前丟失的地方。任何額外的想法? –
我認爲你應該能夠將所有東西都粘貼到Account-Interface的實現中(http://shiro.apache.org/static/current/apidocs/org/apache/shiro/authc/Account.html),因爲它捆綁了認證和授權,例如。 SimpleAccount或定製的東西。 – PepperBob