本文整理匯總了Java中java.security.acl.Group.isMember方法的典型用法代碼示例。如果您正苦於以下問題:Java Group.isMember方法的具體用法?Java Group.isMember怎麽用?Java Group.isMember使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.security.acl.Group
的用法示例。
在下文中一共展示了Group.isMember方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: processRoles
import java.security.acl.Group; //導入方法依賴的package包/類
/**
* Process the group with the roles that are mapped in the
* properies file
* @param group Group that needs to be processed
* @param props Properties file
*/
private void processRoles(Group group,Properties props) //throws Exception
{
Enumeration<?> enumer = props.propertyNames();
while(enumer.hasMoreElements())
{
String roleKey = (String)enumer.nextElement();
String comma_separated_roles = props.getProperty(roleKey);
try {
Principal pIdentity = createIdentity(roleKey);
if (group != null)
{
if(group.isMember(pIdentity))
Util.parseGroupMembers(group,comma_separated_roles,this);
if(REPLACE_ROLE)
group.removeMember(pIdentity);
}
}
catch(Exception e) {
PicketBoxLogger.LOGGER.debugFailureToCreatePrincipal(roleKey, e);
}
}
}
示例2: authorize
import java.security.acl.Group; //導入方法依賴的package包/類
@Override
protected void authorize(LoginContext context) throws LoginException {
HashSet<String> required = new HashSet<>(requiredRoles);
Set<Group> groups = context.getSubject().getPrincipals(Group.class);
if (groups != null) {
for (Group group : groups) {
if ("Roles".equals(group.getName())) {
for (String role : requiredRoles) {
if (group.isMember(new SimplePrincipal(role))) {
required.remove(role);
}
}
}
}
}
if (!required.isEmpty())
throw new LoginException("User does not have required roles: " + required);
}
示例3: isMemberRecurse
import java.security.acl.Group; //導入方法依賴的package包/類
private boolean isMemberRecurse(Principal principal, Vector<Principal> vector)
{
for(Enumeration<Principal> enumeration = members(); enumeration.hasMoreElements();)
{
boolean flag = false;
Principal principal1 = (Principal)enumeration.nextElement();
if(principal1.equals(principal))
return true;
if(principal1 instanceof SecurityGroup)
{
SecurityGroup groupimpl = (SecurityGroup)principal1;
vector.addElement(this);
if(!vector.contains(groupimpl))
flag = groupimpl.isMemberRecurse(principal, vector);
}
else
if(principal1 instanceof Group)
{
Group group1 = (Group)principal1;
if(!vector.contains(group1))
flag = group1.isMember(principal);
}
if(flag)
return flag;
}
return false;
}
示例4: hasRole
import java.security.acl.Group; //導入方法依賴的package包/類
public boolean hasRole(String role) {
tryLogin();
for (Group sg : getSubject().getPrincipals(Group.class)) {
if (ROLES_GROUP.equals(sg.getName())) {
return sg.isMember(new Role(role));
}
}
return false;
}
示例5: isSubjectGranted
import java.security.acl.Group; //導入方法依賴的package包/類
/**
* Tests whether the passed subject has sufficient roles.
*
* @param subject
* the subject to test.
* @param securable
* the securable to test.
* @return true if the subject has sufficient privilege.
*/
public static boolean isSubjectGranted(Subject subject, ISecurable securable) {
if (securable == null) {
return true;
}
Collection<String> grantedRoles = securable.getGrantedRoles();
if (grantedRoles == null) {
return true;
}
if (subject == null) {
return false;
}
grantedRoles = new HashSet<>(grantedRoles);
Collection<String> ungrantedRoles = new HashSet<>();
for (String role : new HashSet<>(grantedRoles)) {
if (role.startsWith("!")) {
grantedRoles.remove(role);
ungrantedRoles.add(role.substring(1));
}
}
Group subjectRoles = getRolesGroup(subject);
if (subjectRoles != null) {
boolean granted = false;
if (!grantedRoles.isEmpty()) {
for (String grantedRole : grantedRoles) {
if (subjectRoles.isMember(new SimplePrincipal(grantedRole))) {
granted = true;
break;
}
}
}
if (!granted && !ungrantedRoles.isEmpty()) {
granted = true;
for (String ungrantedRole : ungrantedRoles) {
if (subjectRoles.isMember(new SimplePrincipal(ungrantedRole))) {
granted = false;
break;
}
}
}
return granted;
}
return false;
}