Skip to content

Commit

Permalink
Merge pull request #450 from okta/ak_okta_595550_include_i18n_error_m…
Browse files Browse the repository at this point in the history
…essages

Include i18n messages in AuthenticationResponse object
  • Loading branch information
arvindkrishnakumar-okta authored Jun 21, 2023
2 parents f4270b9 + e5cee2f commit 88a9e64
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.okta.commons.http.Response;
import com.okta.commons.lang.Assert;
import com.okta.commons.lang.Strings;
import com.okta.idx.sdk.api.exception.ProcessingException;
import com.okta.idx.sdk.api.model.AuthenticationStatus;
import com.okta.idx.sdk.api.model.CurrentAuthenticatorEnrollment;
Expand Down Expand Up @@ -309,7 +310,13 @@ private static void copyErrorMessages(IDXResponse idxResponse, AuthenticationRes
return;
}
Arrays.stream(idxResponse.getMessages().getValue())
.forEach(msg -> authenticationResponse.addError(msg.getMessage()));
.forEach(msg -> {
String message = msg.getMessage();
if (msg.getI18NMessage() != null && Strings.hasText(msg.getI18NMessage().getKey())) {
message += ", " + msg.getI18NMessage();
}
authenticationResponse.addError(message);
});
}

private void fillOutAuthenticators(AuthenticationResponse authenticationResponse) {
Expand Down
41 changes: 41 additions & 0 deletions api/src/main/java/com/okta/idx/sdk/api/model/I18NMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2023-Present, Okta, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.okta.idx.sdk.api.model;

import com.fasterxml.jackson.annotation.JsonAutoDetect;

import java.util.List;

@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
public class I18NMessage {

private String key;

private List<String> params;

public String getKey() {
return key;
}

public List<String> getParams() {
return params;
}

@Override
public String toString() {
return "key='" + key + '\'' + ", params=" + params;
}
}
13 changes: 13 additions & 0 deletions api/src/main/java/com/okta/idx/sdk/api/model/MessageValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,27 @@ public class MessageValue {

private String message;

@JsonAlias("i18n")
private I18NMessage i18NMessage;
@JsonAlias("class")
private String value;

public String getMessage() {
return message;
}

public I18NMessage getI18NMessage() {
return i18NMessage;
}

public String getValue() {
return value;
}

@Override
public String toString() {
return "message='" + message + '\'' +
", i18n=" + i18NMessage +
", value='" + value + '\'';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,8 @@ class IDXAuthenticationWrapperTest {
new AuthenticationOptions("[email protected]", "superSecret".toCharArray()), beginResponse.proceedContext
)
assertThat(authenticationResponse, notNullValue())
assertThat(authenticationResponse.getErrors(), hasItem("There is no account with the Username [email protected]."))
assertThat(authenticationResponse.getErrors(),
hasItem("There is no account with the Username [email protected]., key='idx.unknown.user', params=[]"))
assertThat(authenticationResponse.getAuthenticationStatus(),
is(AuthenticationStatus.UNKNOWN)
)
Expand Down Expand Up @@ -877,7 +878,8 @@ class IDXAuthenticationWrapperTest {
new AuthenticationOptions("[email protected]", "superSecret".toCharArray()), beginResponse.proceedContext
)
assertThat(authenticationResponse, notNullValue())
assertThat(authenticationResponse.getErrors(), hasItem("There is no account with the Username [email protected]."))
assertThat(authenticationResponse.getErrors(),
hasItem("There is no account with the Username [email protected]., key='idx.unknown.user', params=[]"))
assertThat(authenticationResponse.getAuthenticators(), nullValue())
}

Expand Down
5 changes: 3 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
<properties>
<jackson.version>2.15.2</jackson.version>
<snakeyaml.version>2.0</snakeyaml.version>
<okta.commons.version>1.3.1</okta.commons.version>
<okta.sdk.previousVersion>3.0.3</okta.sdk.previousVersion>
<okta.commons.version>1.3.4</okta.commons.version>
<okta.sdk.previousVersion>3.0.4</okta.sdk.previousVersion>
<org.apache.tomcat.embed.version>9.0.76</org.apache.tomcat.embed.version>
<org.jetbrains.kotlin.version>1.6.10</org.jetbrains.kotlin.version>
<github.slug>okta/okta-idx-java</github.slug>
Expand Down Expand Up @@ -252,6 +252,7 @@
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>8.3.1</version>
<configuration>
<!-- no js is used in this project -->
<retireJsAnalyzerEnabled>false</retireJsAnalyzerEnabled>
Expand Down
2 changes: 1 addition & 1 deletion samples/embedded-sign-in-widget/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>nimbus-jose-jwt</artifactId>
<version>9.19</version>
<version>9.30.2</version>
</dependency>

<!-- These are the selenium dependencies -->
Expand Down
11 changes: 0 additions & 11 deletions samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
</parent>

<artifactId>okta-idx-java-samples</artifactId>
<groupId>com.okta.idx.sdk</groupId>
<name>Okta IDX Java SDK :: Samples</name>
<packaging>pom</packaging>

Expand All @@ -34,14 +33,4 @@
<module>embedded-sign-in-widget</module>
</modules>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.3</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>

0 comments on commit 88a9e64

Please sign in to comment.