mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-02-01 04:09:08 +01:00
Merge branch 'develop' into feature/trace_api
This commit is contained in:
@@ -46,6 +46,8 @@ import static com.google.common.base.Preconditions.checkArgument;
|
||||
@Extension
|
||||
public class ApiKeyRealm extends AuthenticatingRealm {
|
||||
|
||||
public static final String NAME = "ApiTokenRealm";
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ApiKeyRealm.class);
|
||||
|
||||
private final ApiKeyService apiKeyService;
|
||||
@@ -55,7 +57,7 @@ public class ApiKeyRealm extends AuthenticatingRealm {
|
||||
@Inject
|
||||
public ApiKeyRealm(ApiKeyService apiKeyService, DAORealmHelperFactory helperFactory, RepositoryRoleManager repositoryRoleManager) {
|
||||
this.apiKeyService = apiKeyService;
|
||||
this.helper = helperFactory.create("ApiTokenRealm");
|
||||
this.helper = helperFactory.create(NAME);
|
||||
this.repositoryRoleManager = repositoryRoleManager;
|
||||
setAuthenticationTokenClass(BearerToken.class);
|
||||
setCredentialsMatcher(new AllowAllCredentialsMatcher());
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.security;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
@@ -31,6 +31,7 @@ import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authz.AuthorizationException;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -154,6 +155,9 @@ public final class JwtAccessTokenBuilder implements AccessTokenBuilder {
|
||||
|
||||
@Override
|
||||
public JwtAccessToken build() {
|
||||
if (SecurityUtils.getSubject().getPrincipals().getRealmNames().contains(ApiKeyRealm.NAME)) {
|
||||
throw new AuthorizationException("Cannot create access token for api keys");
|
||||
}
|
||||
String id = keyGenerator.createKey();
|
||||
|
||||
String sub = getSubject();
|
||||
|
||||
Reference in New Issue
Block a user