keycloak-service
公開メンバ関数 | 関数 | 全メンバ一覧
org.keycloak.broker.saml.SAMLDataMarshaller クラス
org.keycloak.broker.saml.SAMLDataMarshaller の継承関係図
Inheritance graph
org.keycloak.broker.saml.SAMLDataMarshaller 連携図
Collaboration graph

公開メンバ関数

String serialize (Object obj)
 

関数

public< T > T deserialize (String serialized, Class< T > clazz)
 

詳解

著者
Marek Posolda

関数詳解

◆ deserialize()

public<T> T org.keycloak.broker.saml.SAMLDataMarshaller.deserialize ( String  serialized,
Class< T >  clazz 
)
inlinepackage
75  {
76  if (clazz.getName().startsWith("org.keycloak.dom.saml")) {
77  String xmlString = serialized;
78 
79  try {
80  if (clazz.equals(ResponseType.class) || clazz.equals(AssertionType.class) || clazz.equals(AuthnStatementType.class)) {
81  byte[] bytes = xmlString.getBytes(GeneralConstants.SAML_CHARSET);
82  InputStream is = new ByteArrayInputStream(bytes);
83  Object respType = SAMLParser.getInstance().parse(is);
84  return clazz.cast(respType);
85  } else {
86  throw new IllegalArgumentException("Don't know how to deserialize object of type " + clazz.getName());
87  }
88  } catch (ParsingException pe) {
89  throw new RuntimeException(pe);
90  }
91 
92  } else {
93  return super.deserialize(serialized, clazz);
94  }
95  }

◆ serialize()

String org.keycloak.broker.saml.SAMLDataMarshaller.serialize ( Object  obj)
inline
42  {
43 
44  // Lame impl, but hopefully sufficient for now. See if something better is needed...
45  if (obj.getClass().getName().startsWith("org.keycloak.dom.saml")) {
46  ByteArrayOutputStream bos = new ByteArrayOutputStream();
47 
48  try {
49  if (obj instanceof ResponseType) {
50  ResponseType responseType = (ResponseType) obj;
51  SAMLResponseWriter samlWriter = new SAMLResponseWriter(StaxUtil.getXMLStreamWriter(bos));
52  samlWriter.write(responseType, true);
53  } else if (obj instanceof AssertionType) {
54  AssertionType assertion = (AssertionType) obj;
55  SAMLAssertionWriter samlWriter = new SAMLAssertionWriter(StaxUtil.getXMLStreamWriter(bos));
56  samlWriter.write(assertion, true);
57  } else if (obj instanceof AuthnStatementType) {
58  AuthnStatementType authnStatement = (AuthnStatementType) obj;
59  SAMLAssertionWriter samlWriter = new SAMLAssertionWriter(StaxUtil.getXMLStreamWriter(bos));
60  samlWriter.write(authnStatement, true);
61  } else {
62  throw new IllegalArgumentException("Don't know how to serialize object of type " + obj.getClass().getName());
63  }
64  } catch (ProcessingException pe) {
65  throw new RuntimeException(pe);
66  }
67 
68  return new String(bos.toByteArray(), GeneralConstants.SAML_CHARSET);
69  } else {
70  return super.serialize(obj);
71  }
72  }

このクラス詳解は次のファイルから抽出されました: