Search in sources :

Example 41 with RolePrincipal

use of org.apache.karaf.jaas.boot.principal.RolePrincipal in project karaf by apache.

the class ConfigManagedServiceFactoryTest method CheckEditByArbitraryAttribute.

private void CheckEditByArbitraryAttribute() throws IOException, InvalidSyntaxException {
    executeCommand("config:edit '(test2=data2)'\n" + "config:property-set test1 data1new2\n" + "config:update", new RolePrincipal("manager"));
    Configuration config = readConfig();
    assertEquals("data1new2", config.getProperties().get("test1"));
    assertEquals("data2", config.getProperties().get("test2"));
}
Also used : Configuration(org.osgi.service.cm.Configuration) RolePrincipal(org.apache.karaf.jaas.boot.principal.RolePrincipal)

Example 42 with RolePrincipal

use of org.apache.karaf.jaas.boot.principal.RolePrincipal in project karaf by apache.

the class JdbcLoginModuleTest method testLoginModuleWithGroups.

@Test
public void testLoginModuleWithGroups() throws Exception {
    JDBCBackingEngine engine = new JDBCBackingEngine(dataSource);
    engine.addGroupRole("group1", "role2");
    engine.addUser("abc", "xyz");
    engine.addRole("abc", "role1");
    engine.addGroup("abc", "group1");
    JDBCLoginModule module = new JDBCLoginModule();
    Subject subject = new Subject();
    module.initialize(subject, new NamePasswordCallbackHandler("abc", "xyz"), null, options);
    module.login();
    module.commit();
    assertTrue(subject.getPrincipals().contains(new UserPrincipal("abc")));
    assertTrue(subject.getPrincipals().contains(new GroupPrincipal("group1")));
    assertTrue(subject.getPrincipals().contains(new RolePrincipal("role1")));
    assertTrue(subject.getPrincipals().contains(new RolePrincipal("role2")));
}
Also used : NamePasswordCallbackHandler(org.apache.karaf.jaas.modules.NamePasswordCallbackHandler) GroupPrincipal(org.apache.karaf.jaas.boot.principal.GroupPrincipal) RolePrincipal(org.apache.karaf.jaas.boot.principal.RolePrincipal) Subject(javax.security.auth.Subject) UserPrincipal(org.apache.karaf.jaas.boot.principal.UserPrincipal) Test(org.junit.Test)

Example 43 with RolePrincipal

use of org.apache.karaf.jaas.boot.principal.RolePrincipal in project karaf by apache.

the class PropertiesBackingEngine method addRole.

@Override
public void addRole(String username, String role) {
    String userInfos = users.get(username);
    if (userInfos != null) {
        for (RolePrincipal rp : listRoles(username)) {
            if (role.equals(rp.getName())) {
                return;
            }
        }
        for (GroupPrincipal gp : listGroups(username)) {
            if (role.equals(GROUP_PREFIX + gp.getName())) {
                return;
            }
        }
        String newUserInfos = userInfos + "," + role;
        users.put(username, newUserInfos);
    }
    try {
        users.save();
    } catch (Exception ex) {
        LOGGER.error("Cannot update users file,", ex);
    }
}
Also used : GroupPrincipal(org.apache.karaf.jaas.boot.principal.GroupPrincipal) RolePrincipal(org.apache.karaf.jaas.boot.principal.RolePrincipal)

Example 44 with RolePrincipal

use of org.apache.karaf.jaas.boot.principal.RolePrincipal in project ddf by codice.

the class Security method javaSubjectHasAdminRole.

/**
     * Determines if the current Java {@link Subject} has the admin role.
     *
     * @return {@code true} if the Java {@link Subject} exists and has the admin role, {@code false} otherwise
     */
public boolean javaSubjectHasAdminRole() {
    javax.security.auth.Subject subject = javax.security.auth.Subject.getSubject(AccessController.getContext());
    if (subject != null) {
        String localRoles = System.getProperty(KARAF_LOCAL_ROLE, "");
        Collection<RolePrincipal> principals = new ArrayList<>();
        for (String role : localRoles.split(",")) {
            principals.add(new RolePrincipal(role));
        }
        return subject.getPrincipals().containsAll(principals);
    }
    return false;
}
Also used : ArrayList(java.util.ArrayList) RolePrincipal(org.apache.karaf.jaas.boot.principal.RolePrincipal)

Example 45 with RolePrincipal

use of org.apache.karaf.jaas.boot.principal.RolePrincipal in project ddf by codice.

the class Security method getAdminJavaSubject.

private static javax.security.auth.Subject getAdminJavaSubject() {
    Set<Principal> principals = new HashSet<>();
    String localRoles = System.getProperty(KARAF_LOCAL_ROLE, "");
    for (String role : localRoles.split(",")) {
        principals.add(new RolePrincipal(role));
    }
    return new javax.security.auth.Subject(true, principals, new HashSet(), new HashSet());
}
Also used : RolePrincipal(org.apache.karaf.jaas.boot.principal.RolePrincipal) RolePrincipal(org.apache.karaf.jaas.boot.principal.RolePrincipal) Principal(java.security.Principal) Subject(ddf.security.Subject) HashSet(java.util.HashSet)

Aggregations

RolePrincipal (org.apache.karaf.jaas.boot.principal.RolePrincipal)61 UserPrincipal (org.apache.karaf.jaas.boot.principal.UserPrincipal)20 Subject (javax.security.auth.Subject)19 Principal (java.security.Principal)15 Test (org.junit.Test)15 LoginException (javax.security.auth.login.LoginException)14 IOException (java.io.IOException)13 NameCallback (javax.security.auth.callback.NameCallback)13 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)13 ArrayList (java.util.ArrayList)12 Callback (javax.security.auth.callback.Callback)11 PasswordCallback (javax.security.auth.callback.PasswordCallback)10 FailedLoginException (javax.security.auth.login.FailedLoginException)10 GroupPrincipal (org.apache.karaf.jaas.boot.principal.GroupPrincipal)9 BundleContext (org.osgi.framework.BundleContext)8 Hashtable (java.util.Hashtable)7 HashSet (java.util.HashSet)6 File (java.io.File)4 Configuration (org.osgi.service.cm.Configuration)4 Attribute (ddf.security.assertion.Attribute)3