| | |
| | | import java.security.Key; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
| | | import org.springframework.security.core.Authentication; |
| | | import org.springframework.security.core.GrantedAuthority; |
| | |
| | | import org.springframework.security.core.userdetails.User; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import com.pollex.pam.business.config.AppProperties; |
| | | import com.pollex.pam.business.domain.TokenBlackList; |
| | | import com.pollex.pam.business.repository.TokenBlackListRepository; |
| | | |
| | | import tech.jhipster.config.JHipsterProperties; |
| | | |
| | | @Component |
| | |
| | | private final Logger log = LoggerFactory.getLogger(TokenProvider.class); |
| | | |
| | | private static final String AUTHORITIES_KEY = "auth"; |
| | | private static final String AUTHORITIES_DETAILS = "details"; |
| | | |
| | | private final Key key; |
| | | |
| | |
| | | private final long tokenValidityInMilliseconds; |
| | | |
| | | private final long tokenValidityInMillisecondsForRememberMe; |
| | | |
| | | @Autowired |
| | | TokenBlackListRepository tokenBlackListRepository; |
| | | |
| | | @Autowired |
| | | AppProperties applicationProperties; |
| | | |
| | | public TokenProvider(JHipsterProperties jHipsterProperties) { |
| | | byte[] keyBytes; |
| | |
| | | .builder() |
| | | .setSubject(authentication.getName()) |
| | | .claim(AUTHORITIES_KEY, authorities) |
| | | .claim(AUTHORITIES_DETAILS, authentication.getDetails()) |
| | | .signWith(key, SignatureAlgorithm.HS512) |
| | | .setExpiration(validity) |
| | | .compact(); |
| | |
| | | .filter(auth -> !auth.trim().isEmpty()) |
| | | .map(SimpleGrantedAuthority::new) |
| | | .collect(Collectors.toList()); |
| | | User principal = new User(claims.getSubject(), applicationProperties.getDefaultPaxxword(), authorities); |
| | | UsernamePasswordAuthenticationToken authInfo = new UsernamePasswordAuthenticationToken(principal, token, authorities); |
| | | authInfo.setDetails(claims.get(AUTHORITIES_DETAILS)); |
| | | |
| | | User principal = new User(claims.getSubject(), "", authorities); |
| | | |
| | | return new UsernamePasswordAuthenticationToken(principal, token, authorities); |
| | | return authInfo; |
| | | } |
| | | |
| | | public boolean validateToken(String authToken) { |
| | |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | public boolean isBlackListToken(String jwt) { |
| | | Optional<TokenBlackList> tokenBlack = tokenBlackListRepository.findById(jwt); |
| | | return tokenBlack.isPresent(); |
| | | } |
| | | } |