Example usage for javax.xml.bind JAXBElement getName

List of usage examples for javax.xml.bind JAXBElement getName

Introduction

In this page you can find the example usage for javax.xml.bind JAXBElement getName.

Prototype

public QName getName() 

Source Link

Document

Returns the xml element tag name.

Usage

From source file:be.fedict.eid.idp.sp.protocol.ws_federation.sts.SecurityTokenServiceClient.java

/**
 * Validates the given SAML assertion via the eID IdP WS-Trust STS
 * validation service.//from   w w w  .jav  a 2s.  com
 * 
 * @param samlAssertionElement
 *            the SAML assertion DOM element to be validated.
 * @param expectedSAMLAudience
 *            the optional (but recommended) expected value for SAML
 *            Audience.
 */
public void validateToken(Element samlAssertionElement, String expectedSAMLAudience) {
    RequestSecurityTokenType request = this.objectFactory.createRequestSecurityTokenType();
    List<Object> requestContent = request.getAny();

    requestContent.add(this.objectFactory.createRequestType(WSTrustConstants.VALIDATE_REQUEST_TYPE));

    requestContent.add(this.objectFactory.createTokenType(WSTrustConstants.STATUS_TOKEN_TYPE));

    ValidateTargetType validateTarget = this.objectFactory.createValidateTargetType();
    requestContent.add(this.objectFactory.createValidateTarget(validateTarget));

    BindingProvider bindingProvider = (BindingProvider) this.port;
    WSSecuritySoapHandler.setAssertion(samlAssertionElement, bindingProvider);
    SecurityTokenReferenceType securityTokenReference = this.wsseObjectFactory
            .createSecurityTokenReferenceType();
    validateTarget.setAny(this.wsseObjectFactory.createSecurityTokenReference(securityTokenReference));
    securityTokenReference.getOtherAttributes().put(
            new QName(WSTrustConstants.WS_SECURITY_11_NAMESPACE, "TokenType"),
            WSTrustConstants.SAML2_WSSE11_TOKEN_TYPE);
    KeyIdentifierType keyIdentifier = this.wsseObjectFactory.createKeyIdentifierType();
    securityTokenReference.getAny().add(this.wsseObjectFactory.createKeyIdentifier(keyIdentifier));
    String samlAssertionId = samlAssertionElement.getAttribute("ID");
    LOG.debug("SAML assertion ID: " + samlAssertionId);
    keyIdentifier.setValue(samlAssertionId);
    keyIdentifier.getOtherAttributes().put(new QName(WSTrustConstants.WS_SECURITY_NAMESPACE, "ValueType"),
            "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLID");

    if (null != expectedSAMLAudience) {
        AppliesTo appliesTo = this.policyObjectFactory.createAppliesTo();
        requestContent.add(appliesTo);
        EndpointReferenceType endpointReference = this.addrObjectFactory.createEndpointReferenceType();
        appliesTo.getAny().add(this.addrObjectFactory.createEndpointReference(endpointReference));
        AttributedURIType address = this.addrObjectFactory.createAttributedURIType();
        endpointReference.setAddress(address);
        address.setValue(expectedSAMLAudience);
    }

    RequestSecurityTokenResponseCollectionType response = this.port.requestSecurityToken(request);

    if (null == response) {
        throw new SecurityException("missing RSTRC");
    }
    List<RequestSecurityTokenResponseType> responseList = response.getRequestSecurityTokenResponse();
    if (1 != responseList.size()) {
        throw new SecurityException("response list should contain 1 entry");
    }
    RequestSecurityTokenResponseType requestSecurityTokenResponse = responseList.get(0);
    List<Object> requestSecurityTokenResponseContent = requestSecurityTokenResponse.getAny();
    boolean hasStatus = false;
    for (Object requestSecurityTokenResponseObject : requestSecurityTokenResponseContent) {
        if (requestSecurityTokenResponseObject instanceof JAXBElement) {
            JAXBElement jaxbElement = (JAXBElement) requestSecurityTokenResponseObject;
            QName qname = jaxbElement.getName();
            if (WSTrustConstants.TOKEN_TYPE_QNAME.equals(qname)) {
                String tokenType = (String) jaxbElement.getValue();
                if (false == WSTrustConstants.STATUS_TOKEN_TYPE.equals(tokenType)) {
                    throw new SecurityException("invalid response token type: " + tokenType);
                }
            } else if (STATUS_QNAME.equals(qname)) {
                StatusType status = (StatusType) jaxbElement.getValue();
                String statusCode = status.getCode();
                if (false == WSTrustConstants.VALID_STATUS_CODE.equals(statusCode)) {
                    String reason = status.getReason();
                    throw new SecurityException("invalid token: " + reason);
                }
                hasStatus = true;
            }
        }
    }
    if (false == hasStatus) {
        throw new SecurityException("missing wst:Status");
    }
}

