Search in sources :

Example 41 with User

use of com.auth0.flickr2.domain.User in project iesi by metadew.

the class JwtService method generateAuthenticationResponse.

public AuthenticationResponse generateAuthenticationResponse(Authentication authentication) {
    Algorithm algorithm = Algorithm.HMAC256(secret);
    LocalDateTime now = LocalDateTime.now(clock);
    LocalDateTime expiresAt = now.plus(accessTokenExpiryDate, ChronoUnit.SECONDS);
    String token = JWT.create().withIssuer(ISSUER).withSubject(authentication.getName()).withIssuedAt(Timestamp.valueOf(now)).withExpiresAt(Timestamp.valueOf(expiresAt)).withClaim("uuid", ((IesiUserDetails) authentication.getPrincipal()).getId().toString()).sign(algorithm);
    UserDto userDto = userService.get(((IesiUserDetails) authentication.getPrincipal()).getId()).orElseThrow(() -> new UsernameNotFoundException(String.format("Cannot find user %s (%s)", ((IesiUserDetails) authentication.getPrincipal()).getId().toString(), ((IesiUserDetails) authentication.getPrincipal()).getUsername())));
    return new AuthenticationResponse(token, ChronoUnit.SECONDS.between(now, expiresAt), userDto.getRoles());
}
Also used : LocalDateTime(java.time.LocalDateTime) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) UserDto(io.metadew.iesi.server.rest.user.UserDto) IesiUserDetails(io.metadew.iesi.server.rest.configuration.security.IesiUserDetails) Algorithm(com.auth0.jwt.algorithms.Algorithm) AuthenticationResponse(io.metadew.iesi.server.rest.user.AuthenticationResponse)

Example 42 with User

use of com.auth0.flickr2.domain.User in project code by lastwhispers.

the class UserController method login.

/**
 * http://localhost:8080/user/login?username=admin&password=123456
 *
 * @param username
 * @param password
 * @return
 */
@GetMapping("/login")
public String login(@RequestParam String username, @RequestParam String password) {
    Algorithm algorithm = Algorithm.HMAC256(JWT_KEY);
    String token = JWT.create().withClaim(CURRENT_USER, username).withClaim(UID, 1).withExpiresAt(new Date(System.currentTimeMillis() + 3600000)).sign(algorithm);
    return token;
}
Also used : Algorithm(com.auth0.jwt.algorithms.Algorithm) Date(java.util.Date)

Example 43 with User

use of com.auth0.flickr2.domain.User in project TCSS450-Mobile-App by TCSS450-Team7-MobileApp.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mMainActivity = this;
    MainActivityArgs args = MainActivityArgs.fromBundle(getIntent().getExtras());
    // Import com.auth0.android.jwt.JWT
    JWT jwt = new JWT(args.getJwt());
    // created on the web service.
    if (!jwt.isExpired(0)) {
        jwt = new JWT(args.getJwt());
    }
    new ViewModelProvider(this, new UserInfoViewModel.UserInfoViewModelFactory(args.getEmail(), jwt.toString(), args.getFirst(), args.getLast(), args.getNick(), args.getId())).get(UserInfoViewModel.class);
    binding = ActivityMainBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());
    // Make sure the new statements go BELOW setContentView
    BottomNavigationView navView = findViewById(R.id.nav_view);
    // Passing each menu ID as a set of Ids because each
    // menu should be considered as top level destinations.
    mAppBarConfiguration = new AppBarConfiguration.Builder(R.id.navigation_message, R.id.navigation_home, R.id.navigation_weather).build();
    NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
    NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
    NavigationUI.setupWithNavController(navView, navController);
    mNewMessageModel = new ViewModelProvider(this).get(NewMessageCountViewModel.class);
    navController.addOnDestinationChangedListener((controller, destination, arguments) -> {
        if (destination.getId() == R.id.navigation_message) {
            // When the user navigates to the chats page, reset the new message count.
            // This will need some extra logic for your project as it should have
            // multiple chat rooms.
            mNewMessageModel.reset();
        }
    });
    mNewMessageModel.addMessageCountObserver(this, count -> {
        BadgeDrawable badge = binding.navView.getOrCreateBadge(R.id.navigation_message);
        badge.setMaxCharacterCount(2);
        if (count > 0) {
            // new messages! update and show the notification badge.
            badge.setNumber(count);
            badge.setVisible(true);
        } else {
            // user did some action to clear the new messages, remove the badge
            badge.clearNumber();
            badge.setVisible(false);
        }
    });
}
Also used : BadgeDrawable(com.google.android.material.badge.BadgeDrawable) NewMessageCountViewModel(edu.uw.tcss450.blynch99.tcss450mobileapp.model.NewMessageCountViewModel) JWT(com.auth0.android.jwt.JWT) BottomNavigationView(com.google.android.material.bottomnavigation.BottomNavigationView) NavController(androidx.navigation.NavController) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 44 with User

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

the class TextToDBM method main.

public static void main(String[] fn) throws IOException {
    BufferedReader is = new BufferedReader(new FileReader(TEXT_NAME));
    DBM db = new DBM(DBM_NAME);
    String line;
    while ((line = is.readLine()) != null) {
        if (line.startsWith("#")) {
            // comment
            continue;
        }
        StringTokenizer st = new StringTokenizer(line, ":");
        String nick = st.nextToken();
        String pass = st.nextToken();
        String full = st.nextToken();
        String email = st.nextToken();
        String city = st.nextToken();
        String prov = st.nextToken();
        String ctry = st.nextToken();
        User u = new User(nick, pass, full, email, city, prov, ctry);
        String privs = st.nextToken();
        if (privs.indexOf("A") != -1) {
            u.setAdminPrivileged(true);
        }
        db.store(nick, u);
    }
    db.close();
    is.close();
}
Also used : User(domain.User) DBM(dbm.DBM)

Example 45 with User

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

the class UserDBJDBC method deleteUser.

public void deleteUser(String nick) throws SQLException {
    // Find the user object
    User u = getUser(nick);
    if (u == null) {
        throw new SQLException("User " + nick + " not in in-memory DB");
    }
    deleteUserStmt.setString(1, nick);
    int n = deleteUserStmt.executeUpdate();
    if (n != 1) {
        /*CANTHAPPEN */
        throw new SQLException("ERROR: deleted " + n + " rows!!");
    }
    // IFF we deleted it from the DB, also remove from the in-memory list
    users.remove(u);
}
Also used : User(domain.User) SQLException(java.sql.SQLException)

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