com.sun.xml.ws.security.trust.impl.DefaultSTSAttributeProvider Maven / Gradle / Ivy
/*
* Copyright (c) 1997, 2022 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
*/
package com.sun.xml.ws.security.trust.impl;
import com.sun.xml.ws.api.security.trust.Claims;
import com.sun.xml.ws.api.security.trust.STSAttributeProvider;
import com.sun.xml.wss.saml.Assertion;
import com.sun.xml.wss.saml.AssertionUtil;
import com.sun.xml.wss.saml.Attribute;
import com.sun.xml.wss.saml.AttributeStatement;
import com.sun.xml.wss.saml.AuthenticationStatement;
import com.sun.xml.wss.saml.NameID;
import com.sun.xml.wss.saml.NameIdentifier;
import com.sun.xml.wss.saml.SAMLException;
import com.sun.xml.wss.saml.util.SAMLUtil;
import java.security.Principal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.security.auth.Subject;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamReader;
import org.w3c.dom.Element;
/**
*
* @author Jiandong Guo
*/
public class DefaultSTSAttributeProvider implements STSAttributeProvider{
public DefaultSTSAttributeProvider() {}
@Override
public Map> getClaimedAttributes(final Subject subject, final String appliesTo, final String tokenType, final Claims claims){
final Set principals = subject.getPrincipals();
final Map> attrs = new HashMap<>();
if (principals != null && !principals.isEmpty()){
final Iterator iterator = principals.iterator();
while (iterator.hasNext()){
final String name = principals.iterator().next().getName();
if (name != null){
List nameIds = new ArrayList<>();
nameIds.add(name);
attrs.put(new QName("http://sun.com", NAME_IDENTIFIER), nameIds);
break;
}
}
}else {
//handle the case that the authentication token is SAML assertion
Set