From source file:be.agiv.security.client.RSTSClient.java

/**
 * Retrieves a new security token from the R-STS WS-Trust web service using
 * the given IP-STS security token. The security token retrieved from the
 * R-STS always applies to a certain AGIV web service. The location of this
 * AGIV web service is also passed as parameter.
 * /*from   w w w  .  j ava2  s  .  c  o  m*/
 * @param ipStsSecurityToken
 *            the IP-STS security token.
 * @param appliesTo
 *            the WS-SecureConversation enabled web service to which the
 *            R-STS security token should apply.
 * @return the R-STS security token to be used by the service Secure
 *         Conversation.
 */
public SecurityToken getSecurityToken(SecurityToken ipStsSecurityToken, String appliesTo) {
    RequestSecurityTokenType requestSecurityToken = this.objectFactory.createRequestSecurityTokenType();
    List<Object> requestSecurityTokenContent = requestSecurityToken.getAny();
    requestSecurityTokenContent.add(this.objectFactory.createRequestType(WSConstants.ISSUE_REQUEST_TYPE));

    AppliesTo jaxbAppliesTo = this.policyObjectFactory.createAppliesTo();
    EndpointReferenceType endpointReference = this.addrObjectFactory.createEndpointReferenceType();
    AttributedURIType address = this.addrObjectFactory.createAttributedURIType();
    address.setValue(appliesTo);
    endpointReference.setAddress(address);
    jaxbAppliesTo.getAny().add(this.addrObjectFactory.createEndpointReference(endpointReference));
    requestSecurityTokenContent.add(jaxbAppliesTo);

    BindingProvider bindingProvider = (BindingProvider) this.port;
    this.wsAddressingHandler.setAddressing(WSConstants.WS_TRUST_ISSUE_ACTION, this.location);
    this.wsSecurityHandler.setKey(ipStsSecurityToken.getKey(), ipStsSecurityToken.getAttachedReference(),
            ipStsSecurityToken.getToken());

    RequestSecurityTokenResponseCollectionType requestSecurityTokenResponseCollection = this.port
            .requestSecurityToken(requestSecurityToken);

    SecurityToken securityToken = new SecurityToken();

    List<RequestSecurityTokenResponseType> requestSecurityTokenResponseList = requestSecurityTokenResponseCollection
            .getRequestSecurityTokenResponse();
    RequestSecurityTokenResponseType requestSecurityTokenResponse = requestSecurityTokenResponseList.get(0);
    List<Object> requestSecurityTokenResponseContent = requestSecurityTokenResponse.getAny();
    for (Object contentObject : requestSecurityTokenResponseContent) {
        LOG.debug("content object: " + contentObject.getClass().getName());
        if (contentObject instanceof Element) {
            Element contentElement = (Element) contentObject;
            LOG.debug("element name: " + contentElement.getLocalName());
        }
        if (contentObject instanceof JAXBElement) {
            JAXBElement jaxbElement = (JAXBElement) contentObject;
            QName qname = jaxbElement.getName();
            LOG.debug("JAXB qname: " + qname);
            if (WSConstants.LIFETIME_QNAME.equals(qname)) {
                LOG.debug("trust:Lifetime");
                LifetimeType lifetime = (LifetimeType) jaxbElement.getValue();
                String createdValue = lifetime.getCreated().getValue();
                DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTimeParser();
                DateTime created = dateTimeFormatter.parseDateTime(createdValue);
                securityToken.setCreated(created.toDate());
                String expiresString = lifetime.getExpires().getValue();
                DateTime expires = dateTimeFormatter.parseDateTime(expiresString);
                securityToken.setExpires(expires.toDate());
            } else if (WSConstants.REQUESTED_ATTACHED_REFERENCE_QNAME.equals(qname)) {
                RequestedReferenceType requestedReference = (RequestedReferenceType) jaxbElement.getValue();
                SecurityTokenReferenceType securityTokenReference = requestedReference
                        .getSecurityTokenReference();
                List<Object> securityTokenReferenceContent = securityTokenReference.getAny();
                for (Object securityTokenReferenceObject : securityTokenReferenceContent) {
                    LOG.debug("SecurityTokenReference object: "
                            + securityTokenReferenceObject.getClass().getName());
                    if (securityTokenReferenceObject instanceof JAXBElement) {
                        JAXBElement securityTokenReferenceElement = (JAXBElement) securityTokenReferenceObject;
                        LOG.debug("SecurityTokenReference element: " + securityTokenReferenceElement.getName());
                        if (securityTokenReferenceElement.getName().equals(WSConstants.KEY_IDENTIFIER_QNAME)) {
                            KeyIdentifierType keyIdentifier = (KeyIdentifierType) securityTokenReferenceElement
                                    .getValue();
                            String tokenIdentifier = keyIdentifier.getValue();
                            securityToken.setAttachedReference(tokenIdentifier);
                        }
                    }
                }
            } else if (WSConstants.REQUESTED_PROOF_TOKEN_QNAME.equals(qname)) {
                RequestedProofTokenType requestedProofToken = (RequestedProofTokenType) jaxbElement.getValue();
                Object requestedProofTokenContent = requestedProofToken.getAny();
                LOG.debug("requested proof token content: " + requestedProofTokenContent.getClass().getName());
                if (requestedProofTokenContent instanceof JAXBElement) {
                    JAXBElement requestedProofTokenElement = (JAXBElement) requestedProofTokenContent;
                    LOG.debug("requested proof token element: " + requestedProofTokenElement.getName());
                    if (WSConstants.BINARY_SECRET_QNAME.equals(requestedProofTokenElement.getName())) {
                        BinarySecretType serverBinarySecret = (BinarySecretType) requestedProofTokenElement
                                .getValue();
                        byte[] serverSecret = serverBinarySecret.getValue();
                        securityToken.setKey(serverSecret);
                    }
                }
            }
        }
    }

    Element requestedSecurityToken = this.wsTrustHandler.getRequestedSecurityToken();
    securityToken.setToken(requestedSecurityToken);
    securityToken.setRealm(appliesTo);
    securityToken.setStsLocation(this.location);
    securityToken.setParentSecurityToken(ipStsSecurityToken);

    return securityToken;
}

