本文整理匯總了Java中java.security.acl.Group類的典型用法代碼示例。如果您正苦於以下問題:Java Group類的具體用法?Java Group怎麽用?Java Group使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Group類屬於java.security.acl包,在下文中一共展示了Group類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getUseridFromJAASSubject
import java.security.acl.Group; //導入依賴的package包/類
private static String getUseridFromJAASSubject() {
Subject subject = Subject.getSubject(AccessController.getContext());
LOGGER.trace("Subject of caller: {}", subject);
if (subject != null) {
Set<Principal> principals = subject.getPrincipals();
LOGGER.trace("Public principals of caller: {}", principals);
for (Principal pC : principals) {
if (!(pC instanceof Group)) {
String userIdFound = pC.getName();
String userIdUsed = userIdFound;
if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds() && userIdFound != null) {
userIdUsed = userIdFound.toLowerCase();
}
LOGGER.trace("Found User id {}. Returning User id {} ", userIdFound, userIdUsed);
return userIdUsed;
}
}
}
LOGGER.trace("No userid found in subject!");
return null;
}
示例2: getGroupIds
import java.security.acl.Group; //導入依賴的package包/類
public static List<String> getGroupIds() {
Subject subject = Subject.getSubject(AccessController.getContext());
LOGGER.trace("Subject of caller: {}", subject);
List<String> groupIds = new ArrayList<>();
if (subject != null) {
Set<Group> groups = subject.getPrincipals(Group.class);
LOGGER.trace("Public groups of caller: {}", groups);
for (Principal group : groups) {
String groupNameFound = group.getName();
String groupNameReturned = groupNameFound;
if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds() && groupNameFound != null) {
groupNameReturned = groupNameFound.toLowerCase();
}
LOGGER.trace("Found group id {}. Returning group Id: {}", groupNameFound, groupNameReturned);
groupIds.add(groupNameReturned);
}
return groupIds;
}
LOGGER.trace("No groupids found in subject!");
return groupIds;
}
示例3: createGroup
import java.security.acl.Group; //導入依賴的package包/類
/**
* Find or create a Group with the given name. Subclasses should use this method to locate the 'Roles' group or
* create additional types of groups.
*
* @return A named Group from the principals set.
*/
private Group createGroup(String name, Set<Principal> principals) {
Group roles = null;
for (Principal principal : principals) {
if (principal instanceof Group) {
Group grp = (Group) principal;
if (grp.getName().equals(name)) {
roles = grp;
break;
}
}
}
// If we did not find a group create one
if (roles == null) {
roles = new SimpleGroup(name);
principals.add(roles);
}
return roles;
}
示例4: checkPrincipal
import java.security.acl.Group; //導入依賴的package包/類
public boolean checkPrincipal(Object identity) {
if (identity != null && identity instanceof OIDCPrincipal) {
super.loginOk = true;
this.identity = (OIDCPrincipal) identity;
Group roles = new SimpleGroup(SecurityConstants.ROLES_IDENTIFIER);
if (identity != null && rolesClaimName != null) {
Object rolesClaim = this.identity.getClaims().get(rolesClaimName);
if (rolesClaim instanceof JSONArray) {
((List<String>) rolesClaim).forEach(r -> roles.addMember(new SimplePrincipal(r)));
}
}
this.roleSets = new Group[] { roles };
return true;
}
return false;
}
示例5: postLogin
import java.security.acl.Group; //導入依賴的package包/類
/**
* Set session variables after user login
*
* @throws Exception
*/
private void postLogin(User user) {
log.debug("Configuring application after user '{0}' login", user.getUid());
GluuCustomPerson person = findPersonByDn(user.getDn());
Contexts.getSessionContext().set(OxTrustConstants.CURRENT_PERSON, person);
// Set user roles
GluuUserRole[] userRoles = securityService.getUserRoles(user);
if (ArrayHelper.isNotEmpty(userRoles)) {
log.debug("Get '{0}' user roles", Arrays.toString(userRoles));
} else {
log.debug("Get 0 user roles");
}
for (GluuUserRole userRole : userRoles) {
identity.addRole(userRole.getRoleName());
}
if (log.isDebugEnabled()) {
for (Group sg : identity.getSubject().getPrincipals(java.security.acl.Group.class)) {
if ("Roles".equals(sg.getName())) {
log.debug("Using next user roles: '{0}'", sg.members());
break;
}
}
}
}
示例6: equals
import java.security.acl.Group; //導入依賴的package包/類
@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (super.equals(obj))
return true;
if (!Group.class.isAssignableFrom(obj.getClass()))
return false;
Group other = (Group) obj;
String otherGroupName = other.getName();
if(otherGroupName == null)
return false;
if (primaryLdapGroupName == null)
return false;
return primaryLdapGroupName.equals(otherGroupName);
}
示例7: apply
import java.security.acl.Group; //導入依賴的package包/類
@Override
public Boolean apply(Principal obj)
{
if (this == obj)
return true;
if (super.equals(obj))
return true;
if (!Group.class.isAssignableFrom(obj.getClass()))
return false;
Group other = (Group) obj;
String otherGroupName = other.getName();
if(otherGroupName == null)
return false;
if (primaryLdapGroupName == null)
return false;
return primaryLdapGroupName.equals(otherGroupName);
}
示例8: getRoles
import java.security.acl.Group; //導入依賴的package包/類
public static String[] getRoles(Subject subject, String[] defalt) {
ArrayList<String> roles = new ArrayList<String>();
Set<Group> principals = subject.getPrincipals(Group.class);
if ((principals != null) && (principals.size() > 0)) {
for (Group group : principals) {
if (group.getName().equalsIgnoreCase("roles")) { //$NON-NLS-1$
Enumeration<? extends Principal> members = group.members();
while(members.hasMoreElements()) {
Principal member = members.nextElement();
roles.add(member.getName());
}
}
}
return roles.toArray(new String[roles.size()]);
}
return defalt;
}
示例9: getUserRoles
import java.security.acl.Group; //導入依賴的package包/類
private Set<String> getUserRoles() {
if (getSubject() == null) {
return Collections.emptySet();
}
Set<String> roles = new HashSet<String>();
Set<Principal> principals = getSubject().getPrincipals();
for(Principal p: principals) {
// this JBoss specific, but no code level dependencies
if ((p instanceof Group) && p.getName().equals("Roles")){ //$NON-NLS-1$
Group g = (Group)p;
Enumeration<? extends Principal> rolesPrinciples = g.members();
while(rolesPrinciples.hasMoreElements()) {
roles.add(rolesPrinciples.nextElement().getName());
}
}
}
return roles;
}
示例10: getCallerPrincipal
import java.security.acl.Group; //導入依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
public Principal getCallerPrincipal(String securityDomain) {
Principal callerPrincipal = null;
Subject subject = getSubject(securityDomain, false);
if (subject != null) {
outerLoop : for (Principal principal : subject.getPrincipals()) {
if (principal instanceof Group) {
Group group = (Group)principal;
if (group.getName().equalsIgnoreCase(CALLER_PRINCIPAL)) {
Enumeration<? extends Principal> members = group.members();
while (members.hasMoreElements()) {
callerPrincipal = members.nextElement();
break outerLoop;
}
}
} else if (callerPrincipal == null && principal != null) {
// the second case (the simple name comparison) is here to support Karaf
if (principal instanceof UserPrincipal || principal.getClass().getSimpleName().equals("UserPrincipal")) {
callerPrincipal = principal;
}
}
}
}
return callerPrincipal;
}
示例11: isCallerInRole
import java.security.acl.Group; //導入依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
public boolean isCallerInRole(String roleName, String securityDomain) {
Subject subject = getSubject(securityDomain, false);
if (subject != null) {
for (Principal principal : subject.getPrincipals()) {
if (principal instanceof Group) {
Group group = (Group)principal;
if (group.getName().equalsIgnoreCase(ROLES)) {
Enumeration<? extends Principal> roles = group.members();
while (roles.hasMoreElements()) {
Principal role = roles.nextElement();
if (role.getName().equals(roleName)) {
return true;
}
}
}
}
}
}
return false;
}
示例12: transfer
import java.security.acl.Group; //導入依賴的package包/類
/**
* Transfers Principals, private credentials, and public credentials from one Subject to another.
* @param fromSubject the from Subject
* @param toSubject the to Subject
*/
protected void transfer(Subject fromSubject, Subject toSubject) {
if (toSubject != null && fromSubject != null && toSubject != fromSubject && !toSubject.equals(fromSubject)) {
Set<Principal> toPrincipals = toSubject.getPrincipals();
Group toRolesGroup = null;
for (Principal fromPrincipal : fromSubject.getPrincipals()) {
if (fromPrincipal instanceof Group && GroupPrincipal.ROLES.equals(fromPrincipal.getName())) {
Group fromRolesGroup = (Group)fromPrincipal;
if (toRolesGroup == null) {
toRolesGroup = getRolesGroup(toSubject);
}
if (toRolesGroup == fromRolesGroup) {
continue;
}
for (Principal fromRole : Collections.list(fromRolesGroup.members())) {
RolePrincipal toRole = fromRole instanceof RolePrincipal ? (RolePrincipal)fromRole : new RolePrincipal(fromRole.getName());
toRolesGroup.addMember(toRole);
}
} else {
toPrincipals.add(fromPrincipal);
}
}
toSubject.getPrivateCredentials().addAll(fromSubject.getPrivateCredentials());
toSubject.getPublicCredentials().addAll(fromSubject.getPublicCredentials());
}
}
示例13: getRolesGroup
import java.security.acl.Group; //導入依賴的package包/類
/**
* Gets the Group with the name "Roles" from the specified Subject, creating one if not pre-existent.
* @param subject the subject
* @return the "Roles" Group
*/
private Group getRolesGroup(Subject subject) {
Group rolesGroup = null;
Set<Group> groups = subject.getPrincipals(Group.class);
for (Group group : groups) {
if (GroupPrincipal.ROLES.equals(group.getName())) {
rolesGroup = group;
break;
}
}
if (rolesGroup == null) {
rolesGroup = new GroupPrincipal(GroupPrincipal.ROLES);
subject.getPrincipals().add(rolesGroup);
}
return rolesGroup;
}
示例14: getGroupMembership
import java.security.acl.Group; //導入依賴的package包/類
private Set<Group> getGroupMembership(Authorizable authorizable) {
Set<java.security.acl.Group> groupPrincipals = new HashSet<Group>();
try {
Iterator<org.apache.jackrabbit.api.security.user.Group> groups = authorizable.memberOf();
while (groups.hasNext()) {
Principal grPrincipal = groups.next().getPrincipal();
if (grPrincipal instanceof Group) {
groupPrincipals.add((Group) grPrincipal);
}
}
} catch (RepositoryException e) {
log.debug(e.getMessage());
}
groupPrincipals.add(EveryonePrincipal.getInstance());
return groupPrincipals;
}
示例15: createGroup
import java.security.acl.Group; //導入依賴的package包/類
/** Find or create a Group with the given name. Subclasses should use this
method to locate the 'Roles' group or create additional types of groups.
@return A named Group from the principals set.
*/
protected Group createGroup(String name, Set<Principal> principals)
{
Group roles = null;
Iterator<Principal> iter = principals.iterator();
while( iter.hasNext() )
{
Object next = iter.next();
if( (next instanceof Group) == false )
continue;
Group grp = (Group) next;
if( grp.getName().equals(name) )
{
roles = grp;
break;
}
}
// If we did not find a group create one
if( roles == null )
{
roles = new SimpleGroup(name);
principals.add(roles);
}
return roles;
}