All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.ws.security.message.WSSecSecurityContextToken Maven / Gradle / Ivy

Go to download

The Apache WSS4J project provides a Java implementation of the primary security standards for Web Services, namely the OASIS Web Services Security (WS-Security) specifications from the OASIS Web Services Security TC.

There is a newer version: 1.6.19
Show newest version
/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.ws.security.message;

import org.apache.ws.security.WSSecurityException;
import org.apache.ws.security.components.crypto.Crypto;
import org.apache.ws.security.conversation.ConversationConstants;
import org.apache.ws.security.conversation.ConversationException;
import org.apache.ws.security.message.token.SecurityContextToken;
import org.apache.ws.security.util.WSSecurityUtil;
import org.w3c.dom.Document;

/**
 * Builder class to add a wsc:SecurityContextToken into the
 * wsse:Security
 * 
 * @author Ruchith Fernando ([email protected])
 */
public class WSSecSecurityContextToken {

    /**
     * The wsc:SecurityContextToken to be added to the
     * wsse:SecurityHeader
     */
    private SecurityContextToken sct;

    /**
     * The wsu:Id of the wsc:SecurityContextToken 
     */
    private String sctId;

    /**
     * The wsc:Identifier of the
     * wsc:SecurityContextToken
     */
    private String identifier;

    /**
     * The symmetric secret associated with the SecurityContextToken
     */
    protected byte[] secret;
    
    private int wscVersion = ConversationConstants.DEFAULT_VERSION;

    public void prepare(Document doc, Crypto crypto)
        throws WSSecurityException, ConversationException  {

        if (sct == null) {
            if (identifier != null) {
                sct = new SecurityContextToken(wscVersion, doc, identifier);
            } else {
                sct = new SecurityContextToken(wscVersion, doc);
                identifier = sct.getIdentifier();
            }
        }

        // The wsu:Id of the wsc:SecurityContextToken
        if (sctId != null) {
            sct.setID(sctId);
        }
    }

    public void prependSCTElementToHeader(Document doc, WSSecHeader secHeader)
        throws WSSecurityException {
        WSSecurityUtil.prependChildElement(secHeader.getSecurityHeader(), sct.getElement());
    }

    /**
     * @return Returns the sct.
     */
    public SecurityContextToken getSct() {
        return sct;
    }

    /**
     * @param sct The sct to set.
     */
    public void setSct(SecurityContextToken sct) {
        this.sct = sct;
    }

    /**
     * @return Returns the ephemeralKey.
     */
    public byte[] getSecret() {
        return secret;
    }

    /**
     * @param ephemeralKey The ephemeralKey to set.
     */
    protected void setSecret(byte[] ephemeralKey) {
        secret = ephemeralKey;
    }

    /**
     * @return Returns the identifier.
     */
    public String getIdentifier() {
        return identifier;
    }

    /**
     * @param identifier The identifier to set.
     */
    public void setIdentifier(String identifier) {
        this.identifier = identifier;
    }

    /**
     * @return Returns the sctId.
     */
    public String getSctId() {
        if (sct != null) {
            return sct.getID();
        }
        return sctId;
    }

    /**
     * @param sctId The sctId to set.
     */
    public void setSctId(String sctId) {
        this.sctId = sctId;
    }

    /**
     * @param wscVersion The wscVersion to set.
     */
    public void setWscVersion(int wscVersion) {
        this.wscVersion = wscVersion;
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy