use of org.glassfish.api.invocation.ComponentInvocation in project Payara by payara.
the class EntityManagerWrapper method getNonTxEMFromCurrentInvocation.
private EntityManager getNonTxEMFromCurrentInvocation() {
// We store nonTxEM as a payload in a map from EMF to EM inside current invocation.
// It will be closed during NonTxEntityManagerCleaner.beforePostInvoke() below
ComponentInvocation currentInvocation = invMgr.getCurrentInvocation();
Map<EntityManagerFactory, EntityManager> nonTxEMs = getNonTxEMsFromCurrentInvocation(currentInvocation);
if (nonTxEMs == null) {
nonTxEMs = new HashMap<>();
currentInvocation.setRegistryFor(INVOCATION_PAYLOAD_KEY, nonTxEMs);
}
EntityManager nonTxEM = nonTxEMs.get(entityManagerFactory);
if (nonTxEM == null) {
// Could not find one, create new one and store it within current invocation for cleanup
nonTxEM = entityManagerFactory.createEntityManager(synchronizationType, emProperties);
nonTxEMs.put(entityManagerFactory, nonTxEM);
}
return nonTxEM;
}
use of org.glassfish.api.invocation.ComponentInvocation in project Payara by payara.
the class BasicPasswordAuthenticationService method doMap.
/**
* Performs the actual mapping of the principal/userGroup to the
* backendPrincipal by checking at the connector registry for all the
* existing mapping. If a map is found the backendPrincipal is
* returned else null is returned .
*/
private Principal doMap(String principalName, List groupNames, String roleName, RuntimeSecurityMap runtimeSecurityMap) {
// Policy:
// user_1, user_2, ... user_n
// group_1/role_1, group_2/role_2, ... group_n/role_n
// user contains *
// role/group contains *
HashMap userNameSecurityMap = (HashMap) runtimeSecurityMap.getUserMap();
HashMap groupNameSecurityMap = (HashMap) runtimeSecurityMap.getGroupMap();
// Check if caller's user-name is preset in the User Map
if (userNameSecurityMap.containsKey(principalName)) {
return (Principal) userNameSecurityMap.get(principalName);
}
// Check if caller's role is present in the Group Map
if (isContainerContextAWebModuleObject() && roleName != null) {
if (groupNameSecurityMap.containsKey(roleName)) {
return (Principal) groupNameSecurityMap.get(roleName);
}
}
// If ejb, use isCallerInRole
if (isContainerContextAEJBContainerObject() && roleName == null) {
ComponentInvocation componentInvocation = ConnectorRuntime.getRuntime().getInvocationManager().getCurrentInvocation();
EJBInvocation ejbInvocation = (EJBInvocation) componentInvocation;
EJBContext ejbcontext = ejbInvocation.getEJBContext();
Set<Map.Entry> s = (Set<Map.Entry>) groupNameSecurityMap.entrySet();
Iterator i = s.iterator();
while (i.hasNext()) {
Map.Entry mapEntry = (Map.Entry) i.next();
String key = (String) mapEntry.getKey();
Principal entry = (Principal) mapEntry.getValue();
boolean isInRole = false;
try {
isInRole = ejbcontext.isCallerInRole(key);
} catch (Exception ex) {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "BasicPasswordAuthentication::caller not in role " + key);
}
}
if (isInRole) {
return entry;
}
}
}
// Check if caller's group(s) is/are present in the Group Map
for (int j = 0; j < groupNames.size(); j++) {
String groupName = (String) groupNames.get(j);
if (groupNameSecurityMap.containsKey(groupName)) {
return (Principal) groupNameSecurityMap.get(groupName);
}
}
// Check if user name is * in Security Map
if (userNameSecurityMap.containsKey(ConnectorConstants.SECURITYMAPMETACHAR)) {
return (Principal) userNameSecurityMap.get(ConnectorConstants.SECURITYMAPMETACHAR);
}
// Check if role/group name is * in Security Map
if (groupNameSecurityMap.containsKey(ConnectorConstants.SECURITYMAPMETACHAR)) {
return (Principal) groupNameSecurityMap.get(ConnectorConstants.SECURITYMAPMETACHAR);
}
return null;
}
use of org.glassfish.api.invocation.ComponentInvocation in project Payara by payara.
the class ResourceManagerImpl method rollBackTransaction.
/**
* Get's the component's transaction and marks it for rolling back.
*/
public void rollBackTransaction() {
InvocationManager invmgr = ConnectorRuntime.getRuntime().getInvocationManager();
JavaEETransactionManager tm = ConnectorRuntime.getRuntime().getTransactionManager();
Transaction tran = null;
try {
ComponentInvocation inv = invmgr.getCurrentInvocation();
if (inv == null) {
// in that, you return the transaction from the TxManager
try {
tran = tm.getTransaction();
} catch (Exception e) {
tran = null;
_logger.log(Level.INFO, e.getMessage());
}
} else {
tran = (Transaction) inv.getTransaction();
}
if (tran != null) {
tran.setRollbackOnly();
}
} catch (SystemException ex) {
_logger.log(Level.WARNING, "poolmgr.system_exception", ex);
} catch (IllegalStateException ex) {
// ignore
}
}
use of org.glassfish.api.invocation.ComponentInvocation in project Payara by payara.
the class ResourceManagerImpl method registerResource.
/**
* Register the <code>ResourceHandle</code> in the transaction
*
* @param handle <code>ResourceHandle</code> object
* @exception <code>PoolingException</code>
*/
public void registerResource(ResourceHandle handle) throws PoolingException {
try {
Transaction tran = null;
JavaEETransactionManager tm = ConnectorRuntime.getRuntime().getTransactionManager();
// enlist if necessary
if (handle.isTransactional()) {
InvocationManager invmgr = ConnectorRuntime.getRuntime().getInvocationManager();
ComponentInvocation inv = invmgr.getCurrentInvocation();
if (inv == null) {
// in that, you return the transaction from the TxManager
try {
tran = tm.getTransaction();
} catch (Exception e) {
tran = null;
_logger.log(Level.INFO, e.getMessage());
}
} else {
tran = (Transaction) inv.getTransaction();
tm.registerComponentResource(handle);
}
if (tran != null) {
try {
tm.enlistResource(tran, handle);
} catch (Exception ex) {
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("Exception whle trying to enlist resource " + ex.getMessage());
}
// to enlist the resource
if (inv != null) {
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("Attempting to unregister component resource");
}
tm.unregisterComponentResource(handle);
}
throw ex;
}
}
}
} catch (Exception ex) {
_logger.log(Level.SEVERE, "poolmgr.component_register_exception", ex);
throw new PoolingException(ex.toString(), ex);
}
}
use of org.glassfish.api.invocation.ComponentInvocation in project Payara by payara.
the class ResourceManagerImpl method getComponent.
/**
* Returns the component invoking resource request.
*
* @return Handle to the component.
*/
public Object getComponent() {
InvocationManager invmgr = ConnectorRuntime.getRuntime().getInvocationManager();
ComponentInvocation inv = invmgr.getCurrentInvocation();
if (inv == null) {
return null;
}
return inv.getInstance();
}
Aggregations