Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FISH-8215 : port solution from Glassfish #6535

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Portions Copyright [2019] Payara Foundation and/or affiliates
// Portions Copyright [2019-2024] Payara Foundation and/or affiliates
Pandrex247 marked this conversation as resolved.
Show resolved Hide resolved

package org.apache.catalina.realm;


import com.sun.enterprise.security.GroupPrincipal;
import org.apache.catalina.Container;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.LogFacade;

import javax.security.auth.Subject;
import javax.security.auth.login.*;
import java.security.Principal;
import java.security.acl.Group;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Enumeration;
Expand Down Expand Up @@ -438,15 +438,13 @@ protected Principal createPrincipal(String username, Subject subject) {
roles.add(principal.getName());
}
// Same as Jboss - that's a pretty clean solution
if( (principal instanceof Group) &&
"Roles".equals( principal.getName())) {
Group grp=(Group)principal;
Enumeration en=grp.members();
while( en.hasMoreElements() ) {
Principal roleP=(Principal)en.nextElement();
roles.add( roleP.getName());
if ((principal instanceof GroupPrincipal) && "Roles".equals(principal.getName())) {
GroupPrincipal grp = (GroupPrincipal) principal;
Enumeration<? extends Principal> membersEnum = grp.members();
while (membersEnum.hasMoreElements()) {
Principal roleP = membersEnum.nextElement();
roles.add(roleP.getName());
}

}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2021 Contributors to Eclipse Foundation. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
// Portions Copyright 2024 Payara Foundation and/or affiliates
luiseufrasio marked this conversation as resolved.
Show resolved Hide resolved
package com.sun.enterprise.security;

import java.security.Principal;
import java.util.Enumeration;

/**
* A group of principals.
*
* @author Arjan Tijms
*
*/
public interface GroupPrincipal extends Principal {

/**
* Returns true when the given principal is in this group.
*
* <p>
* A recursive search is done, meaning that if a principal is in a group which is itself in this group, the result is true.
*
* @param principal the principal for which we check to be in this group.
*
* @return true if the principal is in this group, false otherwise.
*/
boolean isMember(Principal principal);

/**
* Returns an enumeration of all the principals in this group.
*
* <p>
* The returned principals can include principals that are besides instanced of Principal also instances of GroupPrincipal.
*
* @return an enumeration of principals in this group, potentially including nested group principals.
*/
Enumeration<? extends Principal> members();

}