com.sun.xml.wss.impl.misc.DefaultRealmAuthenticationAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wsit-impl Show documentation
Show all versions of wsit-impl Show documentation
This module contains the Metro WSIT runtime code.
/*
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*
* DefaultRealmAuthenticationProvider.java
*
* Created on November 12, 2006, 10:22 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package com.sun.xml.wss.impl.misc;
import com.sun.xml.wss.RealmAuthenticationAdapter;
import com.sun.xml.wss.WSITXMLFactory;
import com.sun.xml.wss.XWSSecurityException;
import com.sun.xml.wss.impl.MessageConstants;
import java.io.File;
import java.io.IOException;
import java.security.AccessController;
import java.security.Principal;
import java.security.PrivilegedAction;
import java.util.HashMap;
import javax.security.auth.Subject;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import jakarta.security.auth.message.callback.CallerPrincipalCallback;
import jakarta.security.auth.message.callback.PasswordValidationCallback;
import javax.security.auth.x500.X500Principal;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
/**
*
* @author kumar jayanti
*/
public class DefaultRealmAuthenticationAdapter extends RealmAuthenticationAdapter {
private CallbackHandler gfCallbackHandler = null;
private HashMap tomcatUsersXML = null;
private static DocumentBuilderFactory dbf = WSITXMLFactory.createDocumentBuilderFactory(WSITXMLFactory.DISABLE_SECURE_PROCESSING);
private static String classname = "com.sun.enterprise.security.jmac.callback.ContainerCallbackHandler";
/*
static {
dbf.setNamespaceAware(true);
}*/
/** Creates a new instance of DefaultRealmAuthenticationProvider */
public DefaultRealmAuthenticationAdapter() {
if (isGlassfish()) {
gfCallbackHandler = this.loadGFHandler();
} else if (isTomcat()) {
populateTomcatUsersXML();
}
}
private boolean isGlassfish() {
String val = System.getProperty("com.sun.aas.installRoot");
if (val != null) {
return true;
}
return false;
}
private boolean isTomcat() {
String val = System.getProperty("catalina.home");
String val1 = System.getProperty("com.sun.aas.installRoot");
if ((val1 == null) && (val != null)) {
return true;
}
return false;
}
private boolean authenticateFromTomcatUsersXML(
final Subject callerSubject, final String username, final String password)
throws XWSSecurityException {
if (tomcatUsersXML != null) {
String pass = (String)tomcatUsersXML.get(username);
if (pass == null) {
return false;
}
if (pass.equals(password)) {
//populate the subject
AccessController.doPrivileged(new PrivilegedAction