use of org.apache.openejb.core.security.jaas.GroupPrincipal in project tomee by apache.
the class TestLoginModule method commit.
public boolean commit() throws LoginException {
principals.add(new UserPrincipal(user));
principals.add(new GroupPrincipal(user));
subject.getPrincipals().addAll(principals);
user = null;
return true;
}
use of org.apache.openejb.core.security.jaas.GroupPrincipal in project tomee by apache.
the class AbstractSecurityService method isCallerInRole.
@Override
public boolean isCallerInRole(final String role) {
if (role == null) {
throw new IllegalArgumentException("Role must not be null");
}
final ThreadContext threadContext = ThreadContext.getThreadContext();
if (threadContext == null) {
return false;
}
final SecurityContext securityContext = threadContext.get(SecurityContext.class);
if ("**".equals(role)) {
// ie logged in
return securityContext != defaultContext;
}
final Set<Group> grps = securityContext.subject.getPrincipals(Group.class);
for (final Group grp : grps) {
if (grp.getName().equals(role)) {
return true;
}
}
final Set<GroupPrincipal> grpsp = securityContext.subject.getPrincipals(GroupPrincipal.class);
for (final GroupPrincipal grp : grpsp) {
if (grp.getName().equals(role)) {
return true;
}
}
return false;
}
Aggregations