Skip to content

Commit

Permalink
PAYARA-1707 Password and auth fields added to JavaMail Sessions in ad…
Browse files Browse the repository at this point in the history
…mingui (#1639)

* PAYARA-1707 Added password field to JavaMail sessionin admingui

* PAYARA-1707 Added auth field to JavaMail Sessions in admingui

* PAYARA-1707 Updated copyright
  • Loading branch information
Cousjava authored and smillidge committed Jun 13, 2017
1 parent 9dd2995 commit e44b474
Show file tree
Hide file tree
Showing 16 changed files with 225 additions and 27 deletions.
11 changes: 10 additions & 1 deletion appserver/admingui/full/src/main/resources/mailResourceAttr.inc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
only if the new code is made subject to such option by the copyright
holder.
Portions Copyright [2017] Payara Foundation and/or affiliates
-->

<!-- full/adminObjectAttr.inc -->
Expand All @@ -64,8 +65,16 @@

<sun:property id="userProp" labelAlign="left" noWrap="#{true}" overlapLabel="#{false}" label="$resource{i18njmail.javaMail.user}" helpText="$resource{i18njmail.javaMail.userHelp}">
<sun:textField id="user" styleClass="required" text="#{pageSession.valueMap['user']}" columns="$int{55}" maxLength="#{sessionScope.fieldLengths['maxLength.javaMail.user']}" required="#{true}" />
</sun:property>
</sun:property>

<sun:property id="passwordProp" labelAlign="left" noWrap="#{true}" overlapLabel="#{false}" label="$resource{i18njmail.javaMail.password}" helpText="$resource{i18njmail.javaMail.passwordHelp}">
<sun:textField id="password" text="#{pageSession.valueMap['password']}" columns="$int{55}" maxLength="#{sessionScope.fieldLengths['maxLength.javaMail.password']}" required="#{false}" />
</sun:property>

<sun:property id="authProp" labelAlign="left" noWrap="#{true}" overlapLabel="#{false}" label="$resource{i18njmail.javaMail.auth}" helpText="$resource{i18njmail.javaMail.authHelp}">
<sun:checkbox selected="#{pageSession.valueMap['auth']}" label="$resource{i18n.common.Enabled}" selectedValue="true"/>
</sun:property>

<sun:property id="fromProp" labelAlign="left" noWrap="#{true}" overlapLabel="#{false}" label="$resource{i18njmail.javaMail.returnAddr}" helpText="$resource{i18njmail.javaMail.returnAddrHelp}">
<sun:textField id="from" styleClass="required" text="#{pageSession.valueMap['from']}" columns="$int{55}" maxLength="#{sessionScope.fieldLengths['maxLength.javaMail.returnAddr']}" required="#{true}" />
</sun:property>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
only if the new code is made subject to such option by the copyright
holder.

Portions Copyright [2017] Payara Foundation and/or affiliates
-->

<!-- full/jmailResourceEdit.jsf -->
Expand Down Expand Up @@ -80,7 +81,7 @@
setPageSessionAttribute(key="selfUrl", value="#{pageSession.parentUrl}/#{pageSession.childType}/#{pageSession.encodedName}");
gf.getEntityAttrs(endpoint="#{pageSession.selfUrl}", valueMap="#{pageSession.valueMap}");

setPageSessionAttribute(key="convertToFalseList" value={"enabled", "debug"});
setPageSessionAttribute(key="convertToFalseList" value={"enabled", "debug", "auth"});
setPageSessionAttribute(key="skipAttrsList", value={"jndiName"});
gf.restRequest(endpoint="#{pageSession.selfUrl}/property.json" method="GET" result="#{requestScope.propTable}");
setPageSessionAttribute(key="tableList" value="#{requestScope.propTable.data.extraProperties.properties}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
only if the new code is made subject to such option by the copyright
holder.

Portions Copyright [2017] Payara Foundation and/or affiliates
-->

<!-- full/mailResourceNew.jsf -->
Expand All @@ -58,7 +59,7 @@
setPageSessionAttribute(key="parentUrl", value="#{sessionScope.REST_URL}/resources");
gf.getDefaultValues(endpoint="#{pageSession.parentUrl}/#{pageSession.childType}", valueMap="#{pageSession.valueMap}");

setPageSessionAttribute(key="convertToFalseList" value={"enabled", "debug"});
setPageSessionAttribute(key="convertToFalseList" value={"enabled", "debug", "auth"});
//set the following for including buttons.inc
setPageSessionAttribute(key="edit" value="#{false}" );
setPageSessionAttribute(key="showDefaultButton" value="#{true}" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
# only if the new code is made subject to such option by the copyright
# holder.
#
# Portions Copyright [2016] [Payara Foundation]
# Portions Copyright [2016-2017] [Payara Foundation and/or affiliates]
## Java Mail Sessions
javaMailSessions.pageTitle=JavaMail Sessions
javaMailSessions.pageTitleHelp=A JavaMail session resource represents a mail session in the JavaMail API, which provides a platform-independent and protocol-independent framework to build mail and messaging applications.
Expand Down Expand Up @@ -65,7 +65,10 @@ javaMail.transProtocolClass=Transport Protocol Class:
javaMail.transProtocolClassHelp=Default is com.sun.mail.smtp.SMTPTransport
javaMail.Debug=Debug:
javaMail.DebugHelp=Select the Debug checkbox to enable extra debugging output for this mail session, including a protocol trace.

javaMail.password=Password
javaMail.passwordHelp=Password for the user
javaMail.auth=Auth
javaMail.authHelp=Authorisation enabled

## Custom and JNDI Resource
customResources.pageTitle=Custom Resources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
* Portions Copyright [2017] Payara Foundation and/or affiliates
*/

package com.sun.enterprise.resource.deployer;
Expand Down Expand Up @@ -459,6 +461,28 @@ public void setUser(String value) throws PropertyVetoException {
//do nothing
}

@Override
public String getPassword(){
return desc.getPassword();
}

@Override
public void setPassword(String value){
//do nothing
}

@Override
public String getAuth(){
return desc.getAuth();
}

@Override
public void setAuth(String value) throws PropertyVetoException {
//do nothing
}



@Override
public String getFrom() {
return desc.getFrom();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
* Portions Copyright [2017] Payara Foundation and/or affiliates
*/

package com.sun.enterprise.deployment;
Expand Down Expand Up @@ -66,13 +68,16 @@ public class MailConfiguration implements Serializable {
"mail.transport.protocol";
private static final String MAIL_HOST = "mail.host";
private static final String MAIL_USER = "mail.user";
private static final String MAIL_PASSWORD = "mail.password";
private static final String MAIL_FROM = "mail.from";
private static final String MAIL_DEBUG = "mail.debug";

private static final String MAIL_PREFIX = "mail.";
private static final String MAIL_SUFFIX_CLASS = ".class";
private static final String MAIL_SUFFIX_HOST = ".host";
private static final String MAIL_SUFFIX_USER = ".user";
private static final String MAIL_SUFFIX_PASSWORD = ".password";
private static final String MAIL_SUFFIX_AUTH = ".auth";
private static final char MAIL_DELIM = '.';

/**
Expand All @@ -87,6 +92,8 @@ public class MailConfiguration implements Serializable {
private String transportProtocolClass = null;
private String mailHost = null;
private String username = null;
private String password = null;
private boolean auth = false;
private String mailFrom = null;
private boolean debug = false;

Expand Down Expand Up @@ -149,6 +156,8 @@ private void loadMailResources(MailResourceIntf mailResource)
transportProtocolClass = mailResource.getTransportProtocolClass();
mailHost = mailResource.getMailHost();
username = mailResource.getUsername();
password = mailResource.getPassword();
auth = mailResource.getAuth();
mailFrom = mailResource.getMailFrom();
debug = mailResource.isDebug();
if (_logger.isLoggable(Level.FINE)) {
Expand All @@ -158,25 +167,32 @@ private void loadMailResources(MailResourceIntf mailResource)
_logger.fine("transportProtocolClass " + transportProtocolClass);
_logger.fine("mailHost " + mailHost);
_logger.fine("username " + username);
_logger.fine("password has been set.");//Not displayed
_logger.fine("auth" + auth);
_logger.fine("mailFrom " + mailFrom);
_logger.fine("debug " + debug);
}

// JavaMail doesn't default this one properly
if (transportProtocol == null)
if (transportProtocol == null){
transportProtocol = "smtp";

}
// Save to Property list
put(MAIL_HOST, mailHost);
put(MAIL_USER, username);
put(MAIL_PASSWORD, password);
put(MAIL_STORE_PROTOCOL, storeProtocol);
put(MAIL_TRANSPORT_PROTOCOL, transportProtocol);
if (storeProtocol != null)

if (storeProtocol != null){
put(MAIL_PREFIX + storeProtocol + MAIL_SUFFIX_CLASS,
storeProtocolClass);
if (transportProtocol != null)
}
if (transportProtocol != null){
put(MAIL_PREFIX + transportProtocol + MAIL_SUFFIX_CLASS,
transportProtocolClass);
put(MAIL_PREFIX + transportProtocol + MAIL_SUFFIX_AUTH, Boolean.toString(auth));
}
put(MAIL_FROM, mailFrom);
put(MAIL_DEBUG, (debug ? "true" : "false"));

Expand All @@ -188,12 +204,13 @@ private void loadMailResources(MailResourceIntf mailResource)
String name = property.getName();
String value = (String)property.getValue();

if (name.startsWith(PROP_NAME_PREFIX_LEGACY))
if (name.startsWith(PROP_NAME_PREFIX_LEGACY)){
name = name.replace(PROP_NAME_DELIM_LEGACY, MAIL_DELIM);

}
put(name, value);
if (_logger.isLoggable(Level.FINE))
if (_logger.isLoggable(Level.FINE)){
_logger.fine("mail property: " + name + " = " + value);
}
}
}

Expand All @@ -216,6 +233,22 @@ public String getUsername() {
return this.username;
}

/**
* Get the password for the mail session the server will provide.
* @return the password.
*/
public String getPassword(){
return this.password;
}

/**
* Get whether authentication is enabled for the mail session the server will provide
* @return the authentication status.
*/
public boolean getAuth(){
return this.auth;
}

/**
* Get the mail from address for the mail session the server will provide.
* @return the from address.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
* Portions Copyright [2017] Payara Foundation and/or affiliates
*/

package com.sun.enterprise.deployment;
Expand All @@ -55,6 +57,7 @@ public class MailSessionDescriptor extends ResourceDescriptor {
private String transportProtocol;
private String user;
private String password;
private String auth;
private String host;
private String from;
private Properties properties = new Properties();
Expand Down Expand Up @@ -127,6 +130,14 @@ public String getPassword() {
public void setPassword(String password) {
this.password = password;
}

public String getAuth(){
return auth;
}

public void setAuth(String auth){
this.auth = auth;
}

public String getHost() {
return host;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
* Portions Copyright [2017] Payara Foundation and/or affiliates
*/

package com.sun.enterprise.deployment.interfaces;
Expand All @@ -45,12 +47,12 @@
public interface MailResourceIntf {

public String getName();

public String getDescription();

public String getDescription();

public boolean isEnabled();
public boolean isEnabled();

public Set getProperties();
public Set getProperties();

public int getType();

Expand All @@ -70,6 +72,10 @@ public interface MailResourceIntf {

public String getUsername();

public String getPassword();

public boolean getAuth();

public String getMailFrom();

public boolean isDebug();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
* Portions Copyright [2017] Payara Foundation and/or affiliates
*/

package org.glassfish.resources.javamail;
Expand All @@ -62,6 +64,9 @@ protected PasswordAuthentication getPasswordAuthentication() {
String protocol = getRequestingProtocol();
if(protocol != null) {
String password = props.getProperty("mail." + protocol + ".password");
if (password == null){
password = props.getProperty("mail.password");
}
String username = getDefaultUserName();
if(password != null && username != null) {
authenticator = new PasswordAuthentication(username, password);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
* Portions Copyright [2017] Payara Foundation and/or affiliates
*/

package org.glassfish.resources.javamail.admin.cli;
Expand Down Expand Up @@ -87,6 +89,12 @@ public class CreateJavaMailResource implements AdminCommand {
@Param(name="mailuser", alias="user")
private String mailUser;

@Param(name="password", optional=true)
private String mailPassword;

@Param(name="auth", optional=true, defaultValue="false")
private Boolean auth;

@Param(name="fromaddress",alias="from")
private String fromAddress;

Expand Down Expand Up @@ -142,6 +150,8 @@ public void execute(AdminCommandContext context) {
attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.JNDI_NAME, jndiName);
attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_HOST, mailHost);
attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_USER, mailUser);
attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_PASSWORD, mailPassword);
attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_AUTH, auth.toString());
attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_FROM_ADDRESS, fromAddress);
attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_STORE_PROTO, storeProtocol);
attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_STORE_PROTO_CLASS, storeProtocolClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
* Portions Copyright [2017] Payara Foundation and/or affiliates
*/

package org.glassfish.resources.javamail.admin.cli;
Expand Down Expand Up @@ -74,6 +76,8 @@ public class JavaMailResourceManager implements org.glassfish.resources.admin.cl

private String mailHost = null;
private String mailUser = null;
private String mailPassword = null;
private String auth = null;
private String fromAddress = null;
private String jndiName = null;
private String storeProtocol = null;
Expand Down Expand Up @@ -175,6 +179,8 @@ private MailResource createConfigBean(Resources param, Properties props) throws
newResource.setJndiName(jndiName);
newResource.setFrom(fromAddress);
newResource.setUser(mailUser);
newResource.setPassword(mailPassword);
newResource.setAuth(auth);
newResource.setHost(mailHost);
newResource.setEnabled(enabled);
newResource.setStoreProtocol(storeProtocol);
Expand All @@ -201,6 +207,8 @@ private void setAttributes(HashMap attributes, String target) {
jndiName = (String) attributes.get(JNDI_NAME);
mailHost = (String) attributes.get(MAIL_HOST);
mailUser = (String) attributes.get(MAIL_USER);
mailPassword = (String) attributes.get(MAIL_PASSWORD);
auth = (String) attributes.get(MAIL_AUTH);
fromAddress = (String) attributes.get(MAIL_FROM_ADDRESS);
storeProtocol = (String) attributes.get(MAIL_STORE_PROTO);
storeProtocolClass = (String) attributes.get(MAIL_STORE_PROTO_CLASS);
Expand Down
Loading

0 comments on commit e44b474

Please sign in to comment.