@Override public Set<AttributeStatementType> getAttributes(AuthnRequestType authnRequestType, Principal userPrincipal) { if (delegate == null) throw logger.injectedValueMissing("Delegate"); Set<AttributeStatementType> attributeStatementTypes = new HashSet<AttributeStatementType>(); if (SAML2AttributeManager.class.isInstance(this.delegate)) { SAML2AttributeManager saml2AttributeManager = (SAML2AttributeManager) this.delegate; attributeStatementTypes.addAll(saml2AttributeManager.getAttributes(authnRequestType, userPrincipal)); } else { Map<String, Object> attributes = getAttributes(userPrincipal, this.attributeKeys); if (attributes != null) { AttributeStatementType attributeStatement = StatementUtil.createAttributeStatement(attributes); if (attributeStatement != null) { attributeStatementTypes.add(attributeStatement); } } } return attributeStatementTypes; } }
@Override public Set<AttributeStatementType> getAttributes(AuthnRequestType authnRequestType, Principal userPrincipal) { if (delegate == null) throw logger.injectedValueMissing("Delegate"); Set<AttributeStatementType> attributeStatementTypes = new HashSet<AttributeStatementType>(); if (SAML2AttributeManager.class.isInstance(this.delegate)) { SAML2AttributeManager saml2AttributeManager = (SAML2AttributeManager) this.delegate; attributeStatementTypes.addAll(saml2AttributeManager.getAttributes(authnRequestType, userPrincipal)); } else { Map<String, Object> attributes = getAttributes(userPrincipal, this.attributeKeys); if (attributes != null) { AttributeStatementType attributeStatement = StatementUtil.createAttributeStatement(attributes); if (attributeStatement != null) { attributeStatementTypes.add(attributeStatement); } } } return attributeStatementTypes; } }
@SuppressWarnings("unchecked") public void handleRequestType(SAML2HandlerRequest request, SAML2HandlerResponse response) throws ProcessingException { // Do not handle log out request interaction SAML2Object saml2Object = request.getSAML2Object(); if (saml2Object instanceof LogoutRequestType) return; // only handle IDP side if (getType() == HANDLER_TYPE.SP) return; HTTPContext httpContext = (HTTPContext) request.getContext(); HttpSession session = httpContext.getRequest().getSession(false); Principal userPrincipal = (Principal) session.getAttribute(GeneralConstants.PRINCIPAL_ID); AuthnRequestType authnRequestType = (AuthnRequestType) saml2Object; if (userPrincipal == null) { userPrincipal = httpContext.getRequest().getUserPrincipal(); } Map<String, Object> sessionAttributes = (Map<String, Object>) session.getAttribute(GeneralConstants.ATTRIBUTES); if (sessionAttributes == null) { Set<AttributeStatementType> attributes = this.attribManager.getAttributes(authnRequestType, userPrincipal); request.addOption(GeneralConstants.ATTRIBUTES, attributes); session.setAttribute(GeneralConstants.ATTRIBUTES, StatementUtil.asMap(attributes)); } }
@SuppressWarnings("unchecked") public void handleRequestType(SAML2HandlerRequest request, SAML2HandlerResponse response) throws ProcessingException { // Do not handle log out request interaction SAML2Object saml2Object = request.getSAML2Object(); if (saml2Object instanceof LogoutRequestType) return; // only handle IDP side if (getType() == HANDLER_TYPE.SP) return; HTTPContext httpContext = (HTTPContext) request.getContext(); HttpSession session = httpContext.getRequest().getSession(false); Principal userPrincipal = (Principal) session.getAttribute(GeneralConstants.PRINCIPAL_ID); AuthnRequestType authnRequestType = (AuthnRequestType) saml2Object; if (userPrincipal == null) { userPrincipal = httpContext.getRequest().getUserPrincipal(); } Map<String, Object> sessionAttributes = (Map<String, Object>) session.getAttribute(GeneralConstants.ATTRIBUTES); if (sessionAttributes == null) { Set<AttributeStatementType> attributes = this.attribManager.getAttributes(authnRequestType, userPrincipal); request.addOption(GeneralConstants.ATTRIBUTES, attributes); session.setAttribute(GeneralConstants.ATTRIBUTES, StatementUtil.asMap(attributes)); } }