use of se.inera.intyg.infra.security.authorities.AuthoritiesException in project webcert by sklintyg.
the class CommonFakeAuthenticationProvider method applyAuthenticationMethod.
private void applyAuthenticationMethod(Authentication token, Object details) {
if (details instanceof IntygUser) {
if (token.getCredentials() != null && ((FakeCredentials) token.getCredentials()).getOrigin() != null) {
String authenticationMethod = ((FakeCredentials) token.getCredentials()).getAuthenticationMethod();
try {
if (authenticationMethod != null && !authenticationMethod.isEmpty()) {
IntygUser user = (IntygUser) details;
AuthenticationMethod newAuthMethod = AuthenticationMethod.valueOf(authenticationMethod);
user.setAuthenticationMethod(newAuthMethod);
}
} catch (IllegalArgumentException e) {
String allowedTypes = Arrays.asList(AuthenticationMethod.values()).stream().map(val -> val.name()).collect(Collectors.joining(", "));
throw new AuthoritiesException("Could not set authenticationMethod '" + authenticationMethod + "'. Unknown, allowed types are " + allowedTypes);
}
}
}
}
use of se.inera.intyg.infra.security.authorities.AuthoritiesException in project webcert by sklintyg.
the class CommonFakeAuthenticationProvider method applyUserOrigin.
private void applyUserOrigin(Authentication token, Object details) {
if (details instanceof IntygUser) {
if (token.getCredentials() != null && ((FakeCredentials) token.getCredentials()).getOrigin() != null) {
String origin = ((FakeCredentials) token.getCredentials()).getOrigin();
try {
// Type check.
UserOriginType.valueOf(origin);
((IntygUser) details).setOrigin(origin);
} catch (IllegalArgumentException e) {
throw new AuthoritiesException("Could not set origin '" + origin + "'. Unknown, allowed types are NORMAL, DJUPINTEGRATION, UTHOPP");
}
}
}
}
Aggregations