Search in sources :

Example 1 with GroupPrincipal

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;
}
Also used : GroupPrincipal(org.apache.openejb.core.security.jaas.GroupPrincipal) UserPrincipal(org.apache.openejb.core.security.jaas.UserPrincipal)

Example 2 with GroupPrincipal

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;
}
Also used : GroupPrincipal(org.apache.openejb.core.security.jaas.GroupPrincipal) ThreadContext(org.apache.openejb.core.ThreadContext)

Aggregations

GroupPrincipal (org.apache.openejb.core.security.jaas.GroupPrincipal)2 ThreadContext (org.apache.openejb.core.ThreadContext)1 UserPrincipal (org.apache.openejb.core.security.jaas.UserPrincipal)1