Search in sources :

Example 11 with SimpleGroup

use of org.apache.cxf.common.security.SimpleGroup 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) Principal(java.security.Principal) SimplePrincipal(org.apache.cxf.common.security.SimplePrincipal) Test(org.junit.Test)

Example 12 with SimpleGroup

use of org.apache.cxf.common.security.SimpleGroup 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);
    Group group = new SimpleGroup("Roles", p);
    Group 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 : Group(java.security.acl.Group) SimpleGroup(org.apache.cxf.common.security.SimpleGroup) SimpleGroup(org.apache.cxf.common.security.SimpleGroup) 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 13 with SimpleGroup

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

the class TestUserPasswordLoginModule method login.

@Override
public boolean login() throws LoginException {
    NameCallback nameCallback = new NameCallback("User");
    PasswordCallback passwordCallback = new PasswordCallback("Password", false);
    Callback[] callbacks = new Callback[] { nameCallback, passwordCallback };
    try {
        this.callbackHandler.handle(callbacks);
    } catch (IOException e) {
        throw new LoginException(e.getMessage());
    } catch (UnsupportedCallbackException e) {
        throw new LoginException(e.getMessage());
    }
    String userName = nameCallback.getName();
    String password = new String(passwordCallback.getPassword());
    if (!TESTUSER.equals(userName)) {
        throw new LoginException("wrong username");
    }
    if (!TESTPASS.equals(password)) {
        throw new LoginException("wrong password");
    }
    subject.getPrincipals().add(new SimplePrincipal(userName));
    subject.getPrincipals().add(new SimpleGroup(TESTGROUP));
    return true;
}
Also used : NameCallback(javax.security.auth.callback.NameCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) NameCallback(javax.security.auth.callback.NameCallback) Callback(javax.security.auth.callback.Callback) PasswordCallback(javax.security.auth.callback.PasswordCallback) LoginException(javax.security.auth.login.LoginException) SimpleGroup(org.apache.cxf.common.security.SimpleGroup) IOException(java.io.IOException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) SimplePrincipal(org.apache.cxf.common.security.SimplePrincipal)

Aggregations

SimpleGroup (org.apache.cxf.common.security.SimpleGroup)13 Subject (javax.security.auth.Subject)10 SimplePrincipal (org.apache.cxf.common.security.SimplePrincipal)9 Principal (java.security.Principal)6 Test (org.junit.Test)4 Group (java.security.acl.Group)2 HashSet (java.util.HashSet)2 IOException (java.io.IOException)1 Callback (javax.security.auth.callback.Callback)1 NameCallback (javax.security.auth.callback.NameCallback)1 PasswordCallback (javax.security.auth.callback.PasswordCallback)1 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)1 LoginException (javax.security.auth.login.LoginException)1 Claim (org.apache.cxf.rt.security.claims.Claim)1 SAMLClaim (org.apache.cxf.rt.security.saml.claims.SAMLClaim)1 LoginSecurityContext (org.apache.cxf.security.LoginSecurityContext)1 WSUsernameTokenPrincipalImpl (org.apache.wss4j.common.principal.WSUsernameTokenPrincipalImpl)1 UsernameToken (org.apache.wss4j.dom.message.token.UsernameToken)1 Credential (org.apache.wss4j.dom.validate.Credential)1 UsernameSecurityTokenImpl (org.apache.wss4j.stax.impl.securityToken.UsernameSecurityTokenImpl)1