Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion core/src/main/java/org/keycloak/RSATokenVerifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ public static SkeletonKeyToken verifyToken(String tokenString, ResourceMetadata
{
PublicKey realmKey = metadata.getRealmKey();
String realm = metadata.getRealm();
String resource = metadata.getResourceName();
return verifyToken(tokenString, realmKey, realm);
}

public static SkeletonKeyToken verifyToken(String tokenString, PublicKey realmKey, String realm) throws VerificationException
{
JWSInput input = new JWSInput(tokenString);
boolean verified = false;
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class PublishedRealmRepresentation
@JsonProperty("grants")
protected String grantUrl;

@JsonProperty("identity-grants")
protected String identityGrantUrl;

@JsonIgnore
protected volatile transient PublicKey publicKey;

Expand Down Expand Up @@ -133,4 +136,14 @@ public void setGrantUrl(String grantUrl)
{
this.grantUrl = grantUrl;
}

public String getIdentityGrantUrl()
{
return identityGrantUrl;
}

public void setIdentityGrantUrl(String identityGrantUrl)
{
this.identityGrantUrl = identityGrantUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
Expand All @@ -16,6 +17,7 @@ public class RealmRepresentation
protected boolean enabled;
protected boolean sslNotRequired;
protected boolean cookieLoginAllowed;
protected Set<String> roles;
protected List<RequiredCredentialRepresentation> requiredCredentials;
protected List<UserRepresentation> users;
protected List<RoleMappingRepresentation> roleMappings;
Expand Down Expand Up @@ -168,4 +170,14 @@ public void setAccessCodeLifespan(long accessCodeLifespan)
{
this.accessCodeLifespan = accessCodeLifespan;
}

public Set<String> getRoles()
{
return roles;
}

public void setRoles(Set<String> roles)
{
this.roles = roles;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class RoleMappingRepresentation
protected String self; // link
protected String username;
protected Set<String> roles;
protected Set<String> surrogates;

public String getSelf()
{
Expand All @@ -41,24 +40,6 @@ public Set<String> getRoles()
return roles;
}

public Set<String> getSurrogates()
{
return surrogates;
}

public void setSurrogates(Set<String> surrogates)
{
this.surrogates = surrogates;
}

public RoleMappingRepresentation surrogate(String surrogate)
{
if (this.surrogates == null) this.surrogates = new HashSet<String>();
this.surrogates.add(surrogate);
return this;
}


public void setRoles(Set<String> roles)
{
this.roles = roles;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package org.keycloak.services.service;
package org.keycloak.services.managers;

import org.jboss.resteasy.logging.Logger;
import org.keycloak.RSATokenVerifier;
import org.keycloak.VerificationException;
import org.keycloak.representations.SkeletonKeyToken;
import org.keycloak.representations.idm.RequiredCredentialRepresentation;
import org.keycloak.services.model.RealmManager;
import org.keycloak.services.model.RealmModel;
import org.keycloak.services.model.RequiredCredentialModel;
import org.keycloak.services.models.RealmManager;
import org.keycloak.services.models.RealmModel;
import org.keycloak.services.models.RequiredCredentialModel;
import org.picketlink.idm.credential.Credentials;
import org.picketlink.idm.credential.Password;
import org.picketlink.idm.credential.TOTPCredentials;
import org.picketlink.idm.credential.UsernamePasswordCredentials;
import org.picketlink.idm.model.User;

import javax.ws.rs.NotAuthorizedException;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MultivaluedMap;
import java.util.HashSet;
import java.util.Set;
Expand All @@ -30,7 +35,45 @@ public AuthenticationManager(RealmManager adapter)
this.adapter = adapter;
}

public boolean authenticate(RealmModel realm, User user, MultivaluedMap<String, String> formData)
public User authenticateToken(RealmModel realm, HttpHeaders headers)
{
String tokenString = null;
String authHeader = headers.getHeaderString(HttpHeaders.AUTHORIZATION);
if (authHeader == null)
{
throw new NotAuthorizedException("Bearer");
}
else
{
String[] split = authHeader.trim().split("\\s+");
if (split == null || split.length != 2) throw new NotAuthorizedException("Bearer");

This comment was marked as spam.

This comment was marked as spam.

if (!split[0].equalsIgnoreCase("Bearer")) throw new NotAuthorizedException("Bearer");
tokenString = split[1];
}


try
{
SkeletonKeyToken token = RSATokenVerifier.verifyToken(tokenString, realm.getPublicKey(), realm.getId());

This comment was marked as spam.

This comment was marked as spam.

if (!token.isActive())
{
throw new NotAuthorizedException("token_expired");
}
User user = realm.getIdm().getUser(token.getPrincipal());
if (user == null || !user.isEnabled())
{
throw new NotAuthorizedException("invalid_user");
}
return user;
}
catch (VerificationException e)
{
logger.error("Failed to verify token", e);
throw new NotAuthorizedException("invalid_token");
}
}

public boolean authenticateForm(RealmModel realm, User user, MultivaluedMap<String, String> formData)
{
String username = user.getLoginName();
Set<String> types = new HashSet<String>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.keycloak.services.service;
package org.keycloak.services.managers;

import org.jboss.resteasy.jose.Base64Url;
import org.jboss.resteasy.jose.jws.JWSBuilder;
import org.jboss.resteasy.jwt.JsonSerialization;
import org.keycloak.representations.SkeletonKeyScope;
import org.keycloak.representations.SkeletonKeyToken;
import org.keycloak.services.model.RealmManager;
import org.keycloak.services.model.RealmModel;
import org.keycloak.services.model.ResourceModel;
import org.keycloak.services.models.RealmManager;
import org.keycloak.services.models.RealmModel;
import org.keycloak.services.models.ResourceModel;
import org.picketlink.idm.model.User;

import javax.ws.rs.ForbiddenException;
Expand Down
Loading