From source file:com.bluexml.side.portal.alfresco.reverse.reverser.EclipseReverser.java

protected void readAnyElements(Map<String, String> props, List<Object> any) {
    for (Object object : any) {
        String nodeName = null;//  ww w  . j a  va  2  s  .c o  m
        String nodeValue = null;
        if (object instanceof Element) {
            System.out.println(" any Element (w3c) ?" + object);
            Element el = (Element) object;
            nodeName = el.getNodeName();
            nodeValue = el.getTextContent();
            props.put(nodeName, nodeValue);
        } else if (object instanceof JAXBElement) {
            JAXBElement<String> jaxbE = (JAXBElement<String>) object;
            QName name = jaxbE.getName();
            nodeName = name.getLocalPart();
            nodeValue = jaxbE.getValue();
        }

        props.put(nodeName, nodeValue);
    }
}

From source file:be.agiv.security.client.SecureConversationClient.java

/**
 * Cancels a given secure conversation token for this WS-SecureConversation
 * enabled web service./*from   w ww . java2 s  .  com*/
 * 
 * @param secureConversationToken
 */
public void cancelSecureConversationToken(SecurityToken secureConversationToken) {
    RequestSecurityTokenType requestSecurityToken = this.objectFactory.createRequestSecurityTokenType();
    List<Object> requestSecurityTokenContent = requestSecurityToken.getAny();

    requestSecurityTokenContent.add(this.objectFactory.createRequestType(WSConstants.CANCEL_REQUEST_TYPE));

    CancelTargetType cancelTarget = this.objectFactory.createCancelTargetType();
    requestSecurityTokenContent.add(this.objectFactory.createCancelTarget(cancelTarget));
    SecurityTokenReferenceType securityTokenReference = this.wssObjectFactory
            .createSecurityTokenReferenceType();
    cancelTarget.setAny(this.wssObjectFactory.createSecurityTokenReference(securityTokenReference));
    ReferenceType reference = this.wssObjectFactory.createReferenceType();
    securityTokenReference.getAny().add(this.wssObjectFactory.createReference(reference));
    reference.setURI(secureConversationToken.getUnattachedReference());
    reference.setValueType(WSConstants.SECURE_CONVERSATION_TOKEN_TYPE);

    BindingProvider bindingProvider = (BindingProvider) this.port;
    this.wsAddressingHandler.setAddressing(WSConstants.SEC_CONV_CANCEL_ACTION, this.location);
    this.wsSecurityHandler.setKey(secureConversationToken.getKey(),
            secureConversationToken.getAttachedReference(), secureConversationToken.getToken(), false);

    RequestSecurityTokenResponseCollectionType requestSecurityTokenResponseCollection = this.port
            .requestSecurityToken(requestSecurityToken);

    List<RequestSecurityTokenResponseType> requestSecurityTokenResponseList = requestSecurityTokenResponseCollection
            .getRequestSecurityTokenResponse();
    RequestSecurityTokenResponseType requestSecurityTokenResponse = requestSecurityTokenResponseList.get(0);
    List<Object> requestSecurityTokenResponseContent = requestSecurityTokenResponse.getAny();
    boolean tokenCancelled = false;
    for (Object contentObject : requestSecurityTokenResponseContent) {
        LOG.debug("content object: " + contentObject.getClass().getName());
        if (contentObject instanceof JAXBElement) {
            JAXBElement jaxbElement = (JAXBElement) contentObject;
            QName qname = jaxbElement.getName();
            LOG.debug("qname: " + qname);
            if (WSConstants.REQUESTED_TOKEN_CANCELLED_QNAME.equals(qname)) {
                tokenCancelled = true;
            }
        }
    }
    if (false == tokenCancelled) {
        throw new RuntimeException("token not cancelled");
    }
}

