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;
}
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;
}
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);
}
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);
}
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());
}
}
Aggregations