com.sun.xml.ws.security.trust.impl.DefaultSTSAttributeProvider Maven / Gradle / Ivy
/*
* Copyright (c) 1997, 2018 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.*;
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 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