From source file:be.fedict.eid.idp.protocol.ws_federation.sts.SecurityTokenServicePortImpl.java

@Override
public RequestSecurityTokenResponseCollectionType requestSecurityToken(RequestSecurityTokenType request) {
    List<Object> requestContent = request.getAny();
    String expectedAudience = null;
    for (Object requestObject : requestContent) {
        LOG.debug("request object type: " + requestObject.getClass().getName());
        if (requestObject instanceof JAXBElement) {
            JAXBElement jaxbElement = (JAXBElement) requestObject;
            QName qname = jaxbElement.getName();
            if (WSTrustConstants.TOKEN_TYPE_QNAME.equals(qname)) {
                String tokenType = (String) jaxbElement.getValue();
                if (false == WSTrustConstants.STATUS_TOKEN_TYPE.equals(tokenType)) {
                    throw new SecurityException("invalid response token type: " + tokenType);
                }//  w ww .  ja  v a  2 s.c  om
            } else if (WSTrustConstants.REQUEST_TYPE_QNAME.equals(qname)) {
                String requestType = (String) jaxbElement.getValue();
                if (false == WSTrustConstants.VALIDATE_REQUEST_TYPE.equals(requestType)) {
                    throw new SecurityException("invalid request type: " + requestType);
                }
            } else if (WSTrustConstants.VALIDATE_TARGET_QNAME.equals(qname)) {
                ValidateTargetType validateTarget = (ValidateTargetType) jaxbElement.getValue();
                Object validateTargetObject = validateTarget.getAny();
                if (null == validateTargetObject) {
                    throw new SecurityException("missing ValidateTarget content");
                }
                LOG.debug("ValidateTarget content type: " + validateTargetObject.getClass().getName());
                // TODO: verify content is indeed SecurityTokenReference
            }
        } else if (requestObject instanceof AppliesTo) {
            AppliesTo appliesTo = (AppliesTo) requestObject;
            LOG.debug("wsp:AppliesTo present");
            List<Object> appliesToContent = appliesTo.getAny();
            for (Object appliesToObject : appliesToContent) {
                LOG.debug("AppliesTo object type: " + appliesToObject.getClass().getName());
                if (appliesToObject instanceof JAXBElement) {
                    JAXBElement appliesToElement = (JAXBElement) appliesToObject;
                    QName appliesToQName = appliesToElement.getName();
                    if (WSTrustConstants.ENDPOINT_REFERENCE_QNAME.equals(appliesToQName)) {
                        EndpointReferenceType endpointReference = (EndpointReferenceType) appliesToElement
                                .getValue();
                        expectedAudience = endpointReference.getAddress().getValue();
                    }
                }
            }
        }
    }
    Element tokenElement = WSSecuritySoapHandler.getToken(this.context);
    if (null == tokenElement) {
        throw new SecurityException("missing Token");
    }
    LOG.debug("token element: " + tokenElement.getLocalName());
    LOG.debug("expected audience: " + expectedAudience);

    ServletContext servletContext = (ServletContext) context.getMessageContext()
            .get(MessageContext.SERVLET_CONTEXT);
    IdentityProviderConfiguration identityProviderConfiguration = IdentityProviderConfigurationFactory
            .getInstance(servletContext);

    boolean valid;
    String reason = null;
    try {
        validateToken(tokenElement, expectedAudience, identityProviderConfiguration);
        valid = true;
    } catch (Exception e) {
        LOG.error("error validating SAML token: " + e.getMessage(), e);
        valid = false;
        reason = e.getMessage();
    }

    RequestSecurityTokenResponseCollectionType responseCollection = this.objectFactory
            .createRequestSecurityTokenResponseCollectionType();

    List<RequestSecurityTokenResponseType> requestSecurityTokenResponses = responseCollection
            .getRequestSecurityTokenResponse();

    RequestSecurityTokenResponseType requestSecurityTokenResponse = this.objectFactory
            .createRequestSecurityTokenResponseType();
    requestSecurityTokenResponses.add(requestSecurityTokenResponse);

    List<Object> rstsContent = requestSecurityTokenResponse.getAny();

    rstsContent.add(this.objectFactory.createTokenType(WSTrustConstants.STATUS_TOKEN_TYPE));

    StatusType status = this.objectFactory.createStatusType();
    rstsContent.add(this.objectFactory.createStatus(status));
    if (valid) {
        status.setCode(WSTrustConstants.VALID_STATUS_CODE);
    } else {
        status.setCode(WSTrustConstants.INVALID_STATUS_CODE);
        status.setReason(reason);
    }

    return responseCollection;
}

