Ejemplo n.º 1
4
  public Authentication getAuthentication(String token) {
    Claims claims = Jwts.parser().setSigningKey(secretKey).parseClaimsJws(token).getBody();

    Collection<? extends GrantedAuthority> authorities =
        Arrays.stream(claims.get(AUTHORITIES_KEY).toString().split(","))
            .map(SimpleGrantedAuthority::new)
            .collect(Collectors.toList());

    User principal = new User(claims.getSubject(), "", authorities);

    return new UsernamePasswordAuthenticationToken(principal, "", authorities);
  }
  public com.dsmc.data.tables.pojos.AdminUser getAdminUserFromToken(String token) {
    try {
      Jwt<Header, Claims> jwt =
          Jwts.parser().setSigningKeyResolver(signingKeyResolver).parseClaimsJwt(token);

      Claims claims = jwt.getBody();
      Integer claimUserId = claims.get("userId", Integer.TYPE);
      Integer claimCompanyId = claims.get("companyId", Integer.TYPE);
      String claimUsername = claims.get("username", String.class);

      return new com.dsmc.data.tables.pojos.AdminUser(
          claimUserId, claimCompanyId, claimUsername, null, null, null, null);
    } catch (Exception e) {
      LOGGER.error("Token verification failed.", e);
    }
    return null;
  }
Ejemplo n.º 3
0
 public String getAudienceFromToken(String token) {
   String audience;
   try {
     final Claims claims = this.getClaimsFromToken(token);
     audience = (String) claims.get("audience");
   } catch (Exception e) {
     audience = null;
   }
   return audience;
 }
Ejemplo n.º 4
0
 public Date getCreatedDateFromToken(String token) {
   Date created;
   try {
     final Claims claims = this.getClaimsFromToken(token);
     created = new Date((Long) claims.get("created"));
   } catch (Exception e) {
     created = null;
   }
   return created;
 }
Ejemplo n.º 5
0
 public String getOriginFromToken(String token) {
   String origin;
   try {
     final Claims claims = this.getClaimsFromToken(token);
     origin = (String) claims.get("origin");
   } catch (Exception e) {
     origin = null;
   }
   return origin;
 }
Ejemplo n.º 6
0
 public String getAuthoritiesFromToken(String token) {
   String authorities;
   try {
     final Claims claims = this.getClaimsFromToken(token);
     authorities = (String) claims.get("authorities");
   } catch (Exception e) {
     authorities = null;
   }
   return authorities;
 }
Ejemplo n.º 7
0
  public ServiceResult execute(final JsonNode jsonRequest) {
    final Principal principal =
        (Principal) Http.Context.current().args.get(Principal.class.getName());
    final Project project = Json.fromJson(jsonRequest, Project.class);

    final Claims claims = principal.getClaims();
    final ProjectMember ownerMember = new ProjectMember();

    ownerMember.setUserId(new Integer((String) claims.get("id")));
    ownerMember.setForename((String) claims.get("forename"));
    ownerMember.setSurname((String) claims.get("surname"));
    ownerMember.setEmail((String) claims.get("email"));
    ownerMember.setRole(ProjectMember.Role.OWNER);

    project.setOwner(ownerMember);

    final Project savedProject = projectRepository.set(project);

    // TODO email project members

    return new ServiceResult(Json.toJson(savedProject));
  }