Search in sources :

Example 6 with MaterializedJWT

use of io.hops.hopsworks.persistence.entity.airflow.MaterializedJWT in project hopsworks by logicalclocks.

the class JupyterJWTManager method cleanJWT.

@Lock(LockType.WRITE)
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public void cleanJWT(String cid, Integer port) {
    Optional<JupyterJWT> optional = Optional.ofNullable(pidAndPortToJWT.get(new CidAndPort(cid, port)));
    if (!optional.isPresent()) {
        LOG.log(WARNING, "JupyterJWT not found for cid " + cid + " and port " + port);
        return;
    }
    JupyterJWT element = optional.get();
    try {
        MaterializedJWTID materializedJWTID = new MaterializedJWTID(element.project.getId(), element.user.getUid(), MaterializedJWTID.USAGE.JUPYTER);
        MaterializedJWT material = materializedJWTFacade.findById(materializedJWTID);
        jwtTokenWriter.deleteToken(element);
        if (material != null) {
            materializedJWTFacade.delete(materializedJWTID);
        }
        removeToken(element.pidAndPort);
        jwtController.invalidate(element.token);
    } catch (Exception ex) {
        // Catch everything and do not fail. If we failed to determine the status of Jupyter, we renew the token
        // to be safe
        LOG.log(Level.FINE, "Could not determine if Jupyter JWT for " + element + " is still valid. Renewing it...");
    }
}
Also used : MaterializedJWTID(io.hops.hopsworks.persistence.entity.airflow.MaterializedJWTID) MaterializedJWT(io.hops.hopsworks.persistence.entity.airflow.MaterializedJWT) GeneralSecurityException(java.security.GeneralSecurityException) JWTDecodeException(com.auth0.jwt.exceptions.JWTDecodeException) IOException(java.io.IOException) ServiceException(io.hops.hopsworks.exceptions.ServiceException) JWTException(io.hops.hopsworks.jwt.exception.JWTException) InvalidationException(io.hops.hopsworks.jwt.exception.InvalidationException) TransactionAttribute(javax.ejb.TransactionAttribute) Lock(javax.ejb.Lock)

Aggregations

InvalidationException (io.hops.hopsworks.jwt.exception.InvalidationException)6 JWTException (io.hops.hopsworks.jwt.exception.JWTException)6 MaterializedJWT (io.hops.hopsworks.persistence.entity.airflow.MaterializedJWT)6 IOException (java.io.IOException)6 JWTDecodeException (com.auth0.jwt.exceptions.JWTDecodeException)4 MaterializedJWTID (io.hops.hopsworks.persistence.entity.airflow.MaterializedJWTID)4 GeneralSecurityException (java.security.GeneralSecurityException)4 LocalDateTime (java.time.LocalDateTime)4 HashMap (java.util.HashMap)4 Lock (javax.ejb.Lock)3 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)2 AirflowException (io.hops.hopsworks.exceptions.AirflowException)2 ServiceException (io.hops.hopsworks.exceptions.ServiceException)2 Project (io.hops.hopsworks.persistence.entity.project.Project)2 Users (io.hops.hopsworks.persistence.entity.user.Users)2 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 AccessTimeout (javax.ejb.AccessTimeout)2 AirflowDag (io.hops.hopsworks.common.dao.airflow.AirflowDag)1