From source file:com.evolveum.midpoint.model.common.expression.Expression.java

private ExpressionEvaluator<V, D> createEvaluator(Collection<JAXBElement<?>> evaluatorElements,
        ExpressionFactory factory, String contextDescription, Task task, OperationResult result)
        throws SchemaException, ObjectNotFoundException {
    if (evaluatorElements.isEmpty()) {
        throw new SchemaException("Empty evaluator list in " + contextDescription);
    }//  ww  w.j  ava2s .  com
    JAXBElement<?> fistEvaluatorElement = evaluatorElements.iterator().next();
    ExpressionEvaluatorFactory evaluatorFactory = factory.getEvaluatorFactory(fistEvaluatorElement.getName());
    if (evaluatorFactory == null) {
        throw new SchemaException("Unknown expression evaluator element " + fistEvaluatorElement.getName()
                + " in " + contextDescription);
    }
    return evaluatorFactory.createEvaluator(evaluatorElements, outputDefinition, contextDescription, task,
            result);
}

From source file:eu.europa.ec.markt.dss.signature.xades.XAdESProfileT.java

private void extendSignatureTag(Element signatureEl, UnsignedPropertiesType unsigned,
        SignatureFormat signatureFormat) throws IOException {

    XAdESSignature signature = new XAdESSignature(signatureEl);
    XAdESTimeStampType signatureTimestamp = createUnsignedXAdESProperties(
            signature.getSignatureTimestampData());

    UnsignedSignaturePropertiesType sp = unsigned.getUnsignedSignatureProperties();
    if (sp == null) {
        sp = xadesObjectFactory.createUnsignedSignaturePropertiesType();
        unsigned.setUnsignedSignatureProperties(sp);
    }/*ww w.  j  a v a2  s . c  o  m*/

    /* First we count the already existing timestamp */
    List<Object> existingTimestamp = new ArrayList<Object>();
    for (Object o : sp.getCounterSignatureOrSignatureTimeStampOrCompleteCertificateRefs()) {
        if (o instanceof JAXBElement) {
            JAXBElement e = (JAXBElement) o;
            if (e.getName().getLocalPart().equals("SignatureTimeStamp")) {
                existingTimestamp.add(o);
            }
        }
    }

    /*
     * We add the timestamp only if there is no timestamp or there is one but we goes for a extension of level -T
     * again
     */
    if (existingTimestamp.size() == 0
            || (existingTimestamp.size() > 0 && signatureFormat == SignatureFormat.XAdES_T)) {
        sp.getCounterSignatureOrSignatureTimeStampOrCompleteCertificateRefs()
                .add(xadesObjectFactory.createSignatureTimeStamp(signatureTimestamp));

        /*
         * for (Object o : existingTimestamp) {
         * sp.getCounterSignatureOrSignatureTimeStampOrCompleteCertificateRefs().remove(o); }
         */

    }

}

