Search in sources :

Example 46 with User

use of com.auth0.flickr2.domain.User in project javasrc by IanDarwin.

the class UserDBJDBC method setLoginDate.

/**
 * Update the Last Login Date field.
 */
public synchronized void setLoginDate(String nick, java.util.Date date) throws SQLException {
    // Find the user object
    User u = getUser(nick);
    // Change it in DB first; if this fails, the date in
    // the in-memory copy won't be changed either.
    // Have to convert from java.util.Date to java.sql.Date here.
    // Would be more efficient to use java.sql.Date everywhere.
    setLastLoginStmt.setDate(1, new java.sql.Date(date.getTime()));
    setLastLoginStmt.setString(2, nick);
    setLastLoginStmt.executeUpdate();
    // Change it in-memory
    u.setLastLoginDate(date);
}
Also used : User(domain.User)

Example 47 with User

use of com.auth0.flickr2.domain.User in project IginX by thulab.

the class UsersClientImpl method findUsers.

@Override
public List<User> findUsers() throws IginXException {
    GetUserReq req = new GetUserReq(sessionId);
    GetUserResp resp;
    synchronized (iginXClient) {
        iginXClient.checkIsClosed();
        try {
            resp = client.getUser(req);
            RpcUtils.verifySuccess(resp.status);
        } catch (TException | ExecutionException e) {
            throw new IginXException("find users failure: ", e);
        }
    }
    if (resp.usernames == null || resp.userTypes == null || resp.auths == null) {
        return Collections.emptyList();
    }
    List<User> users = new ArrayList<>();
    for (int i = 0; i < resp.usernames.size(); i++) {
        String username = resp.usernames.get(i);
        UserType userType = resp.userTypes.get(i);
        Set<AuthType> auths = resp.auths.get(i);
        users.add(new User(username, userType, auths));
    }
    return users;
}
Also used : TException(org.apache.thrift.TException) IginXException(cn.edu.tsinghua.iginx.session_v2.exception.IginXException) User(cn.edu.tsinghua.iginx.session_v2.domain.User) GetUserReq(cn.edu.tsinghua.iginx.thrift.GetUserReq) ArrayList(java.util.ArrayList) GetUserResp(cn.edu.tsinghua.iginx.thrift.GetUserResp) AuthType(cn.edu.tsinghua.iginx.thrift.AuthType) ExecutionException(cn.edu.tsinghua.iginx.exceptions.ExecutionException) UserType(cn.edu.tsinghua.iginx.thrift.UserType)

Example 48 with User

use of com.auth0.flickr2.domain.User in project rhizome by geekbeast.

the class AuthenticationTest method testLoadUserInfo.

@Test
public void testLoadUserInfo() throws Auth0Exception {
    String accessToken = accessTokens();
    UserInfo userInfoRequest = client.userInfo(accessToken).execute();
    Map<String, Object> d2 = userInfoRequest.getValues();
    Assert.assertTrue(d2.containsKey("email"));
    Assert.assertTrue(d2.containsKey("email_verified"));
    Assert.assertTrue(d2.containsKey("nickname"));
    Assert.assertTrue(d2.containsKey("picture"));
    Assert.assertTrue(d2.containsKey("name"));
    Assert.assertTrue(d2.containsKey("sub"));
    Assert.assertTrue(d2.containsKey("updated_at"));
    logger.info("User Info: {}", d2);
}
Also used : UserInfo(com.auth0.json.auth.UserInfo) Test(org.junit.Test)

Example 49 with User

use of com.auth0.flickr2.domain.User in project bank-of-anthos by GoogleCloudPlatform.

the class LedgerMonolithController method getTransactions.

// BEGIN TRANSACTION HISTORY
/**
 * Return a list of transactions for the specified account.
 *
 * The currently authenticated user must be allowed to access the account.
 * @param bearerToken  HTTP request 'Authorization' header
 * @param accountId    the account to get transactions for.
 * @return             a list of transactions for this account.
 */
@GetMapping("/transactions/{accountId}")
public ResponseEntity<?> getTransactions(@RequestHeader("Authorization") String bearerToken, @PathVariable String accountId) {
    if (bearerToken != null && bearerToken.startsWith("Bearer ")) {
        bearerToken = bearerToken.split("Bearer ")[1];
    }
    try {
        DecodedJWT jwt = verifier.verify(bearerToken);
        // Check that the authenticated user can access this account.
        if (!accountId.equals(jwt.getClaim("acct").asString())) {
            LOGGER.error("Failed to retrieve account transactions: " + "not authorized");
            return new ResponseEntity<String>("not authorized", HttpStatus.UNAUTHORIZED);
        }
        // Load from cache
        AccountInfo info = ledgerReaderCache.get(accountId);
        Deque<Transaction> historyList = info.getTransactions();
        // Set artificial extra latency.
        LOGGER.debug("Setting artificial latency");
        if (extraLatencyMillis != null) {
            try {
                Thread.sleep(extraLatencyMillis);
            } catch (InterruptedException e) {
            // Fake latency interrupted. Continue.
            }
        }
        return new ResponseEntity<Collection<Transaction>>(historyList, HttpStatus.OK);
    } catch (JWTVerificationException e) {
        LOGGER.error("Failed to retrieve account transactions: " + "not authorized");
        return new ResponseEntity<String>("not authorized", HttpStatus.UNAUTHORIZED);
    } catch (ExecutionException | UncheckedExecutionException e) {
        LOGGER.error("Cache error");
        return new ResponseEntity<String>("cache error", HttpStatus.INTERNAL_SERVER_ERROR);
    }
}
Also used : JWTVerificationException(com.auth0.jwt.exceptions.JWTVerificationException) ResponseEntity(org.springframework.http.ResponseEntity) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 50 with User

use of com.auth0.flickr2.domain.User in project bank-of-anthos by GoogleCloudPlatform.

the class BalanceReaderController method getBalance.

/**
 * Return the balance for the specified account.
 *
 * The currently authenticated user must be allowed to access the account.
 *
 * @param bearerToken  HTTP request 'Authorization' header
 * @param accountId    the account to get the balance for
 * @return             the balance of the account
 */
@GetMapping("/balances/{accountId}")
public ResponseEntity<?> getBalance(@RequestHeader("Authorization") String bearerToken, @PathVariable String accountId) {
    if (bearerToken != null && bearerToken.startsWith("Bearer ")) {
        bearerToken = bearerToken.split("Bearer ")[1];
    }
    try {
        DecodedJWT jwt = verifier.verify(bearerToken);
        // Check that the authenticated user can access this account.
        if (!accountId.equals(jwt.getClaim("acct").asString())) {
            LOGGER.error("Failed to retrieve account balance: " + "not authorized");
            return new ResponseEntity<String>("not authorized", HttpStatus.UNAUTHORIZED);
        }
        // Load from cache
        Long balance = cache.get(accountId);
        return new ResponseEntity<Long>(balance, HttpStatus.OK);
    } catch (JWTVerificationException e) {
        LOGGER.error("Failed to retrieve account balance: not authorized");
        return new ResponseEntity<String>("not authorized", HttpStatus.UNAUTHORIZED);
    } catch (ExecutionException | UncheckedExecutionException e) {
        LOGGER.error("Cache error");
        return new ResponseEntity<String>("cache error", HttpStatus.INTERNAL_SERVER_ERROR);
    }
}
Also used : JWTVerificationException(com.auth0.jwt.exceptions.JWTVerificationException) ResponseEntity(org.springframework.http.ResponseEntity) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT) GetMapping(org.springframework.web.bind.annotation.GetMapping)

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