Search in sources :

Example 1 with AuthoritiesException

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);
            }
        }
    }
}
Also used : FakeCredentials(se.inera.intyg.webcert.web.auth.fake.FakeCredentials) AuthenticationMethod(se.inera.intyg.infra.security.common.model.AuthenticationMethod) AuthoritiesException(se.inera.intyg.infra.security.authorities.AuthoritiesException) IntygUser(se.inera.intyg.infra.security.common.model.IntygUser)

Example 2 with AuthoritiesException

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");
            }
        }
    }
}
Also used : FakeCredentials(se.inera.intyg.webcert.web.auth.fake.FakeCredentials) AuthoritiesException(se.inera.intyg.infra.security.authorities.AuthoritiesException) IntygUser(se.inera.intyg.infra.security.common.model.IntygUser)

Aggregations

AuthoritiesException (se.inera.intyg.infra.security.authorities.AuthoritiesException)2 IntygUser (se.inera.intyg.infra.security.common.model.IntygUser)2 FakeCredentials (se.inera.intyg.webcert.web.auth.fake.FakeCredentials)2 AuthenticationMethod (se.inera.intyg.infra.security.common.model.AuthenticationMethod)1