本文整理汇总了Java中org.jboss.security.SimpleGroup类的典型用法代码示例。如果您正苦于以下问题:Java SimpleGroup类的具体用法?Java SimpleGroup怎么用?Java SimpleGroup使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SimpleGroup类属于org.jboss.security包,在下文中一共展示了SimpleGroup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkPrincipal
import org.jboss.security.SimpleGroup; //导入依赖的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;
}
示例2: commit
import org.jboss.security.SimpleGroup; //导入依赖的package包/类
@Override
public boolean commit() throws LoginException {
Set<RolePrincipal> kcRoles = subject.getPrincipals(RolePrincipal.class);
logger.info("commit invoked. Keycloak roles: " + kcRoles);
SimpleGroup wfRoles = new SimpleGroup("Roles");
for (RolePrincipal kcRole : kcRoles) {
wfRoles.addMember(new SimplePrincipal(kcRole.getName()));
}
subject.getPrincipals().add(wfRoles);
return true;
}
示例3: getRoleSets
import org.jboss.security.SimpleGroup; //导入依赖的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;
}
示例4: getRoleSets
import org.jboss.security.SimpleGroup; //导入依赖的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;
}
示例5: commit
import org.jboss.security.SimpleGroup; //导入依赖的package包/类
@Override
public boolean commit() throws LoginException {
subject.getPrincipals().add(jwtPrincipal);
SimpleGroup roles = new SimpleGroup("Roles");
for (String name : jwtPrincipal.getGroups()) {
roles.addMember(new SimplePrincipal(name));
}
subject.getPrincipals().add(roles);
sharedState.put("JsonWebToken", jwtPrincipal);
return super.commit();
}
示例6: getRoleSets
import org.jboss.security.SimpleGroup; //导入依赖的package包/类
@Override
protected Group[] getRoleSets() throws LoginException {
log.debug("Retrieving Groups");
HttpServletRequest request = null;
try {
request = (HttpServletRequest) PolicyContext.getContext("javax.servlet.http.HttpServletRequest");
} catch (PolicyContextException e) {
log.error("Could not load HttpServletRequest", e);
return null;
}
if (request == null) {
return null;
}
Attribute attr = (Attribute) request.getAttribute("UINSON_ROLES");
SimpleGroup group = new SimpleGroup("Roles");
if (attr != null) {
for (String val : attr.getValues()) {
group.addMember(new SimplePrincipal(val));
}
}
if (log.isDebugEnabled()) {
log.debug("Returning Groups : " + group);
}
return new Group[]{group};
}
示例7: getCallerPrincipleFromSubject
import org.jboss.security.SimpleGroup; //导入依赖的package包/类
/**
* Returns the caller principle from the subject
*
* @param subject
* the subject
* @return the caller principle from the subject
*/
public static Optional<String> getCallerPrincipleFromSubject(final Subject subject) {
Optional<String> caller = Optional.empty();
Stream<Principal> stream = subject.getPrincipals().stream();
Optional<Principal> principal = stream.filter(principle -> principle instanceof SimpleGroup).filter(group -> "CallerPrincipal".equals(group.getName())).findFirst();
if (principal.isPresent()) {
SimpleGroup simpleGroup = (SimpleGroup) principal.get();
if (simpleGroup.members().hasMoreElements()) {
caller = Optional.ofNullable(simpleGroup.members().nextElement().getName());
}
}
return caller;
}
示例8: getRoleNamesFromSubject
import org.jboss.security.SimpleGroup; //导入依赖的package包/类
/**
* Returns a set of role names from the subject
*
* @param subject
* the subject
* @return a set of role names from the subject
*/
public static ImmutableSet<String> getRoleNamesFromSubject(final Subject subject) {
if (subject == null || subject.getPrincipals() == null || subject.getPrincipals().isEmpty()) {
return ImmutableSet.of();
}
ImmutableSet.Builder<String> roles = ImmutableSet.builder();
Collections.list(((SimpleGroup) subject.getPrincipals().stream().filter(principle -> principle instanceof SimpleGroup).filter(group -> "Roles".equals(group.getName())).findFirst().get())
.members()).stream().forEach(role -> roles.add(role.getName()));
return roles.build();
}
示例9: createSubject
import org.jboss.security.SimpleGroup; //导入依赖的package包/类
private static Subject createSubject(Set<String> principals) {
final Subject subject = new Subject();
SimpleGroup simpleGroup = new SimpleGroup("Roles");
principals.stream().map(SimplePrincipal::new).forEach(simpleGroup::addMember);
subject.getPrincipals().add(simpleGroup);
return subject;
}
示例10: createSubjectWithRoles
import org.jboss.security.SimpleGroup; //导入依赖的package包/类
private static Subject createSubjectWithRoles(Set<String> principals) {
final Subject subject = new Subject();
SimpleGroup simpleGroup = new SimpleGroup("Roles");
principals.stream().map(SimplePrincipal::new).forEach(simpleGroup::addMember);
subject.getPrincipals().add(simpleGroup);
return subject;
}
示例11: createSubjectWithCallerPrinciple
import org.jboss.security.SimpleGroup; //导入依赖的package包/类
private static Subject createSubjectWithCallerPrinciple(String principal) {
final Subject subject = new Subject();
SimpleGroup simpleGroup = new SimpleGroup("CallerPrincipal");
simpleGroup.addMember(new SimplePrincipal(principal));
subject.getPrincipals().add(simpleGroup);
return subject;
}
示例12: createTestSubject
import org.jboss.security.SimpleGroup; //导入依赖的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;
}
示例13: commit
import org.jboss.security.SimpleGroup; //导入依赖的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;
}
示例14: getRoleSets
import org.jboss.security.SimpleGroup; //导入依赖的package包/类
/** Execute the rolesQuery against the dsJndiName to obtain the roles for
* the authenticated user.
* @return Group[] containing the sets of roles
*/
@Override
protected Group[] getRoleSets() throws LoginException {
Group[] roleSets = null;
if (isPrincipalsEmpty) {
roleSets = new Group[1];
SimpleGroup sg = new SimpleGroup("Roles");
try {
Principal p = createIdentity(roleForEmpty);
sg.addMember(p);
} catch (Exception e) {
if (trace) {
log.trace(String.format(
"Failed to create principal: %s", roleForEmpty), e);
}
}
roleSets[0] = sg;
return roleSets;
}
String username = getUsername();
if (trace) {
log.trace(String.format(
"getRoleSets using rolesQuery: %s, username: %s",
rolesQuery, username));
}
roleSets =
getRoleSets(username, dsJndiName, rolesQuery, suspendResume);
return roleSets;
}
示例15: commit
import org.jboss.security.SimpleGroup; //导入依赖的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 {
if (user != null) {
subject.getPrincipals().add(new SimplePrincipal(user));
if (role != null) {
SimpleGroup sg = new SimpleGroup("Roles");
sg.addMember(new SimplePrincipal(role));
subject.getPrincipals().add(sg);
}
}
return true;
}