public SecurityToken getSecurityToken()

in modules/rampart-integration/src/main/java/org/apache/sandesha2/security/rampart/RampartBasedSecurityManager.java [210:298]


	public SecurityToken getSecurityToken(MessageContext message)
			throws SandeshaException {
		String contextIdentifierKey = RampartUtil
				.getContextIdentifierKey(message);
		String identifier = (String) RampartUtil.getContextMap(message).get(
				contextIdentifierKey);

		if (identifier == null && !message.isServerSide()) {
			try {
				OMElement rstTmpl = RampartUtil.createRSTTempalteForSCT(
						ConversationConstants.VERSION_05_02,
						RahasConstants.VERSION_05_02);

				String action = TrustUtil.getActionValue(
						RahasConstants.VERSION_05_02,
						RahasConstants.RST_ACTION_SCT);

				Policy servicePolicy = (Policy) message
						.getProperty(RampartMessageData.KEY_RAMPART_POLICY);
				if (servicePolicy == null) {
					//Missing service policy means no security requirement
					return null;
				}
				List it = (List) servicePolicy.getAlternatives().next();
				RampartPolicyData rpd = RampartPolicyBuilder.build(it);

				SecureConversationToken secConvTok = null;

				org.apache.ws.secpolicy.model.Token encrtok = rpd
						.getEncryptionToken();
				secConvTok = (encrtok != null && encrtok instanceof SecureConversationToken) ? (SecureConversationToken) encrtok
						: null;

				if (secConvTok == null) {
					org.apache.ws.secpolicy.model.Token sigtok = rpd
							.getSignatureToken();
					secConvTok = (sigtok != null && sigtok instanceof SecureConversationToken) ? (SecureConversationToken) sigtok
							: null;
				}

				if (secConvTok != null) {

					Policy issuerPolicy = secConvTok.getBootstrapPolicy();
					issuerPolicy.addAssertion(rpd.getRampartConfig());

					STSClient client = new STSClient(message
							.getConfigurationContext());
					Options op = new Options();
					op.setProperty(SandeshaClientConstants.UNRELIABLE_MESSAGE,
							Constants.VALUE_TRUE);
					client.setOptions(op);
					client.setAction(action);
					client.setRstTemplate(rstTmpl);
					client.setCryptoInfo(RampartUtil.getEncryptionCrypto(rpd
							.getRampartConfig(), message.getAxisService()
							.getClassLoader()), RampartUtil.getPasswordCB(
							message, rpd));
					String address = message.getTo().getAddress();
					Token tok = client.requestSecurityToken(servicePolicy,
							address, issuerPolicy, null);

					tok.setState(Token.ISSUED);
					this.storage.add(tok);

					contextIdentifierKey = RampartUtil
							.getContextIdentifierKey(message);
					RampartUtil.getContextMap(message).put(
							contextIdentifierKey, tok.getId());
					identifier = tok.getId();

				} else {
					String msg = SandeshaMessageHelper
							.getMessage(SandeshaMessageKeys.noSecConvTokenInPolicy);
					log.debug(msg);
					return null;
				}

			} catch (RampartException e) {
				throw new SandeshaException(e.getMessage(), e);
			} catch (TrustException e) {
				throw new SandeshaException(e.getMessage(), e);
			} catch (WSSPolicyException e) {
				throw new SandeshaException(e.getMessage(), e);
			}
		}

		return this.recoverSecurityToken(identifier);

	}