Search in sources :

Example 91 with User

use of com.auth0.flickr2.domain.User in project engine by Lumeer.

the class UserAuth0Utils method renameUser.

public void renameUser(final String newUserName) throws Auth0Exception {
    if (!initialized) {
        init();
    }
    final String authId = authenticatedUser.getAuthUserInfo().user.getAuthIds().iterator().next();
    refreshManagementApiToken();
    final ManagementAPI mApi = new ManagementAPI(domain, managementApiToken);
    final User user = new User();
    user.setName(newUserName);
    mApi.users().update(authId, user).execute();
}
Also used : ManagementAPI(com.auth0.client.mgmt.ManagementAPI) User(com.auth0.json.mgmt.users.User)

Example 92 with User

use of com.auth0.flickr2.domain.User in project otus_java_basic by petrelevich.

the class Main method main.

public static void main(String[] args) {
    AtomicBoolean executionFlag = new AtomicBoolean(true);
    ConsoleIOService ioService = new ConsoleIOService();
    UserService userService = new UserService();
    EquationEvaluationResultHistoryHolder historyHolder = new EquationEvaluationResultHistoryHolder();
    User user = userService.askUserName(ioService);
    while (executionFlag.get()) {
        String commandOrEquation = showPromptAndReadCommand(ioService);
        if (!handleExitCommand(ioService, commandOrEquation, user.getFullName(), executionFlag)) {
            if (!handleHistoryCommand(ioService, commandOrEquation, historyHolder)) {
                handleEquationCommand(ioService, commandOrEquation, historyHolder);
            }
        }
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) User(ru.otus.solution3_srp.step02.domain.User) EquationEvaluationResultHistoryHolder(ru.otus.solution3_srp.step03.services.EquationEvaluationResultHistoryHolder) UserService(ru.otus.solution3_srp.step02.services.UserService) ConsoleIOService(ru.otus.solution3_srp.step02.services.ConsoleIOService)

Example 93 with User

use of com.auth0.flickr2.domain.User in project hopsworks by logicalclocks.

the class DownloadService method downloadFromHDFS.

@GET
@javax.ws.rs.Path("with_token/{path: .+}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@JWTNotRequired
@ApiOperation(value = "Download file.", response = StreamingOutput.class)
public Response downloadFromHDFS(@PathParam("path") String path, @QueryParam("token") String token, @QueryParam("type") DatasetType datasetType, @Context SecurityContext sc) throws DatasetException, SigningKeyNotFoundException, VerificationException, ProjectException {
    if (!settings.isDownloadAllowed()) {
        throw new DatasetException(RESTCodes.DatasetErrorCode.DOWNLOAD_NOT_ALLOWED, Level.FINEST);
    }
    Project project = this.getProject();
    DatasetPath datasetPath = datasetHelper.getDatasetPathIfFileExist(project, path, datasetType);
    String fullPath = datasetPath.getFullPath().toString();
    DecodedJWT djwt = jWTHelper.verifyOneTimeToken(token, fullPath);
    Users user = userFacade.findByUsername(djwt.getSubject());
    Pair<Path, StreamingOutput> pathStreamPair = downloadFromHDFS(project, datasetPath, user);
    Response.ResponseBuilder response = Response.ok(pathStreamPair.getValue1());
    response.header("Content-disposition", "attachment; filename=\"" + pathStreamPair.getValue0().getName() + "\"");
    return response.build();
}
Also used : Path(org.apache.hadoop.fs.Path) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath) Response(javax.ws.rs.core.Response) Project(io.hops.hopsworks.persistence.entity.project.Project) StreamingOutput(javax.ws.rs.core.StreamingOutput) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath) Users(io.hops.hopsworks.persistence.entity.user.Users) DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT) DatasetException(io.hops.hopsworks.exceptions.DatasetException) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) JWTNotRequired(io.hops.hopsworks.api.filter.JWTNotRequired)

Example 94 with User

use of com.auth0.flickr2.domain.User in project hopsworks by logicalclocks.

the class AirflowManager method monitorSecurityMaterial.

/**
 * Timer bean to periodically (JWT expiration lee way / 2) (a) clean stale JWT and X.509 material for Airflow
 * and (b) renew used JWTs.
 *
 * a. Iterate all the material in memory and clean those that don't have any entry in the database, project has been
 * deleted or those that project exist but user does not own any non-paused DAG in Airflow.
 *
 * b. For a valid JWT, renew it if the time has come (after expiration time and before expiration + expLeeWay)
 *
 * @param timer
 */
