1 /* 2 * Copyright (c) 2002-2014, Mairie de Paris 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright notice 10 * and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright notice 13 * and the following disclaimer in the documentation and/or other materials 14 * provided with the distribution. 15 * 16 * 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its 17 * contributors may be used to endorse or promote products derived from 18 * this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE 24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 * 32 * License 1.0 33 */ 34 package fr.paris.lutece.plugins.mylutece.modules.persona.authentication; 35 36 import fr.paris.lutece.plugins.mylutece.authentication.PortalAuthentication; 37 import fr.paris.lutece.portal.service.security.LoginRedirectException; 38 import fr.paris.lutece.portal.service.security.LuteceUser; 39 import fr.paris.lutece.portal.service.util.AppPropertiesService; 40 import java.io.Serializable; 41 42 import javax.security.auth.login.LoginException; 43 44 import javax.servlet.http.HttpServletRequest; 45 46 47 /** 48 * The Class provides an implementation of the inherited abstract class 49 * PortalAuthentication based on OpenID 50 */ 51 public class PersonaAuthentication extends PortalAuthentication implements Serializable 52 { 53 //////////////////////////////////////////////////////////////////////////////////////////////// 54 // Constants 55 private static final String PROPERTY_AUTH_SERVICE_NAME = "mylutece-persona.service.name"; 56 private static final String CONSTANT_PATH_ICON = "images/local/skin/plugins/mylutece/modules/openid/mylutece-openid.png"; 57 private static final String PLUGIN_NAME = "mylutece-openid"; 58 59 /** 60 * Gets the Authentification service name 61 * 62 * @return The name of the authentication service 63 */ 64 @Override 65 public String getAuthServiceName( ) 66 { 67 return AppPropertiesService.getProperty( PROPERTY_AUTH_SERVICE_NAME ); 68 } 69 70 /** 71 * Gets the Authentification type 72 * 73 * @param request The HTTP request 74 * @return The type of authentication 75 */ 76 @Override 77 public String getAuthType( HttpServletRequest request ) 78 { 79 return HttpServletRequest.BASIC_AUTH; 80 } 81 82 /** 83 * This methods checks the login info in the LDAP repository 84 * 85 * 86 * @return A LuteceUser object corresponding to the login 87 * @param strUserName The username 88 * @param strUserPassword The password 89 * @param request The HttpServletRequest 90 * @throws LoginRedirectException This exception is used to redirect the 91 * authentication to the provider 92 * @throws LoginException The LoginException 93 */ 94 @Override 95 public LuteceUser login( String strUserName, String strUserPassword, HttpServletRequest request ) 96 throws LoginException, LoginRedirectException 97 { 98 return getHttpAuthenticatedUser( request ); 99 } 100 101 /** 102 * This methods logout the user 103 * 104 * @param user The user 105 */ 106 @Override 107 public void logout( LuteceUser user ) 108 { 109 } 110 111 /** 112 * This method returns an anonymous Lutece user 113 * 114 * @return An anonymous Lutece user 115 */ 116 @Override 117 public LuteceUser getAnonymousUser( ) 118 { 119 return new PersonaUser( LuteceUser.ANONYMOUS_USERNAME, this ); 120 } 121 122 /** 123 * Checks that the current user is associated to a given role 124 * 125 * @param user The user 126 * @param request The HTTP request 127 * @param strRole The role name 128 * @return Returns true if the user is associated to the role, otherwise 129 * false 130 */ 131 @Override 132 public boolean isUserInRole( LuteceUser user, HttpServletRequest request, String strRole ) 133 { 134 // Not used 135 return false; 136 } 137 138 /** 139 * 140 * {@inheritDoc} 141 */ 142 @Override 143 public String getIconUrl( ) 144 { 145 return CONSTANT_PATH_ICON; 146 } 147 148 /** 149 * 150 * {@inheritDoc} 151 */ 152 @Override 153 public String getName( ) 154 { 155 return PLUGIN_NAME; 156 } 157 158 /** 159 * 160 * {@inheritDoc} 161 */ 162 @Override 163 public String getPluginName( ) 164 { 165 return PLUGIN_NAME; 166 } 167 168 /** 169 * 170 * {@inheritDoc} 171 */ 172 @Override 173 public boolean isMultiAuthenticationSupported( ) 174 { 175 return false; 176 } 177 }