本文整理匯總了Java中java.security.acl.Group.addMember方法的典型用法代碼示例。如果您正苦於以下問題:Java Group.addMember方法的具體用法?Java Group.addMember怎麽用?Java Group.addMember使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.security.acl.Group
的用法示例。
在下文中一共展示了Group.addMember方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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());
}
}
示例2: parseGroupMembers
import java.security.acl.Group; //導入方法依賴的package包/類
/** Parse the comma delimited roles names given by value and add them to
* group. The type of Principal created for each name is determined by
* the createIdentity method.
*
* @see AbstractServerLoginModule#createIdentity(String)
*
* @param group - the Group to add the roles to.
* @param roles - the comma delimited role names.
*/
static void parseGroupMembers(Group group, String roles, AbstractServerLoginModule aslm)
{
StringTokenizer tokenizer = new StringTokenizer(roles, ",");
while (tokenizer.hasMoreTokens())
{
String token = tokenizer.nextToken();
try
{
Principal p = aslm.createIdentity(token);
group.addMember(p);
}
catch (Exception e)
{
PicketBoxLogger.LOGGER.debugFailureToCreatePrincipal(token, e);
}
}
}
示例3: addRole
import java.security.acl.Group; //導入方法依賴的package包/類
/**
* Adds a role to the authenticated user.
*
* @param role
* The name of the role to add
*/
public boolean addRole(String role) {
if (role == null || "".equals(role)) {
return false;
}
if (!isLoggedIn()) {
return false;
} else {
for (Group sg : getSubject().getPrincipals(Group.class)) {
if (ROLES_GROUP.equals(sg.getName())) {
return sg.addMember(new Role(role));
}
}
SimpleGroup roleGroup = new SimpleGroup(ROLES_GROUP);
roleGroup.addMember(new Role(role));
getSubject().getPrincipals().add(roleGroup);
return true;
}
}
示例4: fixPrincipal
import java.security.acl.Group; //導入方法依賴的package包/類
protected ContributorPrincipal fixPrincipal() {
log.log(Level.FINEST, "Remove CAS principal and default group. Assertion name: {0}", this.assertion.getPrincipal().getName());
this.subject.getPrincipals().remove(new AssertionPrincipal(this.assertion.getPrincipal().getName(), this.assertion));
this.subject.getPrincipals().remove(new SimpleGroup(this.principalGroupName));
log.log(Level.FINEST, "Add ContributorPrincipal");
final ContributorPrincipal contributorPrincipal = new ContributorPrincipal(this.assertion.getPrincipal().getName(), this.assertion);
this.subject.getPrincipals().add(contributorPrincipal);
final Group principalGroup = new SimpleGroup(this.principalGroupName);
principalGroup.addMember(contributorPrincipal);
this.subject.getPrincipals().add(principalGroup);
return contributorPrincipal;
}
示例5: commit
import java.security.acl.Group; //導入方法依賴的package包/類
/**
* Method to commit the authentication process (phase 2).
*/
@Override
public boolean commit() throws LoginException {
if (loginOK == false) {
return false;
}
/*
* If the login method completed successfully as indicated by
* loginOK == true, this method adds the identity value to the subject's principals set. It also adds the
* members of
* each Group returned by getRoleSets() to the subject's principals Set.
*/
Set<Principal> principals = subject.getPrincipals();
principals.add(identity);
for (Group group : getRoleSets()) {
String name = group.getName();
Group subjectGroup = createGroup(name, principals);
// Copy the group members to the Subject group
Enumeration<? extends Principal> members = group.members();
while (members.hasMoreElements()) {
Principal role = members.nextElement();
subjectGroup.addMember(role);
}
}
UniversalLoginModule.log.info("User logged in: " + getUserName());
return true;
}
示例6: getRoleSets
import java.security.acl.Group; //導入方法依賴的package包/類
/**
* Obtiene roles usuario (modificado para que no llame a createIdentity al crear cada role)
*/
protected Group[] getRoleSets() throws LoginException
{
Principal principal = getIdentity ();
if ( ! (principal instanceof MockPrincipal) )
{
if (log.isTraceEnabled()) log.trace("Principal "+principal+" not a MockPrincipal");
return new Group[0];
}
String username = getUsername();
List roles = null;
try {
roles = getUserRoles(username);
} catch (Exception e) {
log.error("Excepcion obteniendo roles",e);
throw new LoginException("Excepcion obteniendo roles");
}
Group rolesGroup = new SimpleGroup("Roles");
for (Iterator iterator = roles.iterator();iterator.hasNext();){
String roleName = (String) iterator.next();
rolesGroup.addMember(new SimplePrincipal(roleName));
}
HashMap setsMap = new HashMap();
setsMap.put("Roles", rolesGroup);
// Montamos grupo "CallerPrincipal"
Group principalGroup = new SimpleGroup("CallerPrincipal");
principalGroup.addMember(principal);
setsMap.put("CallerPrincipal", principalGroup);
// Devolvemos respuesta
Group roleSets[] = new Group[setsMap.size()];
setsMap.values().toArray(roleSets);
return roleSets;
}
示例7: getRoleSets
import java.security.acl.Group; //導入方法依賴的package包/類
/**
* Obtiene roles usuario (modificado para que no llame a createIdentity al crear cada role)
*/
protected Group[] getRoleSets() throws LoginException
{
Principal principal = getIdentity ();
if ( ! (principal instanceof MockPrincipal) )
{
if (log.isTraceEnabled()) log.trace("Principal "+principal+" not a MockPrincipal");
return new Group[0];
}
String username = getUsername();
List roles = null;
try {
roles = getUserRoles(username);
} catch (Exception e) {
log.error("Excepcion obteniendo roles",e);
throw new LoginException("Excepcion obteniendo roles");
}
Group rolesGroup = new SimpleGroup("Roles");
for (Iterator iterator = roles.iterator();iterator.hasNext();){
String roleName = (String) iterator.next();
rolesGroup.addMember(new SimplePrincipal(roleName));
}
HashMap setsMap = new HashMap();
setsMap.put("Roles", rolesGroup);
// Montamos grupo "CallerPrincipal"
Group principalGroup = new SimpleGroup("CallerPrincipal");
principalGroup.addMember(principal);
setsMap.put("CallerPrincipal", principalGroup);
// Devolvemos respuesta
Group roleSets[] = new Group[setsMap.size()];
setsMap.values().toArray(roleSets);
return roleSets;
}
示例8: createTestSubject
import java.security.acl.Group; //導入方法依賴的package包/類
private Subject createTestSubject() {
Subject testSubject = new Subject();
UserPrincipal p = new UserPrincipal("demo");
testSubject.getPrincipals().add(p);
p.putCustomProperty(UserPrincipal.LANGUAGE_PROPERTY, "en");
Group rolesGroup = new SimpleGroup(SecurityHelper.ROLES_GROUP_NAME);
rolesGroup.addMember(new SimplePrincipal("administrator"));
testSubject.getPrincipals().add(rolesGroup);
return testSubject;
}
示例9: commit
import java.security.acl.Group; //導入方法依賴的package包/類
/**
* Method to commit the authentication process (phase 2). If the login
* method completed successfully as indicated by loginOk == true, this
* method adds the getIdentity() value to the subject getPrincipals() Set.
* It also adds the members of each Group returned by getRoleSets()
* to the subject getPrincipals() Set.
* @return true always.
*/
@Override
public boolean commit() throws LoginException {
Set<Principal> principals = this.subject.getPrincipals();
if (this.identity != null) {
principals.add(this.identity);
}
if (this.usernameIdentity != null) {
principals.add(this.usernameIdentity);
}
if (this.roles != null) {
for (Group group : this.roles) {
String name = group.getName();
Group subjectGroup = createGroup(name, principals);
if (subjectGroup instanceof NestableGroup) {
SimpleGroup sg = new SimpleGroup("Roles");
subjectGroup.addMember(sg);
subjectGroup = sg;
}
Enumeration<? extends Principal> members = group.members();
while (members.hasMoreElements()) {
Principal role = (Principal) members.nextElement();
subjectGroup.addMember(role);
}
}
}
return true;
}
示例10: addPrincipals
import java.security.acl.Group; //導入方法依賴的package包/類
/**
* Add principals passed via an enumeration into a group
* @param grp
* @param en
* @return
*/
public static Group addPrincipals(Group grp, Enumeration<? extends Principal> en)
{
while(en.hasMoreElements())
grp.addMember(en.nextElement());
return grp;
}
示例11: appendRoles
import java.security.acl.Group; //導入方法依賴的package包/類
private void appendRoles( Group group )
{
if( ! group.getName().equals( SecurityConstants.ROLES_IDENTIFIER ) )
return;
if(additionalRoles != null && !additionalRoles.isEmpty())
{
StringTokenizer st = new StringTokenizer( additionalRoles , "," );
while(st.hasMoreTokens())
{
group.addMember( new SimplePrincipal( st.nextToken().trim() ) );
}
}
}
示例12: mergeGroups
import java.security.acl.Group; //導入方法依賴的package包/類
private Group mergeGroups(Group a, Group b)
{
Group newGroup = b;
if(a != null)
{
Enumeration<? extends Principal> en = a.members();
while(en.hasMoreElements())
{
newGroup.addMember(en.nextElement());
}
}
return newGroup;
}
示例13: asGroup
import java.security.acl.Group; //導入方法依賴的package包/類
public Group asGroup()
{
try
{
Group gp = IdentityFactory.createGroup("Roles");
gp.addMember(IdentityFactory.createPrincipal(role.getRoleName()));
return gp;
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
示例14: getRoleSets
import java.security.acl.Group; //導入方法依賴的package包/類
@Override
protected Group[] getRoleSets() throws LoginException {
Group roles = new SimpleGroup("Roles");
Group callerPrincipal = new SimpleGroup("CallerPrincipal");
Group[] groups = { roles, callerPrincipal };
callerPrincipal.addMember(getIdentity());
return groups;
}
示例15: getRoleSets
import java.security.acl.Group; //導入方法依賴的package包/類
@Override
protected Group[] getRoleSets() throws LoginException
{
Group roles = new SimpleGroup("Roles");
Group callerPrincipal = new SimpleGroup("CallerPrincipal");
Group[] groups =
{roles, callerPrincipal};
callerPrincipal.addMember(getIdentity());
return groups;
}