0
ユーザーが特定のグループに属している場合、shiroをアクティブディレクトリに接続して構成します。ユーザーがアクティブなディレクトリグループに属しているかどうかを確認します
Shiro.ini
ファイル:
[main]
realm = org.apache.shiro.realm.activedirectory.ActiveDirectoryRealm
realm.url = LDAP://example.com/
realm.systemUsername = [email protected]
realm.systemPassword = password
realm.searchBase = "OU=level2,OU=level1,DC=example,DC=com"
realm.groupRolesMap = "CN=Group1,OU=level2,OU=level1,DC=example,DC=com":"itadmins"
[roles]
itadmins = *
やコード:
public class Quickstart {
private static final transient Logger log = LoggerFactory.getLogger(Quickstart.class);
public static final String userName = "[email protected]";
public static final String password = "userpassword";
public static void main(String[] args) {
// The easiest way to create a Shiro SecurityManager with configured
// realms, users, roles and permissions is to use the simple INI config.
// We'll do that by using a factory that can ingest a .ini file and
// return a SecurityManager instance:
// Use the shiro.ini file at the root of the classpath
// (file: and url: prefixes load from files and urls respectively):
Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini");
SecurityManager securityManager = factory.getInstance();
// for this simple example quickstart, make the SecurityManager
// accessible as a JVM singleton. Most applications wouldn't do this
// and instead rely on their container configuration or web.xml for
// webapps. That is outside the scope of this simple quickstart, so
// we'll just do the bare minimum so you can continue to get a feel
// for things.
SecurityUtils.setSecurityManager(securityManager);
// Now that a simple Shiro environment is set up, let's see what you can do:
UsernamePasswordToken token = new UsernamePasswordToken(userName, password);
// get the currently executing user:
Subject currentUser = SecurityUtils.getSubject();
try {
currentUser.login(token);
System.out.println("We've authenticated! :)");
} catch (AuthenticationException e) {
System.out.println("We did not authenticate :(");
e.printStackTrace();
}
log.info("User [" + currentUser + "] logged in successfully.");
if (currentUser.hasRole("hasRole")) {
System.out.println("We're authorized! :)");
} else {
System.out.println("We are not authorized :(");
}
//all done - log out!
currentUser.logout();
System.exit(0);*/
}
}
ユーザーが認証されたが許可されていません。私は間違って何をしていますか?