// Path: src/main/java/net/unicon/cas/addons/authentication/principal/util/PrincipalUtils.java
// public final class PrincipalUtils {
// 
//     /**
//      * Parses the <code>username</code> and transforms it back if the value is recognized as en email address.
//      * Otherwise, returns the original value.
//      * 
//      * @param username username or email address of the principal passed. A valid email address would be in the format of
//      * "user@domain.edu"
//      * @return Transformed <code>username</code> or <code>null</code> if <code>username</code> is <code>null</code> or blank.
//      */
//     public static String parseNamePartFromEmailAddressIfNecessary(final String username) {
//         if (StringUtils.isBlank(username)) {
//             return null;
//         }
// 
//         final int idx = username.indexOf('@');
//         if (idx == -1) {
//             return username;
//         }
//         return username.substring(0, idx);
//     }
// 
// }


import net.unicon.cas.addons.authentication.principal.util.PrincipalUtils;
import org.jasig.cas.authentication.handler.PrincipalNameTransformer;
package net.unicon.cas.addons.authentication.handler;



/**
 * An implementation of the {@link PrincipalNameTransformer} that accepts an email address
 * and transforms it back to the user id.
 * 
 * <p>Note: this API is only intended to be called by CAS server code e.g. any custom CAS server overlay extension, etc.</p>
 * 
 * @author <a href="mailto:mmoayyed@unicon.net">Misagh Moayyed</a>
 * @author Unicon, inc.
 * @since 0.6
 */
public class EmailAddressToPrincipalNameTransformer implements PrincipalNameTransformer {

    @Override
    public String transform(final String principalId) {
// Path: src/main/java/net/unicon/cas/addons/authentication/principal/util/PrincipalUtils.java
// public final class PrincipalUtils {
// 
//     /**
//      * Parses the <code>username</code> and transforms it back if the value is recognized as en email address.
//      * Otherwise, returns the original value.
//      * 
//      * @param username username or email address of the principal passed. A valid email address would be in the format of
//      * "user@domain.edu"
//      * @return Transformed <code>username</code> or <code>null</code> if <code>username</code> is <code>null</code> or blank.
//      */
//     public static String parseNamePartFromEmailAddressIfNecessary(final String username) {
//         if (StringUtils.isBlank(username)) {
//             return null;
//         }
// 
//         final int idx = username.indexOf('@');
//         if (idx == -1) {
//             return username;
//         }
//         return username.substring(0, idx);
//     }
// 
// }


// Path: src/main/java/net/unicon/cas/addons/authentication/handler/EmailAddressToPrincipalNameTransformer.java
import net.unicon.cas.addons.authentication.principal.util.PrincipalUtils;
import org.jasig.cas.authentication.handler.PrincipalNameTransformer;

package net.unicon.cas.addons.authentication.handler;



/**
 * An implementation of the {@link PrincipalNameTransformer} that accepts an email address
 * and transforms it back to the user id.
 * 
 * <p>Note: this API is only intended to be called by CAS server code e.g. any custom CAS server overlay extension, etc.</p>
 * 
 * @author <a href="mailto:mmoayyed@unicon.net">Misagh Moayyed</a>
 * @author Unicon, inc.
 * @since 0.6
 */
public class EmailAddressToPrincipalNameTransformer implements PrincipalNameTransformer {

    @Override
    public String transform(final String principalId) {
        return PrincipalUtils.parseNamePartFromEmailAddressIfNecessary(principalId);