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) 2000-2012 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.
*/
package com.sun.messaging.jms.ra;
import javax.resource.spi.security.PasswordCredential;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.security.auth.Subject;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Iterator;
import java.util.Set;
/**
* Util methods for the Sun MQ Resource Adapter for JMS
*/
public class Util
{
/** Disable Constructor */
private Util() {}
/** Generic equals method
*
* @param a object 1
* @param b object 2
*
* @return true if objects a and b are equal;
* false otherwise
*/
static public boolean
isEqual(Object a, Object b)
{
if (a == null) {
return (b == null);
} else {
return a.equals(b);
}
}
/** Checks two PassWordCredential instances
* for equality
*
* @param a PasswordCredential 1
* @param b PasswordCredential 2
*
* @return true if PasswordCredential a and
* PasswordCredential b are equal;
* false otherwise
*/
static public boolean
isPasswordCredentialEqual(PasswordCredential a, PasswordCredential b)
{
if (a == b) {
return true;
}
if ((a == null) && (b != null)) {
return false;
}
if ((a != null) && (b == null))
return false;
if (!isEqual(a.getUserName(), b.getUserName())) {
return false;
}
String p1 = null;
String p2 = null;
if (a.getPassword() != null) {
p1 = new String(a.getPassword());
}
if (b.getPassword() != null) {
p2 = new String(b.getPassword());
}
return (isEqual(p1, p2));
}
/** Returns a PasswordCredential by resolving
* the ManagedConnectionFactory, Subject, and
* ConnectionRequestInfo passed in.
*
* If the Subject is non-null, non-empty, it will be the src
* of the pc info.
* else, if it is empty, the MCF should be used
* else if it null, the CRI, is used if non-empty
* else the MCF is used.
*
* @return The PasswordCredential
*/
static public PasswordCredential
getPasswordCredential(
final com.sun.messaging.jms.ra.ManagedConnectionFactory mcf,
final Subject subject,
com.sun.messaging.jms.ra.ConnectionRequestInfo myinfo)
throws javax.resource.ResourceException
{
String username2use = null;
String password2use = null;
PasswordCredential pc = null;
//System.out.println("MQRA:U:getPC()-subject="+subject+":CRInfo="+myinfo);
if (subject != null) {
//System.out.println("MQRA:U:getPC:non-null subject");
pc = (PasswordCredential)
AccessController.doPrivileged(
new PrivilegedAction