Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

External Authorization handler

Avatar

Level 1

I wrote an External Authorization handler and have added it to one of my policies. The process of creating it and deploying it all seemed to work successfully. However, when I protect a document using the policy, something is not working correctly. My external authorization handler is supposed to send an email once it gets invoked. However, when I open the document, no email is sent. Can someone help me? Here is my code:

public ExternalAuthResultDTO evaluate(ExternalAuthDTO arg0) {
ExternalAuthResultDTO retObj = new ExternalAuthResultDTO();
String docId = arg0.getAlternateId();
String clientIP = arg0.getClientIPAddress();
ArrayList<?> permissions = arg0.getPermissions();
retObj.setPermissions(permissions);

String host = "smtp.gmail.com";
String from = "username";
String pass = "password";
Properties props = new Properties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", from);
props.put("mail.smtp.password", pass);
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");

String[] to = {"user@gmail.com"};

Session session = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(session);
try {
message.setFrom(new InternetAddress(from));
InternetAddress[] toAddress = new InternetAddress[to.length];
// To get the array of addresses
for( int i=0; i < to.length; i++ ) {
    toAddress[i] = new InternetAddress(to[i]);
}
for( int i=0; i < toAddress.length; i++) {
    message.addRecipient(Message.RecipientType.TO, toAddress[i]);
}
message.setSubject("Document Opened");
message.setText("Document: " + docId + "\nClient IP: " + clientIP);
  
Transport transport = session.getTransport("smtp");
transport.connect(host, from, pass);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
} catch (AddressException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return retObj;
}
1 Reply

Avatar

Employee

Can you pull out the code to send email in a separate java program and try sending email with that? If you are able to make it work then put the same back in the External Authorizer.