From source file:be.agiv.security.client.SecureConversationClient.java

/**
 * Gives back a secure conversation token using the given R-STS security
 * token. The R-STS security token should apply to this web service.
 * //  ww w. j a  v a2 s.  c om
 * @param rStsSecurityToken
 *            the R-STS security token.
 * @return the secure conversation token to be used to secure the web
 *         service calls.
 */
public SecurityToken getSecureConversationToken(SecurityToken rStsSecurityToken) {
    RequestSecurityTokenType requestSecurityToken = this.objectFactory.createRequestSecurityTokenType();
    List<Object> requestSecurityTokenContent = requestSecurityToken.getAny();

    requestSecurityTokenContent
            .add(this.objectFactory.createTokenType(WSConstants.SECURE_CONVERSATION_TOKEN_TYPE));

    requestSecurityTokenContent.add(this.objectFactory.createRequestType(WSConstants.ISSUE_REQUEST_TYPE));

    EntropyType entropy = this.objectFactory.createEntropyType();
    requestSecurityTokenContent.add(this.objectFactory.createEntropy(entropy));
    BinarySecretType binarySecret = this.objectFactory.createBinarySecretType();
    entropy.getAny().add(this.objectFactory.createBinarySecret(binarySecret));
    binarySecret.setType(WSConstants.SECRET_TYPE_NONCE);
    byte[] entropyData = new byte[256 / 8];
    this.secureRandom.setSeed(System.currentTimeMillis());
    this.secureRandom.nextBytes(entropyData);
    binarySecret.setValue(entropyData);

    requestSecurityTokenContent.add(this.objectFactory.createKeySize(256L));

    BindingProvider bindingProvider = (BindingProvider) this.port;
    this.wsAddressingHandler.setAddressing(WSConstants.SEC_CONV_ISSUE_ACTION, this.location);
    this.wsSecurityHandler.setKey(rStsSecurityToken.getKey(), rStsSecurityToken.getAttachedReference(),
            rStsSecurityToken.getToken());

    RequestSecurityTokenResponseCollectionType requestSecurityTokenResponseCollection = this.port
            .requestSecurityToken(requestSecurityToken);

    SecurityToken securityToken = new SecurityToken();

    List<RequestSecurityTokenResponseType> requestSecurityTokenResponseList = requestSecurityTokenResponseCollection
            .getRequestSecurityTokenResponse();
    RequestSecurityTokenResponseType requestSecurityTokenResponse = requestSecurityTokenResponseList.get(0);
    List<Object> requestSecurityTokenResponseContent = requestSecurityTokenResponse.getAny();
    for (Object contentObject : requestSecurityTokenResponseContent) {
        LOG.debug("content object: " + contentObject.getClass().getName());
        if (contentObject instanceof Element) {
            Element contentElement = (Element) contentObject;
            LOG.debug("element name: " + contentElement.getLocalName());
        }
        if (contentObject instanceof JAXBElement) {
            JAXBElement jaxbElement = (JAXBElement) contentObject;
            QName qname = jaxbElement.getName();
            if (WSConstants.ENTROPY_QNAME.equals(qname)) {
                LOG.debug("trust:Entropy");
                EntropyType serverEntropy = (EntropyType) jaxbElement.getValue();
                List<Object> entropyContent = serverEntropy.getAny();
                for (Object entropyObject : entropyContent) {
                    if (entropyObject instanceof JAXBElement) {
                        JAXBElement entropyElement = (JAXBElement) entropyObject;
                        if (WSConstants.BINARY_SECRET_QNAME.equals(entropyElement.getName())) {
                            BinarySecretType serverBinarySecret = (BinarySecretType) entropyElement.getValue();
                            byte[] serverSecret = serverBinarySecret.getValue();
                            P_SHA1 p_SHA1 = new P_SHA1();
                            byte[] key;
                            try {
                                key = p_SHA1.createKey(entropyData, serverSecret, 0, 256 / 8);
                            } catch (ConversationException e) {
                                LOG.error(e);
                                return null;
                            }
                            LOG.debug("client secret size: " + entropyData.length);
                            LOG.debug("server secret size: " + serverSecret.length);
                            LOG.debug("key size: " + key.length);
                            securityToken.setKey(key);
                        }
                    }
                }
            } else if (WSConstants.LIFETIME_QNAME.equals(qname)) {
                LOG.debug("trust:Lifetime");
                LifetimeType lifetime = (LifetimeType) jaxbElement.getValue();
                String createdValue = lifetime.getCreated().getValue();
                DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTimeParser();
                DateTime created = dateTimeFormatter.parseDateTime(createdValue);
                securityToken.setCreated(created.toDate());
                String expiresString = lifetime.getExpires().getValue();
                DateTime expires = dateTimeFormatter.parseDateTime(expiresString);
                securityToken.setExpires(expires.toDate());
            } else if (WSConstants.REQUESTED_ATTACHED_REFERENCE_QNAME.equals(qname)) {
                RequestedReferenceType requestedReference = (RequestedReferenceType) jaxbElement.getValue();
                SecurityTokenReferenceType securityTokenReference = requestedReference
                        .getSecurityTokenReference();
                List<Object> securityTokenReferenceContent = securityTokenReference.getAny();
                for (Object securityTokenReferenceObject : securityTokenReferenceContent) {
                    LOG.debug("SecurityTokenReference object: "
                            + securityTokenReferenceObject.getClass().getName());
                    if (securityTokenReferenceObject instanceof JAXBElement) {
                        JAXBElement securityTokenReferenceElement = (JAXBElement) securityTokenReferenceObject;
                        LOG.debug("SecurityTokenReference element: " + securityTokenReferenceElement.getName());
                        if (WSConstants.REFERENCE_QNAME.equals(securityTokenReferenceElement.getName())) {
                            ReferenceType reference = (ReferenceType) securityTokenReferenceElement.getValue();
                            String tokenIdentifier = reference.getURI().substring(1);
                            securityToken.setAttachedReference(tokenIdentifier);
                        }
                    }
                }
            } else if (WSConstants.REQUESTED_UNATTACHED_REFERENCE_QNAME.equals(qname)) {
                RequestedReferenceType requestedReference = (RequestedReferenceType) jaxbElement.getValue();
                SecurityTokenReferenceType securityTokenReference = requestedReference
                        .getSecurityTokenReference();
                List<Object> securityTokenReferenceContent = securityTokenReference.getAny();
                for (Object securityTokenReferenceObject : securityTokenReferenceContent) {
                    LOG.debug("SecurityTokenReference object: "
                            + securityTokenReferenceObject.getClass().getName());
                    if (securityTokenReferenceObject instanceof JAXBElement) {
                        JAXBElement securityTokenReferenceElement = (JAXBElement) securityTokenReferenceObject;
                        LOG.debug("SecurityTokenReference element: " + securityTokenReferenceElement.getName());
                        if (WSConstants.REFERENCE_QNAME.equals(securityTokenReferenceElement.getName())) {
                            ReferenceType reference = (ReferenceType) securityTokenReferenceElement.getValue();
                            String tokenIdentifier = reference.getURI();
                            securityToken.setUnattachedReference(tokenIdentifier);
                        }
                    }
                }
            }
        }
    }

    Element requestedSecurityToken = this.wsTrustHandler.getRequestedSecurityToken();
    securityToken.setToken(requestedSecurityToken);
    securityToken.setStsLocation(this.location);
    securityToken.setRealm(this.location); // what else?
    securityToken.setParentSecurityToken(rStsSecurityToken);

    return securityToken;
}

