Skip to content
Snippets Groups Projects
Verified Commit 1105142f authored by Dominik Frantisek Bucik's avatar Dominik Frantisek Bucik
Browse files

fix: :bug: Throw correct error when no auth_code found

- provide correct error instead of internal server error when no
authorization code has been found (probably already consumed or expired)
parent d2f80941
No related branches found
No related tags found
1 merge request!386fix: 🐛 Throw correct error when no auth_code found
Pipeline #412400 passed
......@@ -29,6 +29,7 @@ import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import java.util.Collection;
......@@ -67,7 +68,11 @@ public class JpaAuthorizationCodeRepository implements AuthorizationCodeReposito
AuthorizationCodeEntity.QUERY_BY_VALUE, AuthorizationCodeEntity.class
);
query.setParameter(AuthorizationCodeEntity.PARAM_CODE, code);
return query.getSingleResult();
try {
return query.getSingleResult();
} catch (NoResultException ex) {
return null;
}
}
/* (non-Javadoc)
......
......@@ -100,7 +100,7 @@ public class DefaultOAuth2AuthorizationCodeService implements AuthorizationCodeS
AuthorizationCodeEntity result = repository.getByCode(code);
if (result == null) {
throw new InvalidGrantException("JpaAuthorizationCodeRepository: no authorization code found for value " + code);
throw new InvalidGrantException("No authorization code found for value " + code);
}
OAuth2Authentication auth = result.getAuthenticationHolder().getAuthentication();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment