Search in sources :

Example 1 with WrongArgumentException

use of pl.edu.icm.unity.exceptions.WrongArgumentException in project unity by unity-idm.

the class RevocationResource method killSession.

private Response killSession(OAuthToken parsedAccessToken, long entity) throws EngineException {
    if (parsedAccessToken.getEffectiveScope() == null)
        return makeError(OAuth2Error.INVALID_SCOPE, "Insufficent scope to perform full logout.");
    Optional<String> logoutScope = Arrays.stream(parsedAccessToken.getEffectiveScope()).filter(scope -> LOGOUT_SCOPE.equals(scope)).findAny();
    if (!logoutScope.isPresent())
        return makeError(OAuth2Error.INVALID_SCOPE, "Insufficent scope to perform full logout.");
    try {
        LoginSession ownedSession = sessionManagement.getOwnedSession(new EntityParam(entity), realm.getName());
        sessionManagement.removeSession(ownedSession.getId(), true);
    } catch (WrongArgumentException e) {
    // ok - no session
    }
    return null;
}
Also used : Arrays(java.util.Arrays) Produces(javax.ws.rs.Produces) Path(javax.ws.rs.Path) Log(pl.edu.icm.unity.base.utils.Log) OAuthProcessor(pl.edu.icm.unity.oauth.as.OAuthProcessor) OAuthTokenRepository(pl.edu.icm.unity.oauth.as.OAuthTokenRepository) EntityParam(pl.edu.icm.unity.types.basic.EntityParam) FormParam(javax.ws.rs.FormParam) POST(javax.ws.rs.POST) Token(pl.edu.icm.unity.base.token.Token) WrongArgumentException(pl.edu.icm.unity.exceptions.WrongArgumentException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ErrorObject(com.nimbusds.oauth2.sdk.ErrorObject) AuthenticationRealm(pl.edu.icm.unity.types.authn.AuthenticationRealm) OAuthToken(pl.edu.icm.unity.oauth.as.OAuthToken) TokenNotFoundException(pl.edu.icm.unity.store.api.TokenDAO.TokenNotFoundException) TokensManagement(pl.edu.icm.unity.engine.api.token.TokensManagement) EngineException(pl.edu.icm.unity.exceptions.EngineException) ClientType(com.nimbusds.oauth2.sdk.client.ClientType) Logger(org.apache.logging.log4j.Logger) Response(javax.ws.rs.core.Response) HTTPResponse(com.nimbusds.oauth2.sdk.http.HTTPResponse) OAuth2Error(com.nimbusds.oauth2.sdk.OAuth2Error) LoginSession(pl.edu.icm.unity.engine.api.authn.LoginSession) Optional(java.util.Optional) SessionManagement(pl.edu.icm.unity.engine.api.session.SessionManagement) InvocationContext(pl.edu.icm.unity.engine.api.authn.InvocationContext) LoginSession(pl.edu.icm.unity.engine.api.authn.LoginSession) EntityParam(pl.edu.icm.unity.types.basic.EntityParam) WrongArgumentException(pl.edu.icm.unity.exceptions.WrongArgumentException)

Example 2 with WrongArgumentException

use of pl.edu.icm.unity.exceptions.WrongArgumentException in project unity by unity-idm.

the class OAuthSystemAttributesProvider method getLogoAT.

private AttributeType getLogoAT() {
    ImageAttributeSyntax syntax = new ImageAttributeSyntax();
    try {
        syntax.getConfig().setMaxHeight(200);
        syntax.getConfig().setMaxWidth(400);
        syntax.getConfig().setMaxSize(4000000);
    } catch (WrongArgumentException e) {
        throw new IllegalArgumentException(e);
    }
    AttributeType logoAt = new AttributeType(CLIENT_LOGO, syntax.getValueSyntaxId(), msg);
    logoAt.setFlags(AttributeType.TYPE_IMMUTABLE_FLAG);
    logoAt.setMinElements(1);
    logoAt.setMaxElements(1);
    logoAt.setUniqueValues(false);
    logoAt.setValueSyntaxConfiguration(syntax.getSerializedConfiguration());
    return logoAt;
}
Also used : AttributeType(pl.edu.icm.unity.types.basic.AttributeType) WrongArgumentException(pl.edu.icm.unity.exceptions.WrongArgumentException) ImageAttributeSyntax(pl.edu.icm.unity.stdext.attr.ImageAttributeSyntax)

Example 3 with WrongArgumentException

use of pl.edu.icm.unity.exceptions.WrongArgumentException in project unity by unity-idm.

the class CaptchaComponent method verify.

/**
 * Checks if the value entered in answer text field is the same as the one on captcha image.
 * If so then nothing more is done. If not then exception is raised and the captcha is regenerated.
 * @throws WrongArgumentException
 */
public void verify() throws WrongArgumentException {
    String attempt = answer.getValue();
    if (attempt == null) {
        reset();
        answer.setComponentError(new UserError(msg.getMessage("CaptchaComponent.wrongAnswer")));
        throw new WrongArgumentException("");
    }
    String rightAnswer = engine.getAnswer().toLowerCase();
    attempt = attempt.toLowerCase();
    if (!rightAnswer.equals(attempt)) {
        reset();
        answer.setComponentError(new UserError(msg.getMessage("CaptchaComponent.wrongAnswer")));
        throw new WrongArgumentException("");
    }
    answer.setComponentError(null);
}
Also used : UserError(com.vaadin.server.UserError) WrongArgumentException(pl.edu.icm.unity.exceptions.WrongArgumentException)

Example 4 with WrongArgumentException

use of pl.edu.icm.unity.exceptions.WrongArgumentException in project unity by unity-idm.

the class MessageTemplateLoader method loadTemplate.

private MessageTemplate loadTemplate(Properties properties, String id) throws WrongArgumentException {
    String consumer = properties.getProperty(id + ".consumer", "");
    String description = properties.getProperty(id + ".description", "");
    String typeStr = properties.getProperty(id + ".type", MessageType.PLAIN.name());
    String notificationChannel = properties.getProperty(id + ".notificationChannel", "");
    MessageType type;
    try {
        type = MessageType.valueOf(typeStr);
    } catch (Exception e) {
        throw new ConfigurationException("Invalid template type: " + typeStr + ", " + "for template id " + id + ", supported values are: " + MessageType.values(), e);
    }
    I18nString subjectI18 = getSubject(properties, id);
    I18nString bodyI18 = getBody(properties, id);
    I18nMessage tempMsg = new I18nMessage(subjectI18, bodyI18);
    return new MessageTemplate(id, description, tempMsg, consumer, type, notificationChannel);
}
Also used : MessageTemplate(pl.edu.icm.unity.types.basic.MessageTemplate) ConfigurationException(eu.unicore.util.configuration.ConfigurationException) I18nString(pl.edu.icm.unity.types.I18nString) I18nString(pl.edu.icm.unity.types.I18nString) I18nMessage(pl.edu.icm.unity.types.I18nMessage) MessageType(pl.edu.icm.unity.types.basic.MessageType) InternalException(pl.edu.icm.unity.exceptions.InternalException) WrongArgumentException(pl.edu.icm.unity.exceptions.WrongArgumentException) IOException(java.io.IOException) EngineException(pl.edu.icm.unity.exceptions.EngineException) ConfigurationException(eu.unicore.util.configuration.ConfigurationException)

Example 5 with WrongArgumentException

use of pl.edu.icm.unity.exceptions.WrongArgumentException in project unity by unity-idm.

the class MessageTemplateManagementImpl method validateMessageTemplate.

private void validateMessageTemplate(MessageTemplate toValidate) throws EngineException {
    MessageTemplateDefinition con = registry.getByName(toValidate.getConsumer());
    try {
        MessageTemplateValidator.validateMessage(con, toValidate.getMessage());
    } catch (IllegalVariablesException e) {
        throw new WrongArgumentException("The following variables are unknown: " + e.getUnknown());
    } catch (MandatoryVariablesException e) {
        throw new WrongArgumentException("The following variables must be used: " + e.getMandatory());
    }
    if (toValidate.getConsumer().equals(GenericMessageTemplateDef.NAME))
        return;
    String channel = toValidate.getNotificationChannel();
    if (channel == null || channel.isEmpty()) {
        throw new WrongArgumentException("Notification channel must be set in message template");
    }
    NotificationFacility facility;
    try {
        facility = facilityMan.getNotificationFacilityForChannel(channel);
    } catch (Exception e) {
        throw new WrongArgumentException("Cannot get facility for channel: " + channel, e);
    }
    if (!con.getCompatibleTechnologies().contains(facility.getTechnology())) {
        throw new WrongArgumentException("Notification channel " + toValidate.getNotificationChannel() + " is not compatible with used message consumer " + toValidate.getConsumer());
    }
}
Also used : IllegalVariablesException(pl.edu.icm.unity.engine.api.msgtemplate.MessageTemplateValidator.IllegalVariablesException) MessageTemplateDefinition(pl.edu.icm.unity.base.msgtemplates.MessageTemplateDefinition) MandatoryVariablesException(pl.edu.icm.unity.engine.api.msgtemplate.MessageTemplateValidator.MandatoryVariablesException) WrongArgumentException(pl.edu.icm.unity.exceptions.WrongArgumentException) NotificationFacility(pl.edu.icm.unity.engine.notifications.NotificationFacility) MandatoryVariablesException(pl.edu.icm.unity.engine.api.msgtemplate.MessageTemplateValidator.MandatoryVariablesException) WrongArgumentException(pl.edu.icm.unity.exceptions.WrongArgumentException) EngineException(pl.edu.icm.unity.exceptions.EngineException) IllegalVariablesException(pl.edu.icm.unity.engine.api.msgtemplate.MessageTemplateValidator.IllegalVariablesException)

Aggregations

WrongArgumentException (pl.edu.icm.unity.exceptions.WrongArgumentException)58 EngineException (pl.edu.icm.unity.exceptions.EngineException)18 IOException (java.io.IOException)9 Path (javax.ws.rs.Path)9 POST (javax.ws.rs.POST)6 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)5 IdentityExistsException (pl.edu.icm.unity.exceptions.IdentityExistsException)5 TypeReference (com.fasterxml.jackson.core.type.TypeReference)4 UserError (com.vaadin.server.UserError)4 Consumes (javax.ws.rs.Consumes)4 PUT (javax.ws.rs.PUT)4 WorkflowFinalizationConfiguration (pl.edu.icm.unity.engine.api.finalization.WorkflowFinalizationConfiguration)4 Transactional (pl.edu.icm.unity.store.api.tx.Transactional)4 EntityParam (pl.edu.icm.unity.types.basic.EntityParam)4 RegistrationContext (pl.edu.icm.unity.types.registration.RegistrationContext)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 TimeoutException (java.util.concurrent.TimeoutException)3 Produces (javax.ws.rs.Produces)3 Logger (org.apache.logging.log4j.Logger)3