/** * <p> * Creates a {@code NameIDType} instance with the specified values. * </p> * * @param format a {@code String} representing the name format. * @param qualifier a {@code String} representing the name qualifier. * @param value a {@code String} representing the name value. * @return the constructed {@code NameIDType} instance. */ public static NameIDType createNameID(String format, String qualifier, String value) { NameIDType nameID = new NameIDType(); if (format != null) nameID.setFormat(URI.create(format)); nameID.setNameQualifier(qualifier); nameID.setValue(value); return nameID; }
/** * <p> * Creates a {@code NameIDType} instance with the specified values. * </p> * * @param format a {@code String} representing the name format. * @param qualifier a {@code String} representing the name qualifier. * @param value a {@code String} representing the name value. * @return the constructed {@code NameIDType} instance. */ public static NameIDType createNameID(String format, String qualifier, String value) { NameIDType nameID = new NameIDType(); if (format != null) nameID.setFormat(URI.create(format)); nameID.setNameQualifier(qualifier); nameID.setValue(value); return nameID; }
/** * <p> * Creates a {@code NameIDType} instance with the specified values. * </p> * * @param format a {@code String} representing the name format. * @param qualifier a {@code String} representing the name qualifier. * @param value a {@code String} representing the name value. * @return the constructed {@code NameIDType} instance. */ public static NameIDType createNameID(String format, String qualifier, String value) { NameIDType nameID = new NameIDType(); if (format != null) nameID.setFormat(URI.create(format)); nameID.setNameQualifier(qualifier); nameID.setValue(value); return nameID; }
/** * <p> * Creates a {@code NameIDType} instance with the specified values. * </p> * * @param format a {@code String} representing the name format. * @param qualifier a {@code String} representing the name qualifier. * @param value a {@code String} representing the name value. * * @return the constructed {@code NameIDType} instance. */ public static NameIDType createNameID(String format, String qualifier, String value) { NameIDType nameID = new NameIDType(); if (format != null) nameID.setFormat(URI.create(format)); nameID.setNameQualifier(qualifier); nameID.setValue(value); return nameID; }
/** * <p> * Creates a {@code NameIDType} instance with the specified values. * </p> * * @param format a {@code String} representing the name format. * @param qualifier a {@code String} representing the name qualifier. * @param value a {@code String} representing the name value. * * @return the constructed {@code NameIDType} instance. */ public static NameIDType createNameID(String format, String qualifier, String value) { NameIDType nameID = new NameIDType(); if (format != null) nameID.setFormat(URI.create(format)); nameID.setNameQualifier(qualifier); nameID.setValue(value); return nameID; }
/** * <p>This method populate the request and session with a logout requests to start a global logout from the IdP.</p> * * @param request * @param userPrincipal */ private void prepareLocalGlobalLogoutRequest(Request request, Principal userPrincipal) { try { SAML2Request saml2Request = new SAML2Request(); LogoutRequestType lort = saml2Request.createLogoutRequest(getIdentityURL()); NameIDType nameID = new NameIDType(); nameID.setValue(userPrincipal.getName()); nameID.setFormat(URI.create(JBossSAMLURIConstants.NAMEID_FORMAT_PERSISTENT.get())); lort.setNameID(nameID); lort.setDestination(URI.create(getIdentityURL())); byte[] responseBytes = DocumentUtil.getDocumentAsString(saml2Request.convert(lort)).getBytes("UTF-8"); String samlRequest = RedirectBindingUtil.deflateBase64Encode(responseBytes); Session session = request.getSessionInternal(); session.setNote(SAML_REQUEST_KEY, samlRequest); } catch (Exception e) { throw new RuntimeException("Could not perform IdP Initiated Single Logout.", e); } }
/** * <p>This method populate the request and session with a logout requests to start a global logout from the IdP.</p> * * @param request * @param userPrincipal */ private void prepareLocalGlobalLogoutRequest(Request request, Principal userPrincipal) { try { SAML2Request saml2Request = new SAML2Request(); LogoutRequestType lort = saml2Request.createLogoutRequest(getIdentityURL()); NameIDType nameID = new NameIDType(); nameID.setValue(userPrincipal.getName()); nameID.setFormat(URI.create(JBossSAMLURIConstants.NAMEID_FORMAT_PERSISTENT.get())); lort.setNameID(nameID); lort.setDestination(URI.create(getIdentityURL())); byte[] responseBytes = DocumentUtil.getDocumentAsString(saml2Request.convert(lort)).getBytes("UTF-8"); String samlRequest = RedirectBindingUtil.deflateBase64Encode(responseBytes); Session session = request.getSessionInternal(); session.setNote(SAML_REQUEST_KEY, samlRequest); } catch (Exception e) { throw new RuntimeException("Could not perform IdP Initiated Single Logout.", e); } }
/** * <p>This method populate the request and session with a logout requests to start a global logout from the IdP.</p> * @param request * @param userPrincipal */ private HttpServletRequestWrapper prepareLocalGlobalLogoutRequest(HttpServletRequest request, Principal userPrincipal) { try { SAML2Request saml2Request = new SAML2Request(); LogoutRequestType lort = saml2Request.createLogoutRequest(getIdentityURL()); NameIDType nameID = new NameIDType(); nameID.setValue(userPrincipal.getName()); nameID.setFormat(URI.create(JBossSAMLURIConstants.NAMEID_FORMAT_PERSISTENT.get())); lort.setNameID(nameID); lort.setDestination(URI.create(getIdentityURL())); byte[] responseBytes = DocumentUtil.getDocumentAsString(saml2Request.convert(lort)).getBytes("UTF-8"); final String samlRequest = RedirectBindingUtil.deflateBase64Encode(responseBytes); return new HttpServletRequestWrapper(request) { @Override public String getParameter(String name) { if (SAML_REQUEST_KEY.equals(name)) { return samlRequest; } return super.getParameter(name); } }; } catch (Exception e) { throw new RuntimeException("Could not perform IdP Initiated Single Logout.", e); } }
/** * <p>This method populate the request and session with a logout requests to start a global logout from the IdP.</p> * @param request * @param userPrincipal */ private HttpServletRequestWrapper prepareLocalGlobalLogoutRequest(HttpServletRequest request, Principal userPrincipal) { try { SAML2Request saml2Request = new SAML2Request(); LogoutRequestType lort = saml2Request.createLogoutRequest(getIdentityURL()); NameIDType nameID = new NameIDType(); nameID.setValue(userPrincipal.getName()); nameID.setFormat(URI.create(JBossSAMLURIConstants.NAMEID_FORMAT_PERSISTENT.get())); lort.setNameID(nameID); lort.setDestination(URI.create(getIdentityURL())); byte[] responseBytes = DocumentUtil.getDocumentAsString(saml2Request.convert(lort)).getBytes("UTF-8"); final String samlRequest = RedirectBindingUtil.deflateBase64Encode(responseBytes); return new HttpServletRequestWrapper(request) { @Override public String getParameter(String name) { if (SAML_REQUEST_KEY.equals(name)) { return samlRequest; } return super.getParameter(name); } }; } catch (Exception e) { throw new RuntimeException("Could not perform IdP Initiated Single Logout.", e); } }
/** * <p>This method populate the request and session with a logout requests to start a global logout from the IdP.</p> * * @param request * @param userPrincipal */ private void prepareLocalGlobalLogoutRequest(Request request, Principal userPrincipal) { try { SAML2Request saml2Request = new SAML2Request(); LogoutRequestType lort = saml2Request.createLogoutRequest(getIdentityURL()); NameIDType nameID = new NameIDType(); nameID.setValue(userPrincipal.getName()); nameID.setFormat(URI.create(JBossSAMLURIConstants.NAMEID_FORMAT_PERSISTENT.get())); lort.setNameID(nameID); lort.setDestination(URI.create(getIdentityURL())); byte[] responseBytes = DocumentUtil.getDocumentAsString(saml2Request.convert(lort)).getBytes("UTF-8"); String samlRequest = RedirectBindingUtil.deflateBase64Encode(responseBytes); Session session = request.getSessionInternal(); session.setNote(SAML_REQUEST_KEY, samlRequest); } catch (Exception e) { throw new RuntimeException("Could not perform IdP Initiated Single Logout.", e); } }
nameIDFormat = JBossSAMLURIConstants.NAMEID_FORMAT_PERSISTENT.get(); nameID.setFormat(URI.create(nameIDFormat)); lot.setNameID(nameID);
/** * Parse a {@code NameIDType} * * @param xmlEventReader * @return * @throws ParsingException */ public static NameIDType parseNameIDType(XMLEventReader xmlEventReader) throws ParsingException { StartElement nameIDElement = StaxParserUtil.getNextStartElement(xmlEventReader); NameIDType nameID = new NameIDType(); Attribute nameQualifier = nameIDElement.getAttributeByName(new QName(JBossSAMLConstants.NAME_QUALIFIER.get())); if (nameQualifier != null) { nameID.setNameQualifier(StaxParserUtil.getAttributeValue(nameQualifier)); } Attribute format = nameIDElement.getAttributeByName(new QName(JBossSAMLConstants.FORMAT.get())); if (format != null) { nameID.setFormat(URI.create(StaxParserUtil.getAttributeValue(format))); } Attribute spProvidedID = nameIDElement.getAttributeByName(new QName(JBossSAMLConstants.SP_PROVIDED_ID.get())); if (spProvidedID != null) { nameID.setSPProvidedID(StaxParserUtil.getAttributeValue(spProvidedID)); } Attribute spNameQualifier = nameIDElement.getAttributeByName(new QName(JBossSAMLConstants.SP_NAME_QUALIFIER.get())); if (spNameQualifier != null) { nameID.setSPNameQualifier(StaxParserUtil.getAttributeValue(spNameQualifier)); } String nameIDValue = StaxParserUtil.getElementText(xmlEventReader); nameID.setValue(nameIDValue); return nameID; }
nameID.setFormat(URI.create(StaxParserUtil.getAttributeValue(format)));
nameID.setFormat(URI.create(StaxParserUtil.getAttributeValue(format)));
private LogoutRequestType createLogoutRequest(SAML2HandlerRequest request, String participant) throws ConfigurationException, ProcessingException { HTTPContext httpContext = (HTTPContext) request.getContext(); HttpServletRequest httpServletRequest = httpContext.getRequest(); LogoutRequestType lort = new SAML2Request().createLogoutRequest(request.getIssuer().getValue()); Principal userPrincipal = httpServletRequest.getUserPrincipal(); if (userPrincipal == null) { throw logger.samlHandlerPrincipalNotFoundError(); } NameIDType nameID = new NameIDType(); nameID.setValue(userPrincipal.getName()); //Deal with NameID Format String nameIDFormat = (String) handlerConfig.getParameter(GeneralConstants.NAMEID_FORMAT); if (StringUtil.isNullOrEmpty(nameIDFormat)) { nameIDFormat = JBossSAMLURIConstants.NAMEID_FORMAT_PERSISTENT.get(); } nameID.setFormat(URI.create(nameIDFormat)); lort.setNameID(nameID); long assertionValidity = PicketLinkCoreSTS.instance().getConfiguration().getIssuedTokenTimeout(); lort.setNotOnOrAfter(XMLTimeUtil.add(lort.getIssueInstant(), assertionValidity)); lort.setDestination(URI.create(participant)); return lort; }
private LogoutRequestType createLogoutRequest(SAML2HandlerRequest request, String participant) throws ConfigurationException, ProcessingException { HTTPContext httpContext = (HTTPContext) request.getContext(); HttpServletRequest httpServletRequest = httpContext.getRequest(); LogoutRequestType lort = new SAML2Request().createLogoutRequest(request.getIssuer().getValue()); Principal userPrincipal = httpServletRequest.getUserPrincipal(); if (userPrincipal == null) { throw logger.samlHandlerPrincipalNotFoundError(); } NameIDType nameID = new NameIDType(); nameID.setValue(userPrincipal.getName()); //Deal with NameID Format String nameIDFormat = (String) handlerConfig.getParameter(GeneralConstants.NAMEID_FORMAT); if (StringUtil.isNullOrEmpty(nameIDFormat)) { nameIDFormat = JBossSAMLURIConstants.NAMEID_FORMAT_PERSISTENT.get(); } nameID.setFormat(URI.create(nameIDFormat)); lort.setNameID(nameID); long assertionValidity = PicketLinkCoreSTS.instance().getConfiguration().getIssuedTokenTimeout(); lort.setNotOnOrAfter(XMLTimeUtil.add(lort.getIssueInstant(), assertionValidity)); lort.setDestination(URI.create(participant)); return lort; }
if (format != null) nameID.setFormat(URI.create(StaxParserUtil.getAttributeValue(format)));
if (format != null) nameID.setFormat(URI.create(StaxParserUtil.getAttributeValue(format)));
nameIDType.setFormat(URI.create(JBossSAMLURIConstants.NAMEID_FORMAT_PERSISTENT.get())); nameIDType.setValue(userName);
nameIDType.setFormat(URI.create(JBossSAMLURIConstants.NAMEID_FORMAT_PERSISTENT.get())); nameIDType.setValue(userName);