From source file:be.agiv.security.client.IPSTSClient.java

/**
 * NOT FUNCTIONAL./*from  w  w w  .  j  a  v  a 2s  .  co  m*/
 * 
 * @param securityToken
 */
public void cancelSecurityToken(SecurityToken securityToken) {
    RequestSecurityTokenType requestSecurityToken = this.objectFactory.createRequestSecurityTokenType();
    List<Object> requestSecurityTokenContent = requestSecurityToken.getAny();

    requestSecurityTokenContent.add(this.objectFactory.createRequestType(WSConstants.CANCEL_REQUEST_TYPE));

    CancelTargetType cancelTarget = this.objectFactory.createCancelTargetType();
    requestSecurityTokenContent.add(this.objectFactory.createCancelTarget(cancelTarget));
    SecurityTokenReferenceType securityTokenReference = this.wssObjectFactory
            .createSecurityTokenReferenceType();
    cancelTarget.setAny(this.wssObjectFactory.createSecurityTokenReference(securityTokenReference));
    KeyIdentifierType keyIdentifier = this.wssObjectFactory.createKeyIdentifierType();
    securityTokenReference.getAny().add(this.wssObjectFactory.createKeyIdentifier(keyIdentifier));
    keyIdentifier.setValue(securityToken.getUnattachedReference());
    keyIdentifier.setValueType(WSConstants.SAML_KEY_IDENTIFIER_TYPE);

    BindingProvider bindingProvider = (BindingProvider) this.port;
    this.wsAddressingHandler.setAddressing(WSConstants.WS_TRUST_CANCEL_ACTION, this.location);
    this.wsSecurityHandler.setCredentials((String) null, (String) null);
    this.wsSecurityHandler.setKey(securityToken.getKey(), securityToken.getAttachedReference(),
            securityToken.getToken());

    RequestSecurityTokenResponseCollectionType requestSecurityTokenResponseCollection = this.port
            .requestSecurityToken(requestSecurityToken);

    List<RequestSecurityTokenResponseType> requestSecurityTokenResponseList = requestSecurityTokenResponseCollection
            .getRequestSecurityTokenResponse();
    RequestSecurityTokenResponseType requestSecurityTokenResponse = requestSecurityTokenResponseList.get(0);
    List<Object> requestSecurityTokenResponseContent = requestSecurityTokenResponse.getAny();
    boolean tokenCancelled = false;
    for (Object contentObject : requestSecurityTokenResponseContent) {
        LOG.debug("content object: " + contentObject.getClass().getName());
        if (contentObject instanceof JAXBElement) {
            JAXBElement jaxbElement = (JAXBElement) contentObject;
            QName qname = jaxbElement.getName();
            LOG.debug("qname: " + qname);
            if (WSConstants.REQUESTED_TOKEN_CANCELLED_QNAME.equals(qname)) {
                tokenCancelled = true;
            }
        }
    }
    if (false == tokenCancelled) {
        throw new RuntimeException("token not cancelled");
    }
}

