-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from HiWay-Media/refactor
Refactor
- Loading branch information
Showing
10 changed files
with
259 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -241,4 +241,4 @@ eval "set -- $( | |
tr '\n' ' ' | ||
)" '"$@"' | ||
|
||
exec "$JAVACMD" "$@" | ||
exec "$JAVACMD" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,4 +89,4 @@ exit /b %EXIT_CODE% | |
:mainEnd | ||
if "%OS%"=="Windows_NT" endlocal | ||
|
||
:omega | ||
:omega |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/main/java/media/hiway/provider/DruidIdentityProviderEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package media.hiway.provider; | ||
|
||
import jakarta.ws.rs.FormParam; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.core.Response; | ||
import org.jboss.logging.Logger; | ||
import org.keycloak.OAuth2Constants; | ||
import org.keycloak.broker.provider.IdentityProvider; | ||
import org.keycloak.events.Errors; | ||
import org.keycloak.events.EventBuilder; | ||
import org.keycloak.events.EventType; | ||
import org.keycloak.models.KeycloakSession; | ||
import org.keycloak.models.RealmModel; | ||
import org.keycloak.services.ErrorPage; | ||
import org.keycloak.services.messages.Messages; | ||
|
||
import static media.hiway.provider.DruidIdentityProvider.OAUTH2_PARAMETER_CODE; | ||
|
||
public class DruidIdentityProviderEndpoint { | ||
|
||
protected static final Logger logger = Logger.getLogger(DruidIdentityProviderEndpoint.class); | ||
|
||
private static final String OAUTH2_PARAMETER_STATE = "state"; | ||
private static final String OAUTH2_PARAMETER_USER = "user"; | ||
private static final String ACCESS_DENIED = "access_denied"; | ||
private static final String USER_CANCELLED_AUTHORIZE = "user_cancelled_authorize"; | ||
|
||
private final DruidIdentityProvider druidIdentityProvider; | ||
private final RealmModel realm; | ||
private final IdentityProvider.AuthenticationCallback callback; | ||
private final EventBuilder event; | ||
|
||
protected KeycloakSession session; | ||
|
||
|
||
public DruidIdentityProviderEndpoint(DruidIdentityProvider druidIdentityProvider, RealmModel realm, IdentityProvider.AuthenticationCallback callback, EventBuilder event, KeycloakSession session) { | ||
this.druidIdentityProvider = druidIdentityProvider; | ||
this.realm = realm; | ||
this.callback = callback; | ||
this.event = event; | ||
this.session = session; | ||
} | ||
|
||
@POST | ||
public Response authResponse(@FormParam(OAUTH2_PARAMETER_STATE) String state, @FormParam(OAUTH2_PARAMETER_CODE) String authorizationCode, @FormParam(OAUTH2_PARAMETER_USER) String user, @FormParam(OAuth2Constants.ERROR) String error) { | ||
if (state == null) { | ||
return errorIdentityProviderLogin(Messages.IDENTITY_PROVIDER_MISSING_STATE_ERROR); | ||
} | ||
// TODO | ||
logger.debugf("State is %s", state); | ||
return errorIdentityProviderLogin(Messages.IDENTITY_PROVIDER_UNEXPECTED_ERROR); | ||
} | ||
|
||
private Response errorIdentityProviderLogin(String message) { | ||
return errorIdentityProviderLogin(message, Response.Status.BAD_GATEWAY); | ||
} | ||
|
||
private Response errorIdentityProviderLogin(String message, Response.Status status) { | ||
sendErrorEvent(); | ||
return ErrorPage.error(session, null, status, message); | ||
} | ||
|
||
private void sendErrorEvent() { | ||
event.event(EventType.IDENTITY_PROVIDER_LOGIN); | ||
event.detail("idp", druidIdentityProvider.getConfig().getProviderId()); | ||
event.error(Errors.IDENTITY_PROVIDER_LOGIN_FAILURE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/media/hiway/provider/DruidUserRepresentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package media.hiway.provider; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
|
||
public class DruidUserRepresentation { | ||
private String firstName; | ||
private String lastName; | ||
private JsonNode profile; | ||
|
||
public String getFirstName() { | ||
return firstName; | ||
} | ||
|
||
public void setFirstName(String firstName) { | ||
this.firstName = firstName; | ||
} | ||
|
||
public String getLastName() { | ||
return lastName; | ||
} | ||
|
||
public void setLastName(String lastName) { | ||
this.lastName = lastName; | ||
} | ||
|
||
public JsonNode getProfile() { | ||
return profile; | ||
} | ||
|
||
public void setProfile(JsonNode profile) { | ||
this.profile = profile; | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/media/hiway/provider/DruidUserSessionNoteMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package media.hiway.provider; | ||
|
||
import org.keycloak.broker.oidc.mappers.ClaimToUserSessionNoteMapper; | ||
|
||
public class DruidUserSessionNoteMapper extends ClaimToUserSessionNoteMapper { | ||
private static final String[] cp = new String[] {DruidIdentityProviderFactory.PROVIDER_ID}; | ||
|
||
@Override | ||
public String[] getCompatibleProviders() { | ||
return cp; | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return "apple-claim-user-session-note-mapper"; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/media/hiway/provider/TokenExchangeParms.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package media.hiway.provider; | ||
|
||
import jakarta.ws.rs.core.MultivaluedMap; | ||
import org.keycloak.OAuth2Constants; | ||
|
||
public class TokenExchangeParms { | ||
private String appIdentifier; | ||
private String subjectToken; | ||
private String subjectTokenType; | ||
private String userJson; | ||
|
||
public void TokenExchangeParams(MultivaluedMap<String, String> params) { | ||
this.subjectToken = params.getFirst(OAuth2Constants.SUBJECT_TOKEN); | ||
this.subjectTokenType = params.getFirst(OAuth2Constants.SUBJECT_TOKEN_TYPE); | ||
this.userJson = params.getFirst("user_profile"); | ||
this.appIdentifier = params.getFirst("app_identifier"); | ||
|
||
this.normalizeAppIdentifier(); | ||
this.setTypeDefaultIfNull(); | ||
this.normalizeUserJson(); | ||
} | ||
|
||
private void normalizeAppIdentifier() { | ||
if (this.appIdentifier != null && this.appIdentifier.isBlank()) { | ||
this.appIdentifier = null; | ||
} | ||
} | ||
|
||
private void setTypeDefaultIfNull() { | ||
if (this.subjectTokenType == null || this.subjectTokenType.isBlank()) { | ||
this.subjectTokenType = DruidIdentityProvider.DRUID_AUTHZ_CODE; | ||
} | ||
} | ||
|
||
private void normalizeUserJson() { | ||
if (this.userJson != null && (this.userJson.isBlank() || this.userJson.equals("null"))) { | ||
this.userJson = null; | ||
} | ||
} | ||
|
||
public String getAppIdentifier() { | ||
return this.appIdentifier; | ||
} | ||
|
||
public String getSubjectToken() { | ||
return this.subjectToken; | ||
} | ||
|
||
public String getSubjectTokenType() { | ||
return this.subjectTokenType; | ||
} | ||
|
||
public String getUserJson() { | ||
return this.userJson; | ||
} | ||
} |