001/* 002 * Licensed under the Apache License, Version 2.0 (the "License"); 003 * you may not use this file except in compliance with the License. 004 * You may obtain a copy of the License at 005 * 006 * http://www.apache.org/licenses/LICENSE-2.0 007 * 008 * Unless required by applicable law or agreed to in writing, software 009 * distributed under the License is distributed on an "AS IS" BASIS, 010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 011 * See the License for the specific language governing permissions and 012 * limitations under the License. 013 */ 014package org.gbif.ws.remoteauth.app; 015 016import org.gbif.ws.security.GbifAuthUtils; 017 018import java.util.Objects; 019 020import org.springframework.security.authentication.AbstractAuthenticationToken; 021 022/** 023 * GBIF APP {@link org.springframework.security.core.Authentication}. 024 */ 025public class GbifAppAuthentication extends AbstractAuthenticationToken { 026 027 private String gbifScheme; 028 private String gbifUser; 029 private String contentMd5; 030 private String contentType; 031 private String method; 032 private String originalRequestUrl; 033 034 public GbifAppAuthentication( 035 String gbifScheme, 036 String gbifUser, 037 String contentMd5, 038 String contentType, 039 String method, 040 String originalRequestUrl) { 041 super(null); 042 this.gbifScheme = gbifScheme; 043 this.gbifUser = gbifUser; 044 this.contentMd5 = contentMd5; 045 this.contentType = contentType; 046 this.method = method; 047 this.originalRequestUrl = originalRequestUrl; 048 super.setAuthenticated(false); 049 } 050 051 @Override 052 public Object getCredentials() { 053 return null; 054 } 055 056 @Override 057 public Object getPrincipal() { 058 return gbifUser; 059 } 060 061 public String getAppKey() { 062 return GbifAuthUtils.getAppKeyFromRequest(gbifScheme); 063 } 064 065 public String getGbifScheme() { 066 return gbifScheme; 067 } 068 069 public String getContentMd5() { 070 return contentMd5; 071 } 072 073 public String getMethod() { 074 return method; 075 } 076 077 public String getOriginalRequestUrl() { 078 return originalRequestUrl; 079 } 080 081 public String getContentType() { 082 return contentType; 083 } 084 085 @Override 086 public boolean equals(Object o) { 087 if (this == o) { 088 return true; 089 } 090 if (!(o instanceof GbifAppAuthentication)) { 091 return false; 092 } 093 if (!super.equals(o)) { 094 return false; 095 } 096 GbifAppAuthentication that = (GbifAppAuthentication) o; 097 return Objects.equals(gbifScheme, that.gbifScheme) 098 && Objects.equals(gbifUser, that.gbifUser) 099 && Objects.equals(contentMd5, that.contentMd5) 100 && Objects.equals(contentType, that.contentType) 101 && Objects.equals(originalRequestUrl, that.originalRequestUrl); 102 } 103 104 @Override 105 public int hashCode() { 106 return Objects.hash( 107 super.hashCode(), gbifScheme, gbifUser, contentMd5, contentType, originalRequestUrl); 108 } 109}