【前処理】
:
String [] retAttributes = new String[1];
retAttributes[0] = "ssoRoleName";
SearchControls sc = new SearchControls();
sc.setSearchScope(SearchControls.OBJECT_SCOPE);
sc.setReturningAttributes(retAttributes);
sc.setCountLimit(1);
sc.setTimeLimit(5*1000); // 5 seconds
String filter = "(cn=" + user + ")";
String dn = "cn=" + user + ",ou=User,ou=interstage,o=fujitsu,dc=com";
NamingEnumeration ne = ctx.search(dn, filter, sc);
Attribute roleAttr = null;
while(ne.hasMore()) {
SearchResult sr = (SearchResult)ne.next();
Attributes attrs = sr.getAttributes();
if(attrs != null) {
roleAttr = attrs.get("ssoRoleName");
if(roleAttr != null) {
break;
}
}
}
if(roleAttr != null) {
if(roleAttr.remove(role)) {
ModificationItem[] mods = new ModificationItem[1];
mods[0] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, roleAttr );
ctx.modifyAttributes(dn, mods);
}
}
:
【後処理】 |