001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.reef.runtime.common.client.defaults; 020 021import org.apache.reef.annotations.audience.ClientSide; 022import org.apache.reef.annotations.audience.DriverSide; 023import org.apache.reef.annotations.audience.Private; 024import org.apache.reef.runtime.common.UserCredentials; 025 026import javax.inject.Inject; 027import java.io.IOException; 028import java.security.PrivilegedExceptionAction; 029 030/** 031 * A holder object for REEF user credentials. 032 */ 033@Private 034@ClientSide 035@DriverSide 036public final class DefaultUserCredentials implements UserCredentials { 037 038 @Inject 039 private DefaultUserCredentials() { } 040 041 /** 042 * Copy credentials from another existing user. 043 * This method can be called only once per instance. 044 * This default implementation should never be called. 045 * @param name Name of the new user. 046 * @param other Credentials of another user. 047 * @throws RuntimeException always throws. 048 */ 049 @Override 050 public void set(final String name, final UserCredentials other) throws IOException { 051 throw new RuntimeException("Not implemented! Attempt to set user " + name + " from: " + other); 052 } 053 054 /** 055 * Check if the user credentials had been set. Always returns false. 056 * @return always false. 057 */ 058 @Override 059 public boolean isSet() { 060 return false; 061 } 062 063 /** 064 * Execute the privileged action as a given user. 065 * This implementation always executes the action outside the user context, simply by calling action.run(). 066 * @param action an action to run. 067 * @param <T> action return type. 068 * @return result of an action. 069 * @throws Exception whatever the action can throw. 070 */ 071 @Override 072 public <T> T doAs(final PrivilegedExceptionAction<T> action) throws Exception { 073 return action.run(); 074 } 075}