@@ -0,0 +1,2670 @@
+package org.dcache.auth;%0A%0Aimport java.security.Principal;%0Aimport java.util.Collections;%0Aimport java.util.Set;%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;%0A%0Aimport javax.security.auth.Subject;%0A%0Aimport org.dcache.auth.attributes.LoginAttribute;%0Aimport org.springframework.beans.factory.annotation.Required;%0A%0Aimport diskCacheV111.util.CacheException;%0A%0A/**%0A * Anonymous login strategy, used on the xrootd door when%0A * no authentication is specified. The behaviour follows the old door%0A * behaviour - depending on configuration, a NOBODY user, a ROOT user or a%0A * user based on the configured uid/gid is returned as a result of the%0A * login operation.%0A *%0A * @author tzangerl%0A */%0Apublic class AnonymousLoginStrategy implements LoginStrategy%0A%7B%0A    public final static String USER_ROOT = %22root%22;%0A    public final static String USER_NOBODY = %22nobody%22;%0A    public final static Pattern USER_PATTERN =%0A        Pattern.compile(%22(%5C%5Cd+):((%5C%5Cd+)(,(%5C%5Cd+))*)%22);%0A%0A    private final static Set%3CLoginAttribute%3E NO_ATTRIBUTES =%0A            Collections.emptySet();%0A%0A    private Subject _subject;%0A%0A    public AnonymousLoginStrategy()%0A    %7B%0A    %7D%0A%0A    @Override%0A    public LoginReply login(Subject subject) throws CacheException%0A    %7B%0A        return new LoginReply(_subject, NO_ATTRIBUTES);%0A    %7D%0A%0A    @Override%0A    public Principal map(Principal principal) throws CacheException%0A    %7B%0A        return null;%0A    %7D%0A%0A    @Override%0A    public Set%3CPrincipal%3E reverseMap(Principal principal) throws CacheException%0A    %7B%0A        return null;%0A    %7D%0A%0A    /**%0A     * Parses a string on the form UID:GID(,GID)* and returns a%0A     * corresponding Subject.%0A     */%0A    private Subject parseUidGidList(String user)%0A    %7B%0A        Matcher matcher = USER_PATTERN.matcher(user);%0A        if (!matcher.matches()) %7B%0A            throw new IllegalArgumentException(%22Invalid user string%22);%0A        %7D%0A%0A        Subject subject = new Subject();%0A        int uid = Integer.parseInt(matcher.group(1));%0A        Set%3CPrincipal%3E principals = subject.getPrincipals();%0A        principals.add(new UidPrincipal(uid));%0A        boolean primary = true;%0A        for (String group: matcher.group(2).split(%22,%22)) %7B%0A            int gid = Integer.parseInt(group);%0A            principals.add(new GidPrincipal(gid, primary));%0A            primary = false;%0A        %7D%0A        subject.setReadOnly();%0A%0A        return subject;%0A    %7D%0A%0A    @Required%0A    public void setUser(String user) %7B%0A        if (user.equals(USER_ROOT)) %7B%0A            _subject = Subjects.ROOT;%0A        %7D else if (user.equals(USER_NOBODY)) %7B%0A            _subject = Subjects.NOBODY;%0A        %7D else %7B%0A            _subject = parseUidGidList(user);%0A        %7D%0A    %7D%0A%7D%0A

Add Anonymous LoginStrategy from trunk