List of usage examples for java.security.acl Group addMember
public boolean addMember(Principal user);
From source file:org.betaconceptframework.astroboa.resourceapi.utility.ContentApiUtils.java
public static Subject createSubjectForSystemUserAndItsRoles(String cmsRepositoryId) { Subject subject = new Subject(); //System identity subject.getPrincipals().add(new IdentityPrincipal(IdentityPrincipal.SYSTEM)); //Load default roles for SYSTEM USER //Must return at list one group named "Roles" in order to be Group rolesPrincipal = new CmsGroup(AstroboaPrincipalName.Roles.toString()); for (CmsRole cmsRole : CmsRole.values()) { rolesPrincipal.addMember(new CmsPrincipal(CmsRoleAffiliationFactory.INSTANCE .getCmsRoleAffiliationForRepository(cmsRole, cmsRepositoryId))); }/*from w w w.jav a2 s.c o m*/ subject.getPrincipals().add(rolesPrincipal); return subject; }
From source file:be.fedict.eid.applet.beta.service.AuthorizationLoginModule.java
public boolean commit() throws LoginException { this.subject.getPrincipals().add(this.principal); /*//w w w .jav a2s . co m * JBoss Roles */ Group roleGroup = new SimpleGroup("Roles"); NamePrincipal adminRole = new NamePrincipal("admin"); roleGroup.addMember(adminRole); this.subject.getPrincipals().add(roleGroup); return true; }
From source file:org.jspresso.hrsample.backend.BackTestStartup.java
private Subject createTestSubject() { Subject testSubject = new Subject(); UserPrincipal p = new UserPrincipal("demo"); testSubject.getPrincipals().add(p);//from w w w . j a va 2 s .c o m 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; }
From source file:org.betaconceptframework.astroboa.console.security.IdentityStoreRunAsSystem.java
private Subject createSubjectForSystemUserAndItsRoles(String cmsRepositoryId) { Subject subject = new Subject(); //System identity subject.getPrincipals().add(new IdentityPrincipal(IdentityPrincipal.SYSTEM)); //Load default roles for SYSTEM USER //Must return at list one group named "Roles" in order to be Group rolesPrincipal = new CmsGroup(AstroboaPrincipalName.Roles.toString()); for (CmsRole cmsRole : CmsRole.values()) { rolesPrincipal.addMember(new CmsPrincipal(CmsRoleAffiliationFactory.INSTANCE .getCmsRoleAffiliationForRepository(cmsRole, cmsRepositoryId))); }//from w w w . java 2s . co m subject.getPrincipals().add(rolesPrincipal); return subject; }
From source file:de.adorsys.oauth.loginmodule.HTTPAuthenticationLoginModule.java
private SimplePrincipal populateSubject(String principalId, Iterable<Object> roles) { preparedPrincipals = new ArrayList<>(); SimplePrincipal principal = new SimplePrincipal(principalId); preparedPrincipals.add(principal);/*from w ww. j a va2s. co m*/ Group callerGroup = new SimpleGroup("CallerPrincipal"); preparedPrincipals.add(callerGroup); callerGroup.addMember(principal); Group rolesGroup = new SimpleGroup("Roles"); preparedPrincipals.add(rolesGroup); if (roles != null) { for (Object object : roles) { if (object instanceof String) { rolesGroup.addMember(new SimplePrincipal((String) object)); } } } return principal; }
From source file:org.chililog.server.engine.JAASLoginModule.java
/** * <p>/*from w w w . j av a 2 s . c o m*/ * We check the credentials against the repository. By convention, the username is the repository name and the * password is either the publisher or subscriber password. The role assigned to the user is constructed from the * combination of username and publisher password. * </p> * * @return Returns true if this method succeeded, or false if this LoginModule should be ignored. */ public boolean login() throws LoginException { try { // // This code is from org.hornetq.spi.core.security.JAASSecurityManager.getAuthenticatedSubject(); // It is how HornetQ uses JAAS to authenticate // // Subject subject = new Subject(); // if (user != null) // { // subject.getPrincipals().add(principal); // } // subject.getPrivateCredentials().add(passwordChars); // LoginContext lc = new LoginContext(configurationName, subject, callbackHandler, config); // Get the user name Iterator<Principal> iterator = _subject.getPrincipals().iterator(); String username = iterator.next().getName(); if (StringUtils.isBlank(username)) { throw new FailedLoginException("Username is requried."); } // Get the password Iterator<char[]> iterator2 = _subject.getPrivateCredentials(char[].class).iterator(); char[] passwordChars = iterator2.next(); String password = new String(passwordChars); if (StringUtils.isBlank(password)) { throw new FailedLoginException("Password is requried."); } // Check if system user if (username.equals(_systemUsername) && password.equals(_systemPassword)) { Group roles = new SimpleGroup("Roles"); roles.addMember(new SimplePrincipal(UserBO.SYSTEM_ADMINISTRATOR_ROLE_NAME)); _subject.getPrincipals().add(roles); return true; } // Let's validate non-system user DB db = MongoConnection.getInstance().getConnection(); UserBO user = UserController.getInstance().tryGetByUsername(db, username); if (user == null) { throw new FailedLoginException("Invalid username or password."); } if (StringUtils.isBlank(password) || !user.validatePassword(password)) { throw new FailedLoginException("Invalid username or password."); } // Add role Group roles = new SimpleGroup("Roles"); for (String role : user.getRoles()) { roles.addMember(new SimplePrincipal(role)); } _subject.getPrincipals().add(roles); // OK return true; } catch (Exception ex) { throw new LoginException(ex.getMessage()); } }
From source file:org.josso.jb5.agent.JBossSSOGatewayLoginModule.java
/** * The Subject saved in the previously executed initialize() method, is modified * by adding a new special Group called "Roles" whose members are the SSO user roles. * JBoss will fetch user roles by examining such group. * /*from ww w .j a va 2s. c o m*/ * @see org.josso.jaspi.agent.SSOGatewayLoginModule#logout() */ public boolean commit() throws LoginException { boolean rc = false; rc = super.commit(); Set ssoRolePrincipals = _savedSubject.getPrincipals(SSORole.class); Group targetGrp = new BaseRoleImpl("Roles"); Iterator i = ssoRolePrincipals.iterator(); while (i.hasNext()) { Principal p = (Principal) i.next(); targetGrp.addMember(p); // Add user role to "Roles" group } // Add the "Roles" group to the Subject so that JBoss can fetch user roles. _savedSubject.getPrincipals().add(targetGrp); Set ssoUserPrincipals = _savedSubject.getPrincipals(SSOUser.class); Group callerPrincipal = new BaseRoleImpl("CallerPrincipal"); Iterator j = ssoUserPrincipals.iterator(); if (j.hasNext()) { Principal user = (Principal) j.next(); callerPrincipal.addMember(user); } // Add the "CallerPrincipal" group to the Subject so that JBoss can fetch user. _savedSubject.getPrincipals().add(callerPrincipal); return rc; }
From source file:org.gatein.sso.saml.plugin.SAML2IdpLoginModule.java
public boolean commit() throws LoginException { String username = (String) sharedState.get("javax.security.auth.login.name"); Set<Principal> principals = subject.getPrincipals(); Group roleGroup = new SimpleGroup("Roles"); for (String role : getRoles(username)) { roleGroup.addMember(new SimplePrincipal(role)); }//from www . ja va2s . co m // group principal principals.add(roleGroup); // username principal principals.add(new SimplePrincipal(username)); return true; }
From source file:org.josso.jb32.agent.JBossSSOGatewayLoginModule.java
public boolean commit() throws LoginException { boolean rc = false; // HashMap setsMap = new HashMap(); rc = super.commit(); Set ssoRolePrincipals = _savedSubject.getPrincipals(SSORole.class); Group targetGrp = new BaseRoleImpl("Roles"); Iterator i = ssoRolePrincipals.iterator(); while (i.hasNext()) { Principal p = (Principal) i.next(); targetGrp.addMember(p); // Add user role to "Roles" group }// w w w .j a v a2s. c o m // Add the "Roles" group to the Subject so that JBoss can fetch user roles. _savedSubject.getPrincipals().add(targetGrp); return rc; }
From source file:org.josso.jb4.agent.JBossSSOGatewayLoginModule.java
public boolean commit() throws LoginException { boolean rc = false; // HashMap setsMap = new HashMap(); rc = super.commit(); Set ssoRolePrincipals = _savedSubject.getPrincipals(SSORole.class); Group targetGrp = new BaseRoleImpl("Roles"); Iterator i = ssoRolePrincipals.iterator(); while (i.hasNext()) { Principal p = (Principal) i.next(); targetGrp.addMember(p); // Add user role to "Roles" group }/*ww w .j a v a 2 s. c o m*/ // Add the "Roles" group to the Subject so that JBoss can fetch user roles. _savedSubject.getPrincipals().add(targetGrp); Set ssoUserPrincipals = _savedSubject.getPrincipals(SSOUser.class); Group callerPrincipal = new BaseRoleImpl("CallerPrincipal"); Iterator j = ssoUserPrincipals.iterator(); if (j.hasNext()) { Principal user = (Principal) j.next(); callerPrincipal.addMember(user); } // Add the "CallerPrincipal" group to the Subject so that JBoss can fetch user. _savedSubject.getPrincipals().add(callerPrincipal); return rc; }