use of org.apache.cxf.common.security.SimplePrincipal in project wildfly by wildfly.
the class SamlSecurityContextInInterceptor method handleMessage.
@Override
public void handleMessage(SoapMessage message) throws Fault {
final SecurityContext securityContext = message.get(SecurityContext.class);
final Principal principal = securityContext.getUserPrincipal();
final String name = principal.getName();
final Endpoint endpoint = message.getExchange().get(Endpoint.class);
final SecurityDomainContext securityDomainContext = endpoint.getSecurityDomainContext();
Principal simplePrincipal = new SimplePrincipal(name);
Subject subject = new Subject(false, Collections.singleton(simplePrincipal), Collections.emptySet(), Collections.emptySet());
securityDomainContext.pushSubjectContext(subject, simplePrincipal, null);
message.put(SecurityContext.class, new DefaultSecurityContext(simplePrincipal, subject));
}
use of org.apache.cxf.common.security.SimplePrincipal in project cxf by apache.
the class DeprecatedSecurityContextTest method testPrivateStaticGroup.
@Test
public void testPrivateStaticGroup() {
Subject s = new Subject();
Principal p = new SimplePrincipal("Barry");
s.getPrincipals().add(p);
// create a friend group and add Barry to this group
GroupWrapper test = new GroupWrapper("friend", "Barry");
s.getPrincipals().add(test.getGroup());
LoginSecurityContext context = new DefaultSecurityContext(p, s);
assertTrue(context.isUserInRole("Barry"));
}
use of org.apache.cxf.common.security.SimplePrincipal in project cxf by apache.
the class RolePrefixSecurityContextImplTest method testUserNotInRole.
@Test
public void testUserNotInRole() {
Subject s = new Subject();
Principal p = new SimplePrincipal("Barry");
s.getPrincipals().add(p);
assertFalse(new RolePrefixSecurityContextImpl(s, "").isUserInRole("friend"));
}
use of org.apache.cxf.common.security.SimplePrincipal in project cxf by apache.
the class DefaultSecurityContextTest method testMultipleRoles.
@Test
public void testMultipleRoles() {
Subject s = new Subject();
Principal p = new SimplePrincipal("Barry");
s.getPrincipals().add(p);
Set<Principal> roles = new HashSet<>();
roles.add(new SimpleGroup("friend", p));
roles.add(new SimpleGroup("admin", p));
s.getPrincipals().addAll(roles);
LoginSecurityContext context = new DefaultSecurityContext(p, s);
assertTrue(context.isUserInRole("friend"));
assertTrue(context.isUserInRole("admin"));
assertFalse(context.isUserInRole("bar"));
Set<Principal> roles2 = context.getUserRoles();
assertEquals(roles2, roles);
}
use of org.apache.cxf.common.security.SimplePrincipal in project cxf by apache.
the class DefaultSecurityContextTest method testUserInImplicitRoles.
@Test
public void testUserInImplicitRoles() {
Subject s = new Subject();
Principal p = new SimplePrincipal("Barry");
s.getPrincipals().add(p);
Principal role = new SimplePrincipal("friend");
s.getPrincipals().add(role);
LoginSecurityContext context = new DefaultSecurityContext(p, s);
assertTrue(context.isUserInRole("friend"));
assertFalse(context.isUserInRole("family"));
assertFalse(context.isUserInRole("Barry"));
}
Aggregations