Search in sources :

Example 21 with SimplePrincipal

use of org.apache.cxf.common.security.SimplePrincipal in project cxf by apache.

the class DefaultSecurityContextTest method testUserInRole3.

@Test
public void testUserInRole3() {
    Subject s = new Subject();
    Principal p = new SimplePrincipal("Barry");
    s.getPrincipals().add(p);
    GroupPrincipal group = new SimpleGroup("Roles", p);
    GroupPrincipal subgroup = new SimpleGroup("subgroup");
    subgroup.addMember(new SimpleGroup("friend"));
    group.addMember(subgroup);
    s.getPrincipals().add(group);
    assertTrue(new DefaultSecurityContext(p, s).isUserInRole("friend"));
}
Also used : GroupPrincipal(org.apache.cxf.common.security.GroupPrincipal) 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) Test(org.junit.Test)

Example 22 with SimplePrincipal

use of org.apache.cxf.common.security.SimplePrincipal in project cxf by apache.

the class DefaultSecurityContextTest method testUserInRole.

@Test
public void testUserInRole() {
    Subject s = new Subject();
    Principal p = new SimplePrincipal("Barry");
    s.getPrincipals().add(p);
    s.getPrincipals().add(new SimpleGroup("friend", p));
    assertTrue(new DefaultSecurityContext(p, s).isUserInRole("friend"));
}
Also used : 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) Test(org.junit.Test)

Example 23 with SimplePrincipal

use of org.apache.cxf.common.security.SimplePrincipal in project cxf by apache.

the class RolePrefixSecurityContextImplTest method testUserInRoleWithRolePrincipal.

@Test
public void testUserInRoleWithRolePrincipal() {
    Subject s = new Subject();
    Principal p = new SimplePrincipal("Barry");
    s.getPrincipals().add(p);
    s.getPrincipals().add(new RolePrincipal("friend"));
    assertTrue(new RolePrefixSecurityContextImpl(s, "RolePrincipal", "classname").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 24 with SimplePrincipal

use of org.apache.cxf.common.security.SimplePrincipal in project cxf by apache.

the class RolePrefixSecurityContextImplTest 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 SimplePrincipal("role_friend"));
    roles.add(new SimplePrincipal("role_admin"));
    s.getPrincipals().addAll(roles);
    LoginSecurityContext context = new RolePrefixSecurityContextImpl(s, "role_");
    assertTrue(context.isUserInRole("role_friend"));
    assertTrue(context.isUserInRole("role_admin"));
    assertFalse(context.isUserInRole("role_bar"));
    Set<Principal> roles2 = context.getUserRoles();
    assertEquals(roles2, roles);
}
Also used : 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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 25 with SimplePrincipal

use of org.apache.cxf.common.security.SimplePrincipal in project cxf by apache.

the class RolePrefixSecurityContextImplTest method testUserInRole.

@Test
public void testUserInRole() {
    Subject s = new Subject();
    Principal p = new SimplePrincipal("Barry");
    s.getPrincipals().add(p);
    s.getPrincipals().add(new SimplePrincipal("role_friend"));
    assertTrue(new RolePrefixSecurityContextImpl(s, "role_").isUserInRole("role_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)

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