001/* 002 * Copyright 2016 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.plugins.core.impl.authentication; 017 018import java.util.Map; 019 020import org.apache.cocoon.environment.Redirector; 021 022import org.ametys.core.authentication.AbstractCredentialProvider; 023import org.ametys.core.authentication.NonBlockingCredentialProvider; 024import org.ametys.core.user.UserIdentity; 025 026/** 027 * This implementation will always provide the same credentials 028 */ 029public class DefinedCredentialProvider extends AbstractCredentialProvider implements NonBlockingCredentialProvider 030{ 031 /** Name of the parameter holding the defined user */ 032 private static final String __PARAM_USER = "runtime.authentication.defined.user"; 033 034 /** The credentials */ 035 private UserIdentity _userIdentity; 036 037 @Override 038 public void init(String id, String cpModelId, Map<String, Object> paramValues, String label) 039 { 040 super.init(id, cpModelId, paramValues, label); 041 String login = (String) paramValues.get(__PARAM_USER); 042 _userIdentity = new UserIdentity(login, null); 043 } 044 045 @Override 046 public boolean nonBlockingIsStillConnected(UserIdentity userIdentity, Redirector redirector) throws Exception 047 { 048 return true; 049 } 050 051 @Override 052 public boolean nonBlockingGrantAnonymousRequest() 053 { 054 return false; 055 } 056 057 @Override 058 public UserIdentity nonBlockingGetUserIdentity(Redirector redirector) throws Exception 059 { 060 return _userIdentity; 061 } 062 063 @Override 064 public void nonBlockingUserNotAllowed(Redirector redirector) throws Exception 065 { 066 // nothing 067 } 068 069 @Override 070 public void nonBlockingUserAllowed(UserIdentity userIdentity) 071 { 072 // nothing 073 } 074}