From source file:com.netflix.imfutility.cpl._2013.Cpl2013ContextBuilderStrategy.java

@Override
protected void buildFromCpl() {
    // 1. get a composition edit rate (it's used if no specific edit rate is specified for a segment).
    this.compositionEditRate = ConversionHelper.parseEditRate(cpl2013.getEditRate());

    // 2. go through all segments and all sequences and build segment, sequence and resource contexts.
    for (SegmentType segment : cpl2013.getSegmentList().getSegment()) {
        this.currentSegmentUuid = SegmentUUID.create(segment.getId());

        contextProvider.getSegmentContext().initSegment(currentSegmentUuid);

        for (Object anySeqJaxb : segment.getSequenceList().getAny()) {
            if (!(anySeqJaxb instanceof JAXBElement)) {
                throw new ConversionException(
                        String.format("Could not understand a sequence '%s'", anySeqJaxb.toString()));
            }/* w  w  w.j  ava 2  s  .  c  o m*/

            JAXBElement jaxbElement = (JAXBElement) (anySeqJaxb);
            Object anySeq = jaxbElement.getValue();

            SequenceTypeCpl currentSequenceTypeCpl = SequenceTypeCpl
                    .fromName(jaxbElement.getName().getLocalPart());
            if ((currentSequenceTypeCpl != null) && (anySeq instanceof SequenceType)) {
                this.currentSequence = (SequenceType) anySeq;
                this.currentSequenceType = currentSequenceTypeCpl.toSequenceType();
                this.currentSequenceUuid = SequenceUUID.create(currentSequence.getTrackId());
                processSequence();
            }
        }
    }
}