Package org.cilogon.oauth2.servlet.util
Class DBServiceSerializer
- java.lang.Object
-
- org.cilogon.oauth2.servlet.util.DBServiceSerializer
-
- Direct Known Subclasses:
DBServiceSerializer2
public class DBServiceSerializer extends Object
A class that serializes to a print writer or deserializes to streams.Created by Jeff Gaynor
on Nov 19, 2010 at 11:03:15 AM
-
-
Field Summary
Fields Modifier and Type Field Description static StringCILOGON_CALLBACK_URIstatic StringCILOGON_FAILURE_URIstatic StringCILOGON_PORTAL_NAMEstatic StringCILOGON_SUCCESS_URIprotected org.oa4mp.delegation.common.storage.clients.ClientApprovalKeysclientApprovalKeysprotected org.oa4mp.delegation.common.storage.clients.ClientKeysclientKeysprotected IDPKeysidpKeysprotected TwoFactorSerializationKeystfKeysprotected UserKeysuserKeysstatic StringUTF8_ENCODING
-
Constructor Summary
Constructors Constructor Description DBServiceSerializer(UserKeys userKeys, IDPKeys idpKeys, TwoFactorSerializationKeys tfk, org.oa4mp.delegation.common.storage.clients.ClientKeys cKeys, org.oa4mp.delegation.common.storage.clients.ClientApprovalKeys caKeys)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckForStatus(String head, String tail)Checks the status line in the serialized object for error codes and throws a corresponding exception.Stringdecode(String x)List<IdentityProvider>deserializeIdps(InputStream is)edu.uiuc.ncsa.security.storage.XMLMapdeserializeToMap(InputStream is)This takes the serialized payload and pulls it into a simple map.UserdeserializeUser(InputStream is, User user)This takes a user as the argument since the user requires a reference to the namespace resolution machinery of the server environment.edu.uiuc.ncsa.security.core.IdentifierdeserializeUserID(InputStream is)protected voiddoUserSerialization(PrintWriter w, User user)Override this method if you have to extend the user.protected Stringencode(String x)protected Stringencode(URI x)protected voidonlyPrintIfNotTrivial(PrintWriter w, String key, String value)protected String[]parseLine(String linein)protected voidprint(PrintWriter w, String key, edu.uiuc.ncsa.security.core.Identifier identifier)voidprint(PrintWriter w, String key, Object value)voidprint(PrintWriter w, String key, String value)protected voidprint(PrintWriter w, String key, URI uri)protected voidprint(PrintWriter w, String key, Date date)intreadResponseOnly(InputStream is)booleanreponseOk(InputStream is)Checks that the serialized content of the input stream has an ok as its status.voidserialize(PrintWriter w, edu.uiuc.ncsa.security.core.Identifier userid)voidserialize(PrintWriter w, Collection<IdentityProvider> idps)voidserialize(PrintWriter w, Map<String,Object> map)voidserialize(PrintWriter w, TwoFactorInfo tfi, int statusCode)voidserialize(PrintWriter w, User user, int statusCode)voidserialize(PrintWriter w, User user, TwoFactorInfo tfi, int statusCode)voidserialize(PrintWriter w, org.oa4mp.delegation.server.ServiceTransaction t)protected voidsetUserField(User user, String head, String tail)protected String[]splitLine(String linein)voidwriteMessage(PrintWriter w, int statusCode)voidwriteMessage(PrintWriter w, String message)
-
-
-
Field Detail
-
CILOGON_SUCCESS_URI
public static final String CILOGON_SUCCESS_URI
- See Also:
- Constant Field Values
-
CILOGON_FAILURE_URI
public static final String CILOGON_FAILURE_URI
- See Also:
- Constant Field Values
-
CILOGON_PORTAL_NAME
public static final String CILOGON_PORTAL_NAME
- See Also:
- Constant Field Values
-
CILOGON_CALLBACK_URI
public static final String CILOGON_CALLBACK_URI
- See Also:
- Constant Field Values
-
UTF8_ENCODING
public static final String UTF8_ENCODING
- See Also:
- Constant Field Values
-
userKeys
protected UserKeys userKeys
-
idpKeys
protected IDPKeys idpKeys
-
tfKeys
protected TwoFactorSerializationKeys tfKeys
-
clientKeys
protected org.oa4mp.delegation.common.storage.clients.ClientKeys clientKeys
-
clientApprovalKeys
protected org.oa4mp.delegation.common.storage.clients.ClientApprovalKeys clientApprovalKeys
-
-
Constructor Detail
-
DBServiceSerializer
public DBServiceSerializer(UserKeys userKeys, IDPKeys idpKeys, TwoFactorSerializationKeys tfk, org.oa4mp.delegation.common.storage.clients.ClientKeys cKeys, org.oa4mp.delegation.common.storage.clients.ClientApprovalKeys caKeys)
-
-
Method Detail
-
writeMessage
public void writeMessage(PrintWriter w, String message) throws IOException
- Throws:
IOException
-
writeMessage
public void writeMessage(PrintWriter w, int statusCode) throws IOException
- Throws:
IOException
-
serialize
public void serialize(PrintWriter w, Map<String,Object> map) throws IOException
- Throws:
IOException
-
serialize
public void serialize(PrintWriter w, TwoFactorInfo tfi, int statusCode) throws IOException
- Throws:
IOException
-
serialize
public void serialize(PrintWriter w, User user, TwoFactorInfo tfi, int statusCode) throws IOException
- Throws:
IOException
-
doUserSerialization
protected void doUserSerialization(PrintWriter w, User user) throws IOException
Override this method if you have to extend the user. This is where the user is written- Parameters:
w-user-- Throws:
IOException
-
onlyPrintIfNotTrivial
protected void onlyPrintIfNotTrivial(PrintWriter w, String key, String value) throws IOException
- Throws:
IOException
-
serialize
public void serialize(PrintWriter w, User user, int statusCode) throws IOException
- Throws:
IOException
-
serialize
public void serialize(PrintWriter w, Collection<IdentityProvider> idps) throws IOException
- Throws:
IOException
-
serialize
public void serialize(PrintWriter w, edu.uiuc.ncsa.security.core.Identifier userid) throws IOException
- Throws:
IOException
-
serialize
public void serialize(PrintWriter w, org.oa4mp.delegation.server.ServiceTransaction t) throws IOException
- Throws:
IOException
-
deserializeToMap
public edu.uiuc.ncsa.security.storage.XMLMap deserializeToMap(InputStream is) throws IOException
This takes the serialized payload and pulls it into a simple map. This is mostly used to deserialize things that might not be available to a client, such as a server transaction.Caveats
- The status is always stored as a Long
- List values are stored as List<String>'s
- This never throws an exception if there is an issue. You must decide on the course of action from the returned status code.
- Parameters:
is-- Returns:
- Throws:
IOException
-
reponseOk
public boolean reponseOk(InputStream is) throws IOException
Checks that the serialized content of the input stream has an ok as its status. This ignores the rest of the stream and discards it! Only use when you are sure there is nothing else to parse, but want to check that an operation worked. If there are other status codes, this will throw an exception corresponding to the error.- Parameters:
is-- Returns:
- Throws:
ExceptionIOException
-
readResponseOnly
public int readResponseOnly(InputStream is) throws IOException
- Throws:
IOException
-
deserializeUserID
public edu.uiuc.ncsa.security.core.Identifier deserializeUserID(InputStream is) throws IOException
- Throws:
IOException
-
deserializeUser
public User deserializeUser(InputStream is, User user) throws IOException, ParseException
This takes a user as the argument since the user requires a reference to the namespace resolution machinery of the server environment. It deserializes the stream into it, overwriting any of its content.- Parameters:
is-user-- Returns:
- Throws:
IOExceptionParseException
-
setUserField
protected void setUserField(User user, String head, String tail) throws ParseException, UnsupportedEncodingException
-
deserializeIdps
public List<IdentityProvider> deserializeIdps(InputStream is) throws IOException
- Throws:
IOException
-
splitLine
protected String[] splitLine(String linein) throws UnsupportedEncodingException
- Throws:
UnsupportedEncodingException
-
parseLine
protected String[] parseLine(String linein) throws UnsupportedEncodingException
- Throws:
UnsupportedEncodingException
-
checkForStatus
protected void checkForStatus(String head, String tail)
Checks the status line in the serialized object for error codes and throws a corresponding exception. If the status is ok, the call succeeds.- Parameters:
head-tail-
-
encode
protected String encode(String x) throws UnsupportedEncodingException
- Throws:
UnsupportedEncodingException
-
encode
protected String encode(URI x) throws UnsupportedEncodingException
- Throws:
UnsupportedEncodingException
-
decode
public String decode(String x) throws UnsupportedEncodingException
- Throws:
UnsupportedEncodingException
-
print
protected void print(PrintWriter w, String key, edu.uiuc.ncsa.security.core.Identifier identifier) throws IOException
- Throws:
IOException
-
print
protected void print(PrintWriter w, String key, URI uri) throws IOException
- Throws:
IOException
-
print
protected void print(PrintWriter w, String key, Date date) throws IOException
- Throws:
IOException
-
print
public void print(PrintWriter w, String key, String value) throws IOException
- Throws:
IOException
-
print
public void print(PrintWriter w, String key, Object value) throws IOException
- Throws:
IOException
-
-