@Lock(LockType.WRITE)
@AccessTimeout(value = 500)
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
@Timeout
public void monitorSecurityMaterial(Timer timer) {
    try {
        LocalDateTime now = DateUtils.getNow();
        // Clean unused token files and X.509 certificates
        cleanStaleSecurityMaterial();
        // Renew them
        Set<AirflowJWT> newTokens2Add = new HashSet<>();
        Iterator<AirflowJWT> airflowJWTIt = airflowJWTs.iterator();
        while (airflowJWTIt.hasNext()) {
            AirflowJWT airflowJWT = airflowJWTIt.next();
            // If first does not need to be renewed, neither do the rest
            if (airflowJWT.maybeRenew(now)) {
                try {
                    LocalDateTime expirationDateTime = now.plus(settings.getJWTLifetimeMs(), ChronoUnit.MILLIS);
                    Date expirationDate = DateUtils.localDateTime2Date(expirationDateTime);
                    String token = jwtController.renewToken(airflowJWT.token, expirationDate, DateUtils.localDateTime2Date(DateUtils.getNow()), true, new HashMap<>(3));
                    AirflowJWT renewedJWT = new AirflowJWT(airflowJWT.username, airflowJWT.projectId, airflowJWT.projectName, expirationDateTime, airflowJWT.uid);
                    renewedJWT.tokenFile = airflowJWT.tokenFile;
                    renewedJWT.token = token;
                    airflowJWTIt.remove();
                    writeTokenToFile(renewedJWT);
                    newTokens2Add.add(renewedJWT);
                } catch (JWTException ex) {
                    LOG.log(Level.WARNING, "Could not renew Airflow JWT for " + airflowJWT, ex);
                } catch (IOException ex) {
                    LOG.log(Level.WARNING, "Could not write renewed Airflow JWT for " + airflowJWT, ex);
                    try {
                        jwtController.invalidate(airflowJWT.token);
                    } catch (InvalidationException iex) {
                        LOG.log(Level.FINE, "Could not invalidate Airflow JWT. SKipping...");
                    }
                } catch (Exception ex) {
                    LOG.log(Level.SEVERE, "Generic error while renewing Airflow JWTs", ex);
                }
            } else {
                break;
            }
        }
        airflowJWTs.addAll(newTokens2Add);
    } catch (Exception e) {
        LOG.log(Level.SEVERE, "Got an exception while renewing/invalidating airflow jwt token", e);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) JWTException(io.hops.hopsworks.jwt.exception.JWTException) IOException(java.io.IOException) InvalidationException(io.hops.hopsworks.jwt.exception.InvalidationException) Date(java.util.Date) GeneralSecurityException(java.security.GeneralSecurityException) JWTDecodeException(com.auth0.jwt.exceptions.JWTDecodeException) SQLException(java.sql.SQLException) AirflowException(io.hops.hopsworks.exceptions.AirflowException) IOException(java.io.IOException) JWTException(io.hops.hopsworks.jwt.exception.JWTException) InvalidationException(io.hops.hopsworks.jwt.exception.InvalidationException) HashSet(java.util.HashSet) AccessTimeout(javax.ejb.AccessTimeout) TransactionAttribute(javax.ejb.TransactionAttribute) Timeout(javax.ejb.Timeout) AccessTimeout(javax.ejb.AccessTimeout) Lock(javax.ejb.Lock)

Example 95 with User

use of com.auth0.flickr2.domain.User in project hopsworks by logicalclocks.

the class JWTHelper method getUserPrincipal.

/**
 * Get the user from the request header Authorization field.
 *
 * @param req
 * @return
 */
public Users getUserPrincipal(HttpServletRequest req) {
    String jwt = getAuthToken(req);
    DecodedJWT djwt = jwtController.decodeToken(jwt);
    return djwt == null ? null : userFacade.findByUsername(djwt.getSubject());
}
Also used : DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT)

Aggregations

Algorithm (com.auth0.jwt.algorithms.Algorithm)64 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)60 IOException (java.io.IOException)51 Test (org.junit.Test)46 JWT (com.auth0.jwt.JWT)42 Instant (java.time.Instant)39 java.util (java.util)37 Duration (java.time.Duration)36 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)35 Maps (io.gravitee.common.util.Maps)34 DEFAULT_JWT_ISSUER (io.gravitee.rest.api.service.common.JWTHelper.DefaultValues.DEFAULT_JWT_ISSUER)34 User (io.gravitee.repository.management.model.User)33 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)32 UserRepository (io.gravitee.repository.management.api.UserRepository)30 io.gravitee.rest.api.model (io.gravitee.rest.api.model)30 JWTVerifier (com.auth0.jwt.JWTVerifier)28 MetadataPage (io.gravitee.common.data.domain.MetadataPage)28 MembershipRepository (io.gravitee.repository.management.api.MembershipRepository)28 Membership (io.gravitee.repository.management.model.Membership)28 UserStatus (io.gravitee.repository.management.model.UserStatus)28