public STSClient create(final STSClientConfig config) throws ParsingException { return new STSClient(config); } }
/** * Validate that we have a {@code Dispatch} to work with */ private void validateDispatch() { if (getDispatch() == null) throw new RuntimeException(ErrorCodes.INJECTED_VALUE_MISSING + "Dispatch"); } }
setAppliesTo(endpointURI, request); setTokenType(tokenType, request); setOnBehalfOf(principal, request); return issueToken(request);
/** * Issues a Security Token from the STS. This methods has the option of specifying one or both of * endpointURI/tokenType but at least one must specified. * * @param endpointURI * - The ultimate recipient of the token. This will be set at the AppliesTo for the RequestSecurityToken * which is an optional element so it may be null. * @param tokenType * - The type of security token to be issued. * @return Element - The Security Token Element issued. * @throws IllegalArgumentException * If neither endpointURI nor tokenType was specified. * @throws WSTrustException */ public Element issueToken(String endpointURI, String tokenType) throws WSTrustException { if (endpointURI == null && tokenType == null) throw new IllegalArgumentException(ErrorCodes.NULL_ARGUMENT + "endpointURI or tokenType"); RequestSecurityToken request = new RequestSecurityToken(); if (wsaIssuerAddress != null) { request.setIssuer(WSTrustUtil.createIssuer(wsaIssuerAddress)); } setAppliesTo(endpointURI, request); setTokenType(tokenType, request); return issueToken(request); }
/** * Issues a Security Token for the ultimate recipient of the token. * * @param endpointURI - The ultimate recipient of the token. This will be set at the AppliesTo for the RequestSecurityToken * which is an optional element so it may be null. * @return Element - The Security Token Element which will be of the TokenType configured for the endpointURI passed in. * @throws WSTrustException */ public Element issueTokenForEndpoint(String endpointURI) throws WSTrustException { RequestSecurityToken request = new RequestSecurityToken(); if (wsaIssuerAddress != null) { request.setIssuer(WSTrustUtil.createIssuer(wsaIssuerAddress)); } setAppliesTo(endpointURI, request); return issueToken(request); }
validateDispatch(); RequestSecurityToken request = new RequestSecurityToken(); request.setContext("context"); DOMSource requestSource = this.createSourceFromRequest(request); Source response = dispatchLocal.get().invoke(requestSource); NodeList nodes;
token = getSamlTokenFromCaller(); final boolean result = stsClient.validateToken(token); log.debug("Validation result: " + result); if (result == false)
/** * Issue a token * * @param tokenType * @return * @throws WSTrustException */ public Element issueToken(String tokenType) throws WSTrustException { // create a custom token request message. RequestSecurityToken request = new RequestSecurityToken(); setTokenType(tokenType, request); if (wsaIssuerAddress != null) { request.setIssuer(WSTrustUtil.createIssuer(wsaIssuerAddress)); } if (wspAppliesTo != null) { request.setAppliesTo(WSTrustUtil.createAppliesTo(wspAppliesTo)); } // send the token request to JBoss STS and get the response. return issueToken(request); }
/** * This method will issue a token for the configured user. * * @return Element The issued element. * * @throws javax.security.auth.login.LoginException If an error occurs while trying to perform the authentication. */ public Element invokeSTS(final STSClient stsClient) throws WSTrustException { return stsClient.issueToken(endpointURI, tokenType); } }
/** * <p> * Constructor that creates the {@link Dispatch} for use. * </p> * <p> * If you need to customize the ws properties, it is suggested to preconstruct a {@link Dispatch} * object and use the default no-arg constructor followed by a {@linkplain #setDispatch(Dispatch)} call * </p> * @param config */ public STSClient(STSClientConfig config) { QName service = new QName(targetNS, config.getServiceName()); QName portName = new QName(targetNS, config.getPortName()); isBatch = config.isBatch(); wsaIssuerAddress = config.getWsaIssuer(); wspAppliesTo = config.getWspAppliesTo(); Service jaxwsService = Service.create(service); jaxwsService.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, config.getEndPointAddress()); Dispatch<Source> dispatch = jaxwsService.createDispatch(portName, Source.class, Mode.PAYLOAD); Map<String, Object> reqContext = dispatch.getRequestContext(); String username = config.getUsername(); if (username != null) { // add the username and password to the request context. reqContext.put(BindingProvider.USERNAME_PROPERTY, config.getUsername()); reqContext.put(BindingProvider.PASSWORD_PROPERTY, config.getPassword()); } setDispatch(dispatch); }
validateDispatch(); RequestSecurityToken request = new RequestSecurityToken(); request.setContext("context"); DOMSource requestSource = this.createSourceFromRequest(request); Source response = dispatchLocal.get().invoke(requestSource); NodeList nodes;
/** * Issues a Security Token from the STS. This methods has the option of specifying one or both of * endpointURI/tokenType but at least one must specified. * * @param endpointURI * - The ultimate recipient of the token. This will be set at the AppliesTo for the RequestSecurityToken * which is an optional element so it may be null. * @param tokenType * - The type of security token to be issued. * @return Element - The Security Token Element issued. * @throws IllegalArgumentException * If neither endpointURI nor tokenType was specified. * @throws WSTrustException */ public Element issueToken(String endpointURI, String tokenType) throws WSTrustException { if (endpointURI == null && tokenType == null) throw new IllegalArgumentException(ErrorCodes.NULL_ARGUMENT + "endpointURI or tokenType"); RequestSecurityToken request = new RequestSecurityToken(); if (wsaIssuerAddress != null) { request.setIssuer(WSTrustUtil.createIssuer(wsaIssuerAddress)); } setAppliesTo(endpointURI, request); setTokenType(tokenType, request); return issueToken(request); }
token = getSamlTokenFromCaller(); final boolean result = stsClient.validateToken(token); log.debug("Validation result: " + result); if (result == false)
/** * Issues a Security Token for the ultimate recipient of the token. * * @param endpointURI * - The ultimate recipient of the token. This will be set at the AppliesTo for the RequestSecurityToken * which is an optional element so it may be null. * @return Element - The Security Token Element which will be of the TokenType configured for the endpointURI passed * in. * @throws WSTrustException */ public Element issueTokenForEndpoint(String endpointURI) throws WSTrustException { RequestSecurityToken request = new RequestSecurityToken(); if (wsaIssuerAddress != null) { request.setIssuer(WSTrustUtil.createIssuer(wsaIssuerAddress)); } setAppliesTo(endpointURI, request); return issueToken(request); }
/** * Issue a token * * @param tokenType * * @return * * @throws WSTrustException */ public Element issueToken(String tokenType) throws WSTrustException { // create a custom token request message. RequestSecurityToken request = new RequestSecurityToken(); setTokenType(tokenType, request); if (wsaIssuerAddress != null) { request.setIssuer(WSTrustUtil.createIssuer(wsaIssuerAddress)); } if (wspAppliesTo != null) { request.setAppliesTo(WSTrustUtil.createAppliesTo(wspAppliesTo)); } // send the token request to JBoss STS and get the response. return issueToken(request); }
/** * This method will issue a token for the configured user. * * @return Element The issued element. * @throws LoginException If an error occurs while trying to perform the authentication. */ public Element invokeSTS(final STSClient stsClient) throws WSTrustException { return stsClient.issueToken(endpointURI, tokenType); } }
/** * <p> * Constructor that creates the {@link Dispatch} for use. * </p> * <p> * If you need to customize the ws properties, it is suggested to preconstruct a {@link Dispatch} * object and use the default no-arg constructor followed by a {@linkplain #setDispatch(Dispatch)} call * </p> * @param config */ public STSClient(STSClientConfig config) { QName service = new QName(targetNS, config.getServiceName()); QName portName = new QName(targetNS, config.getPortName()); isBatch = config.isBatch(); wsaIssuerAddress = config.getWsaIssuer(); wspAppliesTo = config.getWspAppliesTo(); Service jaxwsService = Service.create(service); jaxwsService.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, config.getEndPointAddress()); Dispatch<Source> dispatch = jaxwsService.createDispatch(portName, Source.class, Mode.PAYLOAD); Map<String, Object> reqContext = dispatch.getRequestContext(); String username = config.getUsername(); if (username != null) { // add the username and password to the request context. reqContext.put(BindingProvider.USERNAME_PROPERTY, config.getUsername()); reqContext.put(BindingProvider.PASSWORD_PROPERTY, config.getPassword()); } setDispatch(dispatch); }
setAppliesTo(endpointURI, request); setTokenType(tokenType, request); setOnBehalfOf(principal, request); return issueToken(request);
request.setContext("default-context"); validateDispatch(); DOMSource requestSource = this.createSourceFromRequest(request); Source response = dispatchLocal.get().invoke(requestSource);
/** * Issues a Security Token from the STS. This methods has the option of specifying one or both of endpointURI/tokenType but * at least one must specified. * * @param endpointURI - The ultimate recipient of the token. This will be set at the AppliesTo for the RequestSecurityToken * which is an optional element so it may be null. * @param tokenType - The type of security token to be issued. * @return Element - The Security Token Element issued. * @throws IllegalArgumentException If neither endpointURI nor tokenType was specified. * @throws WSTrustException */ public Element issueToken(String endpointURI, String tokenType) throws WSTrustException { if (endpointURI == null && tokenType == null) throw logger.nullArgumentError("endpointURI or tokenType"); RequestSecurityToken request = new RequestSecurityToken(); if (wsaIssuerAddress != null) { request.setIssuer(WSTrustUtil.createIssuer(wsaIssuerAddress)); } setAppliesTo(endpointURI, request); setTokenType(tokenType, request); return issueToken(request); }