Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 1997-2013 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2016] [Payara Foundation and/or its affiliates]
package com.sun.enterprise.security.acl;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.security.Principal;
import java.security.PrivilegedAction;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.logging.*;
import javax.security.auth.Subject;
import org.glassfish.deployment.common.RootDeploymentDescriptor;
import org.glassfish.security.common.Role;
import org.glassfish.security.common.PrincipalImpl;
import org.glassfish.deployment.common.SecurityRoleMapper;
import com.sun.enterprise.config.serverbeans.SecurityService;
import com.sun.enterprise.deployment.Application;
import com.sun.enterprise.deployment.BundleDescriptor;
import com.sun.enterprise.security.common.AppservAccessController;
import com.sun.logging.*;
import org.glassfish.api.admin.ServerEnvironment;
import org.glassfish.internal.api.Globals;
import org.glassfish.internal.data.ApplicationInfo;
import org.glassfish.internal.data.ApplicationRegistry;
import org.glassfish.security.common.Group;
/** This Object maintains a mapping of users and groups to application
* specific Roles.
* Using this object this mapping information could be maintained and
* queried at a later time. This is a complete rewrite of the previous
* RoleMapper for JACC related changes.
* @author Harpreet Singh
*/
public class RoleMapper implements Serializable, SecurityRoleMapper {
//private static Map ROLEMAPPER = new HashMap();
private static final long serialVersionUID = -4455830942007736853L;
private static final String DEFAULT_ROLE_NAME = "ANYONE";
private Role defaultRole = null;
private String defaultRoleName = null;
private String appName;
private final Map roleToSubject =
new HashMap();
// default mapper to emulate Servlet default p2r mapping semantics
private String defaultP2RMappingClassName = null;
private DefaultRoleToSubjectMapping defaultRTSM =
new DefaultRoleToSubjectMapping();
/* the following 2 Maps are a copy of roleToSubject.
* This is added as a support for deployment.
* Should think of optimizing this.
*/
private final Map> roleToPrincipal =
new HashMap>();
private final Map> roleToGroup =
new HashMap>();
/* The following objects are used to detect conflicts during deployment */
/* .....Mapping of module (or application) that is presently calling
* assignRole(). It is set by the startMappingFor() method.
* After all the subjects have been assigned, stopMappingFor()
* is called and then the mappings can be checked against
* those previously assigned.
*/
private Mapping currentMapping;
// These override roles mapped in submodules.
private Set topLevelRoles;
// used to identify the application level mapping file
private static final String TOP_LEVEL = "sun-application.xml mapping file";
// used to log a warning only one time
private boolean conflictLogged = false;
// store roles that have a conflict so they are not re-mapped
private Set conflictedRoles;
/* End conflict detection objects */
private Boolean appDefaultMapping;
private static final Logger _logger =
LogDomains.getLogger(RoleMapper.class, LogDomains.SECURITY_LOGGER);
private transient SecurityService secService = null;
RoleMapper(String appName) {
this.appName = appName;
secService = Globals.getDefaultHabitat().getService(SecurityService.class,
ServerEnvironment.DEFAULT_INSTANCE_NAME);
defaultP2RMappingClassName = getDefaultP2RMappingClassName();
postConstruct();
}
private synchronized void initDefaultRole() {
// if (!SecurityServicesUtil.getInstance().isServer()) {
// //do nothing if this is not an EJB or Web Container
// return;
// }
if (defaultRole == null) {
defaultRoleName = DEFAULT_ROLE_NAME;
try {
assert (secService != null);
defaultRoleName = secService.getAnonymousRole();
} catch (Exception e) {
_logger.log(Level.WARNING,
"java_security.anonymous_role_reading_exception",
e);
}
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Default role is: " + defaultRoleName);
}
defaultRole = new Role(defaultRoleName);
}
}
private boolean getAppDefaultRoleMapping() {
if(appDefaultMapping != null) {
return appDefaultMapping;
}
appDefaultMapping = false;
if(secService != null) {
appDefaultMapping = Boolean.parseBoolean(secService.getActivateDefaultPrincipalToRoleMapping());
if (appDefaultMapping) {
// if set explicitly in the security service allow default mapping
return appDefaultMapping;
}
}
ApplicationRegistry appRegistry = Globals.getDefaultHabitat().getService(ApplicationRegistry.class);
ApplicationInfo appInfo = appRegistry.get(appName);
if(appInfo == null) {
return appDefaultMapping;
}
Application app = appInfo.getMetaData(Application.class);
BundleDescriptor bd = app.getModuleByUri(appName);
appDefaultMapping = bd == null? app.isDefaultGroupPrincipalMapping() : app.getModuleByUri(appName).isDefaultGroupPrincipalMapping();
return appDefaultMapping;
}
/**
* @return The application/module name for this RoleMapper
*/
public String getName() {
return appName;
}
/**
* @param name The application/module name
*/
public void setName(String name) {
this.appName = name;
}
/**
* @param principal A principal that corresponds to the role
* @param role A role corresponding to this principal
*/
private void addRoleToPrincipal(final Principal principal, String role) {
assert roleToSubject != null;
Subject subject = roleToSubject.get(role);
final Subject sub = (subject == null) ? new Subject() : subject;
AppservAccessController.doPrivileged(new PrivilegedAction