Search in sources :

Example 1 with AccessTokenStatus

use of cbit.vcell.modeldb.ApiAccessToken.AccessTokenStatus in project vcell by virtualcell.

the class UserDbDriver method generateApiAccessToken.

public ApiAccessToken generateApiAccessToken(Connection con, KeyFactory keyFactory, KeyValue apiClientKey, User user, Date expirationDate) throws SQLException {
    String sql;
    KeyValue key = keyFactory.getNewKey(con);
    UUID idOne = UUID.randomUUID();
    Date creationDate = new Date();
    String token = idOne.toString();
    AccessTokenStatus accessTokenStatus = AccessTokenStatus.created;
    sql = "INSERT INTO " + ApiAccessTokenTable.table.getTableName() + " " + ApiAccessTokenTable.table.getSQLColumnList() + " VALUES " + ApiAccessTokenTable.table.getSQLValueList(key, token, apiClientKey, user, creationDate, expirationDate, accessTokenStatus);
    DbDriver.updateCleanSQL(con, sql);
    return new ApiAccessToken(key, token, apiClientKey, user, creationDate, expirationDate, accessTokenStatus);
}
Also used : KeyValue(org.vcell.util.document.KeyValue) AccessTokenStatus(cbit.vcell.modeldb.ApiAccessToken.AccessTokenStatus) UUID(java.util.UUID) Date(java.util.Date)

Example 2 with AccessTokenStatus

use of cbit.vcell.modeldb.ApiAccessToken.AccessTokenStatus in project vcell by virtualcell.

the class ApiAccessTokenTable method getApiAccessToken.

/**
 * This method was created in VisualAge.
 * @return Model
 * @param rset ResultSet
 * @param log SessionLog
 */
public ApiAccessToken getApiAccessToken(ResultSet rset) throws SQLException, DataAccessException {
    KeyValue key = new KeyValue(rset.getBigDecimal(id.toString()));
    String token = rset.getString(accesstoken.toString());
    KeyValue clientKey = new KeyValue(rset.getBigDecimal(clientRef.toString()));
    KeyValue userKey = new KeyValue(rset.getBigDecimal(userref.toString()));
    String userid = rset.getString(UserTable.table.userid.toString());
    User user = new User(userid, userKey);
    java.util.Date creation = VersionTable.getDate(rset, creationDate.toString());
    if (creation == null) {
        throw new DataAccessException("could not parse creation date");
    }
    java.util.Date expiration = VersionTable.getDate(rset, expireDate.toString());
    if (expiration == null) {
        throw new DataAccessException("could not parse expiration date");
    }
    String accessTokenDatabaseString = rset.getString(status.toString());
    // default value if null
    AccessTokenStatus accessTokenStatus = AccessTokenStatus.created;
    if (accessTokenDatabaseString != null) {
        accessTokenStatus = AccessTokenStatus.fromDatabaseString(accessTokenDatabaseString);
    }
    ApiAccessToken apiAccessToken = new ApiAccessToken(key, token, clientKey, user, creation, expiration, accessTokenStatus);
    return apiAccessToken;
}
Also used : KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) AccessTokenStatus(cbit.vcell.modeldb.ApiAccessToken.AccessTokenStatus) Date(java.util.Date) DataAccessException(org.vcell.util.DataAccessException)

Aggregations

AccessTokenStatus (cbit.vcell.modeldb.ApiAccessToken.AccessTokenStatus)2 Date (java.util.Date)2 KeyValue (org.vcell.util.document.KeyValue)2 UUID (java.util.UUID)1 DataAccessException (org.vcell.util.DataAccessException)1 User (org.vcell.util.document.User)1