Search in sources :

Example 1 with GidPrincipal

use of org.dcache.auth.GidPrincipal in project dcache by dCache.

the class StrategyIdMapper method principalToGid.

@Override
public int principalToGid(String name) {
    try {
        String principal = stripDomain(name);
        Principal gidPrincipal = _remoteLoginStrategy.map(new GroupNamePrincipal(principal));
        if (gidPrincipal instanceof GidPrincipal) {
            return (int) ((GidPrincipal) gidPrincipal).getGid();
        }
    } catch (CacheException e) {
        LOGGER.debug("Failed to map principal {} : {}", name, e);
    }
    return tryNumericIfAllowed(name);
}
Also used : CacheException(diskCacheV111.util.CacheException) GroupNamePrincipal(org.dcache.auth.GroupNamePrincipal) GroupNamePrincipal(org.dcache.auth.GroupNamePrincipal) GidPrincipal(org.dcache.auth.GidPrincipal) KerberosPrincipal(javax.security.auth.kerberos.KerberosPrincipal) UserNamePrincipal(org.dcache.auth.UserNamePrincipal) Principal(java.security.Principal) UidPrincipal(org.dcache.auth.UidPrincipal) GidPrincipal(org.dcache.auth.GidPrincipal)

Example 2 with GidPrincipal

use of org.dcache.auth.GidPrincipal in project dcache by dCache.

the class Nis method map.

@Override
public void map(Set<Principal> principals) throws AuthenticationException {
    boolean mapped;
    Principal principal = find(principals, instanceOf(UserNamePrincipal.class), null);
    checkAuthentication(principal != null, "no username principal");
    try {
        Attributes userAttr = _ctx.getAttributes(NISMAP_PASSWORD_BY_NAME + "/" + principal.getName());
        principals.add(new UidPrincipal((String) userAttr.get(UID_NUMBER_ATTRIBUTE).get()));
        principals.add(new GidPrincipal((String) userAttr.get(GID_NUMBER_ATTRIBUTE).get(), true));
        NamingEnumeration<SearchResult> groupResult = _ctx.search(NISMAP_GROUP_BY_NAME, new BasicAttributes(MEMBER_UID_ATTRIBUTE, principal.getName()));
        mapped = true;
        while (groupResult.hasMore()) {
            SearchResult result = groupResult.next();
            principals.add(new GidPrincipal((String) result.getAttributes().get(GID_NUMBER_ATTRIBUTE).get(), false));
        }
    } catch (NamingException e) {
        LOGGER.debug("Failed to get mapping: {}", e.toString());
        throw new AuthenticationException("no mapping: " + e.getMessage(), e);
    }
    checkAuthentication(mapped, "no matching principal");
}
Also used : UserNamePrincipal(org.dcache.auth.UserNamePrincipal) BasicAttributes(javax.naming.directory.BasicAttributes) AuthenticationException(org.dcache.gplazma.AuthenticationException) UidPrincipal(org.dcache.auth.UidPrincipal) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes) SearchResult(javax.naming.directory.SearchResult) NamingException(javax.naming.NamingException) GroupNamePrincipal(org.dcache.auth.GroupNamePrincipal) GidPrincipal(org.dcache.auth.GidPrincipal) UserNamePrincipal(org.dcache.auth.UserNamePrincipal) Principal(java.security.Principal) UidPrincipal(org.dcache.auth.UidPrincipal) GidPrincipal(org.dcache.auth.GidPrincipal)

Example 3 with GidPrincipal

use of org.dcache.auth.GidPrincipal in project dcache by dCache.

the class Nsswitch method map.

@Override
public void map(Set<Principal> principals) throws AuthenticationException {
    __password password = null;
    boolean havePrimaryGid = false;
    for (Principal p : principals) {
        if (p instanceof UserNamePrincipal && password == null) {
            password = _libc.getpwnam(p.getName());
        } else if (p instanceof GidPrincipal) {
            havePrimaryGid |= ((GidPrincipal) p).isPrimaryGroup();
        }
    }
    checkAuthentication(password != null, "no mapping");
    principals.add(new UidPrincipal(password.uid));
    principals.add(new GidPrincipal(password.gid, !havePrimaryGid));
    for (int id : groupsOf(password)) {
        principals.add(new GidPrincipal(id, false));
    }
}
Also used : UserNamePrincipal(org.dcache.auth.UserNamePrincipal) UidPrincipal(org.dcache.auth.UidPrincipal) UserNamePrincipal(org.dcache.auth.UserNamePrincipal) Principal(java.security.Principal) UidPrincipal(org.dcache.auth.UidPrincipal) GroupNamePrincipal(org.dcache.auth.GroupNamePrincipal) GidPrincipal(org.dcache.auth.GidPrincipal) GidPrincipal(org.dcache.auth.GidPrincipal)

Example 4 with GidPrincipal

use of org.dcache.auth.GidPrincipal in project dcache by dCache.

the class GplazmaMultiMapFileTest method shouldMatchNonPrimarySpecificGroupWithNonPrimaryGroup.

@Test
public void shouldMatchNonPrimarySpecificGroupWithNonPrimaryGroup() throws Exception {
    givenConfig("group:test gid:1000,false");
    whenMapping(new GroupNamePrincipal("test", false));
    assertThat(warnings, is(empty()));
    assertThat(mappedPrincipals, hasItem(new GidPrincipal(1000, false)));
}
Also used : GroupNamePrincipal(org.dcache.auth.GroupNamePrincipal) GidPrincipal(org.dcache.auth.GidPrincipal) Test(org.junit.Test)

Example 5 with GidPrincipal

use of org.dcache.auth.GidPrincipal in project dcache by dCache.

the class GplazmaMultiMapFileTest method shouldMatchNonPrimarySpecificGroupWithPrimaryGroup.

@Test
public void shouldMatchNonPrimarySpecificGroupWithPrimaryGroup() throws Exception {
    givenConfig("group:test gid:1000,false");
    whenMapping(new GroupNamePrincipal("test", true));
    assertThat(warnings, is(empty()));
    assertThat(mappedPrincipals, hasItem(new GidPrincipal(1000, false)));
}
Also used : GroupNamePrincipal(org.dcache.auth.GroupNamePrincipal) GidPrincipal(org.dcache.auth.GidPrincipal) Test(org.junit.Test)

Aggregations

GidPrincipal (org.dcache.auth.GidPrincipal)39 UidPrincipal (org.dcache.auth.UidPrincipal)27 Test (org.junit.Test)21 Principal (java.security.Principal)18 UserNamePrincipal (org.dcache.auth.UserNamePrincipal)13 GroupNamePrincipal (org.dcache.auth.GroupNamePrincipal)11 OidcSubjectPrincipal (org.dcache.auth.OidcSubjectPrincipal)9 Subject (javax.security.auth.Subject)4 AuthenticationException (org.dcache.gplazma.AuthenticationException)4 HashSet (java.util.HashSet)3 NamingException (javax.naming.NamingException)3 BasicAttributes (javax.naming.directory.BasicAttributes)3 SearchResult (javax.naming.directory.SearchResult)3 FQANPrincipal (org.dcache.auth.FQANPrincipal)3 CacheException (diskCacheV111.util.CacheException)2 Attributes (javax.naming.directory.Attributes)2 KerberosPrincipal (javax.security.auth.kerberos.KerberosPrincipal)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Strings (com.google.common.base.Strings)1 UserPrincipal (com.sun.security.auth.UserPrincipal)1