Search in sources :

Example 6 with ExtraAttrs

use of org.maxkey.entity.ExtraAttrs in project MaxKey by dromara.

the class ExtendApiQiye163ExmailAdapter method authorize.

@Override
public ModelAndView authorize(ModelAndView modelAndView) {
    Apps details = (Apps) app;
    // extraAttrs from Applications
    ExtraAttrs extraAttrs = null;
    if (details.getIsExtendAttr() == 1) {
        extraAttrs = new ExtraAttrs(details.getExtendAttr());
    }
    String time = System.currentTimeMillis() + "";
    // 域名,请使用企业自己的域名
    String domain = details.getPrincipal();
    String account_name = this.userInfo.getEmail();
    // String lang = "0";
    String src = account_name + domain + time;
    String privateKey = details.getCredentials();
    String enc = null;
    try {
        enc = HexUtils.bytes2HexString(RSAUtils.sign(src.getBytes("UTF-8"), (RSAPrivateKey) RSAUtils.privateKey(HexUtils.hex2Bytes(privateKey)), null));
        String loginUrl = String.format(REDIRECT_URI, domain, account_name, time, enc);
        _logger.debug("LoginUrl {} ", loginUrl);
        modelAndView.addObject("redirect_uri", loginUrl);
    } catch (UnsupportedEncodingException e) {
        _logger.error("UnsupportedEncodingException ", e);
    } catch (Exception e) {
        _logger.error("Exception ", e);
    }
    return modelAndView;
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) ExtraAttrs(org.maxkey.entity.ExtraAttrs) Apps(org.maxkey.entity.apps.Apps) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 7 with ExtraAttrs

use of org.maxkey.entity.ExtraAttrs in project MaxKey by dromara.

the class AttributeStatementGenerator method generateAttributeStatement.

public AttributeStatement generateAttributeStatement(AppsSAML20Details saml20Details, ArrayList<GrantedAuthority> grantedAuthoritys, HashMap<String, String> attributeMap) {
    AttributeStatementBuilder attributeStatementBuilder = (AttributeStatementBuilder) builderFactory.getBuilder(AttributeStatement.DEFAULT_ELEMENT_NAME);
    AttributeStatement attributeStatement = attributeStatementBuilder.buildObject();
    Attribute attributeGrantedAuthority = builderGrantedAuthority(grantedAuthoritys);
    attributeStatement.getAttributes().add(attributeGrantedAuthority);
    putUserAttributes(attributeMap);
    if (null != attributeMap) {
        Iterator<Entry<String, String>> iterator = attributeMap.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, String> entry = (Map.Entry<String, String>) iterator.next();
            String key = entry.getKey();
            String value = entry.getValue();
            Attribute attribute = builderAttribute(key, value, Attribute.BASIC);
            attributeStatement.getAttributes().add(attribute);
        }
    }
    logger.debug("ExtendAttr " + saml20Details.getExtendAttr());
    if (ConstsBoolean.isTrue(saml20Details.getIsExtendAttr()) && saml20Details.getExtendAttr() != null) {
        ExtraAttrs extraAttrs = new ExtraAttrs(saml20Details.getExtendAttr());
        for (ExtraAttr extraAttr : extraAttrs.getExtraAttrs()) {
            extraAttr.setValue(extraAttr.getValue().replaceAll(COMMA_ISO8859_1, COMMA));
            logger.debug("Attribute : {} , Vale : {} , Type : {}", extraAttr.getAttr(), extraAttr.getValue(), extraAttr.getType());
            attributeStatement.getAttributes().add(builderAttribute(extraAttr.getAttr(), extraAttr.getValue(), extraAttr.getType()));
        }
    }
    return attributeStatement;
}
Also used : AttributeStatementBuilder(org.opensaml.saml2.core.impl.AttributeStatementBuilder) ExtraAttr(org.maxkey.entity.ExtraAttr) Entry(java.util.Map.Entry) Attribute(org.opensaml.saml2.core.Attribute) AttributeStatement(org.opensaml.saml2.core.AttributeStatement) XSString(org.opensaml.xml.schema.XSString) ExtraAttrs(org.maxkey.entity.ExtraAttrs) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ExtraAttrs (org.maxkey.entity.ExtraAttrs)7 Apps (org.maxkey.entity.apps.Apps)5 HashMap (java.util.HashMap)2 HttpRequestAdapter (org.maxkey.web.HttpRequestAdapter)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 ConstsOperateMessage (org.maxkey.constants.ConstsOperateMessage)1 ExtraAttr (org.maxkey.entity.ExtraAttr)1 Message (org.maxkey.web.message.Message)1 Attribute (org.opensaml.saml2.core.Attribute)1 AttributeStatement (org.opensaml.saml2.core.AttributeStatement)1 AttributeStatementBuilder (org.opensaml.saml2.core.impl.AttributeStatementBuilder)1 XSString (org.opensaml.xml.schema.XSString)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1