Search in sources :

Example 6 with SimplePrincipal

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));
}
Also used : DefaultSecurityContext(org.apache.cxf.interceptor.security.DefaultSecurityContext) Endpoint(org.jboss.wsf.spi.deployment.Endpoint) SecurityContext(org.apache.cxf.security.SecurityContext) DefaultSecurityContext(org.apache.cxf.interceptor.security.DefaultSecurityContext) SimplePrincipal(org.apache.cxf.common.security.SimplePrincipal) Principal(java.security.Principal) SecurityDomainContext(org.jboss.wsf.spi.security.SecurityDomainContext) SimplePrincipal(org.apache.cxf.common.security.SimplePrincipal) Subject(javax.security.auth.Subject)

Example 7 with SimplePrincipal

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"));
}
Also used : GroupWrapper(org.apache.cxf.interceptor.security.test.GroupWrapper) LoginSecurityContext(org.apache.cxf.security.LoginSecurityContext) Subject(javax.security.auth.Subject) SimplePrincipal(org.apache.cxf.common.security.SimplePrincipal) Principal(java.security.Principal) SimplePrincipal(org.apache.cxf.common.security.SimplePrincipal) Test(org.junit.Test)

Example 8 with SimplePrincipal

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"));
}
Also used : Subject(javax.security.auth.Subject) SimplePrincipal(org.apache.cxf.common.security.SimplePrincipal) Principal(java.security.Principal) SimplePrincipal(org.apache.cxf.common.security.SimplePrincipal) Test(org.junit.Test)

Example 9 with SimplePrincipal

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);
}
Also used : LoginSecurityContext(org.apache.cxf.security.LoginSecurityContext) SimpleGroup(org.apache.cxf.common.security.SimpleGroup) Subject(javax.security.auth.Subject) SimplePrincipal(org.apache.cxf.common.security.SimplePrincipal) GroupPrincipal(org.apache.cxf.common.security.GroupPrincipal) Principal(java.security.Principal) SimplePrincipal(org.apache.cxf.common.security.SimplePrincipal) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with SimplePrincipal

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"));
}
Also used : LoginSecurityContext(org.apache.cxf.security.LoginSecurityContext) Subject(javax.security.auth.Subject) SimplePrincipal(org.apache.cxf.common.security.SimplePrincipal) GroupPrincipal(org.apache.cxf.common.security.GroupPrincipal) Principal(java.security.Principal) SimplePrincipal(org.apache.cxf.common.security.SimplePrincipal) Test(org.junit.Test)

Aggregations

SimplePrincipal (org.apache.cxf.common.security.SimplePrincipal)33 Principal (java.security.Principal)19 Subject (javax.security.auth.Subject)19 Test (org.junit.Test)13 SimpleGroup (org.apache.cxf.common.security.SimpleGroup)10 SecurityContext (org.apache.cxf.security.SecurityContext)9 GroupPrincipal (org.apache.cxf.common.security.GroupPrincipal)6 Message (org.apache.cxf.message.Message)6 LoginSecurityContext (org.apache.cxf.security.LoginSecurityContext)4 IOException (java.io.IOException)3 Callback (javax.security.auth.callback.Callback)3 NameCallback (javax.security.auth.callback.NameCallback)3 PasswordCallback (javax.security.auth.callback.PasswordCallback)3 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)3 LoginException (javax.security.auth.login.LoginException)3 Base64Exception (org.apache.cxf.common.util.Base64Exception)3 ClaimCollection (org.apache.cxf.rt.security.claims.ClaimCollection)3 HashSet (java.util.HashSet)2 CallbackHandler (javax.security.auth.callback.CallbackHandler)2 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)2