Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
atlas
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dataplatform
atlas
Commits
40d909ef
Commit
40d909ef
authored
8 years ago
by
rdsolani
Committed by
nixonrodrigues
8 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-1896:Fix for adding Cross Origin [CORS] headers for Atlas
Signed-off-by:
nixonrodrigues
<
nixon@apache.org
>
parent
4e62a062
master
No related merge requests found
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
55 additions
and
31 deletions
+55
-31
SHA256Utils.java
common/src/main/java/org/apache/atlas/utils/SHA256Utils.java
+20
-18
atlas-application.properties
distro/src/conf/atlas-application.properties
+7
-0
TypedInstanceToGraphMapper.java
...he/atlas/repository/graph/TypedInstanceToGraphMapper.java
+2
-2
Id.java
...main/java/org/apache/atlas/typesystem/persistence/Id.java
+2
-2
ReferenceableInstance.java
...e/atlas/typesystem/persistence/ReferenceableInstance.java
+2
-2
StructInstance.java
...g/apache/atlas/typesystem/persistence/StructInstance.java
+2
-2
AtlasAuthenticationFilter.java
...g/apache/atlas/web/filters/AtlasAuthenticationFilter.java
+20
-5
No files found.
common/src/main/java/org/apache/atlas/utils/
MD5
Utils.java
→
common/src/main/java/org/apache/atlas/utils/
SHA256
Utils.java
View file @
40d909ef
...
@@ -15,25 +15,22 @@
...
@@ -15,25 +15,22 @@
* See the License for the specific language governing permissions and
* See the License for the specific language governing permissions and
* limitations under the License.
* limitations under the License.
*/
*/
package
org
.
apache
.
atlas
.
utils
;
package
org
.
apache
.
atlas
.
utils
;
import
java.security.MessageDigest
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
import
java.security.NoSuchAlgorithmException
;
/**
public
class
SHA256Utils
{
* Utilities for MD5 hash.
*/
public
final
class
MD5Utils
{
private
MD5Utils
()
{
}
private
static
final
ThreadLocal
<
MessageDigest
>
DIGESTER_FACTORY
=
private
static
final
ThreadLocal
<
MessageDigest
>
DIGESTER_FACTORY
=
new
ThreadLocal
<
MessageDigest
>()
{
new
ThreadLocal
<
MessageDigest
>()
{
@Override
@Override
protected
MessageDigest
initialValue
()
{
protected
MessageDigest
initialValue
()
{
try
{
try
{
return
MessageDigest
.
getInstance
(
"
MD5
"
);
return
MessageDigest
.
getInstance
(
"
SHA-256
"
);
}
catch
(
NoSuchAlgorithmException
e
)
{
}
catch
(
NoSuchAlgorithmException
e
)
{
throw
new
RuntimeException
(
e
);
throw
new
RuntimeException
(
e
);
}
}
...
@@ -41,26 +38,31 @@ public final class MD5Utils {
...
@@ -41,26 +38,31 @@ public final class MD5Utils {
};
};
/**
/**
* Create a thread local
MD5
digester.
* Create a thread local
SHA256
digester.
*/
*/
public
static
MessageDigest
getDigester
()
{
public
static
MessageDigest
getDigester
()
{
MessageDigest
digester
=
DIGESTER_FACTORY
.
get
();
MessageDigest
digester
=
DIGESTER_FACTORY
.
get
();
digester
.
reset
();
digester
.
reset
();
return
digester
;
return
digester
;
}
}
private
static
final
char
[]
HEX_DIGITS
=
public
static
String
toString
(
byte
[]
hash
)
{
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
};
try
{
StringBuffer
hexString
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
hash
.
length
;
i
++)
{
String
hex
=
Integer
.
toHexString
(
0xff
&
hash
[
i
]);
if
(
hex
.
length
()
==
1
)
hexString
.
append
(
'0'
);
hexString
.
append
(
hex
);
}
public
static
String
toString
(
byte
[]
digest
)
{
return
hexString
.
toString
();
StringBuilder
buf
=
new
StringBuilder
(
MD5_LEN
*
2
);
}
catch
(
Exception
ex
){
for
(
int
i
=
0
;
i
<
MD5_LEN
;
i
++)
{
throw
new
RuntimeException
(
ex
);
int
b
=
digest
[
i
];
buf
.
append
(
HEX_DIGITS
[(
b
>>
4
)
&
0xf
]);
buf
.
append
(
HEX_DIGITS
[
b
&
0xf
]);
}
}
return
buf
.
toString
();
}
}
public
static
final
int
MD5_LEN
=
16
;
}
}
This diff is collapsed.
Click to expand it.
distro/src/conf/atlas-application.properties
View file @
40d909ef
...
@@ -251,3 +251,10 @@ atlas.metric.query.cache.ttlInSecs=900
...
@@ -251,3 +251,10 @@ atlas.metric.query.cache.ttlInSecs=900
#Set to false to disable full text search.
#Set to false to disable full text search.
#atlas.search.fulltext.enable=true
#atlas.search.fulltext.enable=true
########## Add http headers ###########
#atlas.headers.Access-Control-Allow-Origin=*
#atlas.headers.Access-Control-Allow-Methods=GET,OPTIONS,HEAD,PUT,POST
#atlas.headers.<headerName>=<headerValue>
This diff is collapsed.
Click to expand it.
repository/src/main/java/org/apache/atlas/repository/graph/TypedInstanceToGraphMapper.java
View file @
40d909ef
...
@@ -39,7 +39,7 @@ import org.apache.atlas.typesystem.types.*;
...
@@ -39,7 +39,7 @@ import org.apache.atlas.typesystem.types.*;
import
org.apache.atlas.typesystem.types.DataTypes.TypeCategory
;
import
org.apache.atlas.typesystem.types.DataTypes.TypeCategory
;
import
org.apache.atlas.typesystem.types.utils.TypesUtil
;
import
org.apache.atlas.typesystem.types.utils.TypesUtil
;
import
org.apache.atlas.util.AtlasRepositoryConfiguration
;
import
org.apache.atlas.util.AtlasRepositoryConfiguration
;
import
org.apache.atlas.utils.
MD5
Utils
;
import
org.apache.atlas.utils.
SHA256
Utils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
...
@@ -675,7 +675,7 @@ public final class TypedInstanceToGraphMapper {
...
@@ -675,7 +675,7 @@ public final class TypedInstanceToGraphMapper {
}
}
// Update attributes
// Update attributes
final
MessageDigest
digester
=
MD5
Utils
.
getDigester
();
final
MessageDigest
digester
=
SHA256
Utils
.
getDigester
();
String
newSignature
=
newAttributeValue
.
getSignatureHash
(
digester
);
String
newSignature
=
newAttributeValue
.
getSignatureHash
(
digester
);
String
curSignature
=
GraphHelper
.
getSingleValuedProperty
(
structInstanceVertex
,
SIGNATURE_HASH_PROPERTY_KEY
,
String
.
class
);
String
curSignature
=
GraphHelper
.
getSingleValuedProperty
(
structInstanceVertex
,
SIGNATURE_HASH_PROPERTY_KEY
,
String
.
class
);
...
...
This diff is collapsed.
Click to expand it.
typesystem/src/main/java/org/apache/atlas/typesystem/persistence/Id.java
View file @
40d909ef
...
@@ -24,7 +24,7 @@ import org.apache.atlas.utils.ParamChecker;
...
@@ -24,7 +24,7 @@ import org.apache.atlas.utils.ParamChecker;
import
org.apache.atlas.typesystem.IStruct
;
import
org.apache.atlas.typesystem.IStruct
;
import
org.apache.atlas.typesystem.ITypedReferenceableInstance
;
import
org.apache.atlas.typesystem.ITypedReferenceableInstance
;
import
org.apache.atlas.typesystem.types.FieldMapping
;
import
org.apache.atlas.typesystem.types.FieldMapping
;
import
org.apache.atlas.utils.
MD5
Utils
;
import
org.apache.atlas.utils.
SHA256
Utils
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.math.BigInteger
;
...
@@ -290,7 +290,7 @@ public class Id implements ITypedReferenceableInstance {
...
@@ -290,7 +290,7 @@ public class Id implements ITypedReferenceableInstance {
digester
.
update
(
id
.
getBytes
(
Charset
.
forName
(
"UTF-8"
)));
digester
.
update
(
id
.
getBytes
(
Charset
.
forName
(
"UTF-8"
)));
digester
.
update
(
typeName
.
getBytes
(
Charset
.
forName
(
"UTF-8"
)));
digester
.
update
(
typeName
.
getBytes
(
Charset
.
forName
(
"UTF-8"
)));
byte
[]
digest
=
digester
.
digest
();
byte
[]
digest
=
digester
.
digest
();
return
MD5
Utils
.
toString
(
digest
);
return
SHA256
Utils
.
toString
(
digest
);
}
}
private
static
long
nextNegativeLong
()
{
private
static
long
nextNegativeLong
()
{
...
...
This diff is collapsed.
Click to expand it.
typesystem/src/main/java/org/apache/atlas/typesystem/persistence/ReferenceableInstance.java
View file @
40d909ef
...
@@ -29,7 +29,7 @@ import org.apache.atlas.typesystem.ITypedStruct;
...
@@ -29,7 +29,7 @@ import org.apache.atlas.typesystem.ITypedStruct;
import
org.apache.atlas.typesystem.types.ClassType
;
import
org.apache.atlas.typesystem.types.ClassType
;
import
org.apache.atlas.typesystem.types.FieldMapping
;
import
org.apache.atlas.typesystem.types.FieldMapping
;
import
org.apache.atlas.typesystem.types.TypeSystem
;
import
org.apache.atlas.typesystem.types.TypeSystem
;
import
org.apache.atlas.utils.
MD5
Utils
;
import
org.apache.atlas.utils.
SHA256
Utils
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.math.BigInteger
;
...
@@ -130,6 +130,6 @@ public class ReferenceableInstance extends StructInstance implements ITypedRefer
...
@@ -130,6 +130,6 @@ public class ReferenceableInstance extends StructInstance implements ITypedRefer
ClassType
classType
=
TypeSystem
.
getInstance
().
getDataType
(
ClassType
.
class
,
getTypeName
());
ClassType
classType
=
TypeSystem
.
getInstance
().
getDataType
(
ClassType
.
class
,
getTypeName
());
classType
.
updateSignatureHash
(
digester
,
this
);
classType
.
updateSignatureHash
(
digester
,
this
);
byte
[]
digest
=
digester
.
digest
();
byte
[]
digest
=
digester
.
digest
();
return
MD5
Utils
.
toString
(
digest
);
return
SHA256
Utils
.
toString
(
digest
);
}
}
}
}
This diff is collapsed.
Click to expand it.
typesystem/src/main/java/org/apache/atlas/typesystem/persistence/StructInstance.java
View file @
40d909ef
...
@@ -32,7 +32,7 @@ import org.apache.atlas.typesystem.types.FieldMapping;
...
@@ -32,7 +32,7 @@ import org.apache.atlas.typesystem.types.FieldMapping;
import
org.apache.atlas.typesystem.types.StructType
;
import
org.apache.atlas.typesystem.types.StructType
;
import
org.apache.atlas.typesystem.types.TypeSystem
;
import
org.apache.atlas.typesystem.types.TypeSystem
;
import
org.apache.atlas.typesystem.types.ValueConversionException
;
import
org.apache.atlas.typesystem.types.ValueConversionException
;
import
org.apache.atlas.utils.
MD5
Utils
;
import
org.apache.atlas.utils.
SHA256
Utils
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.math.BigInteger
;
...
@@ -774,7 +774,7 @@ public class StructInstance implements ITypedStruct {
...
@@ -774,7 +774,7 @@ public class StructInstance implements ITypedStruct {
StructType
structType
=
TypeSystem
.
getInstance
().
getDataType
(
StructType
.
class
,
getTypeName
());
StructType
structType
=
TypeSystem
.
getInstance
().
getDataType
(
StructType
.
class
,
getTypeName
());
structType
.
updateSignatureHash
(
digester
,
this
);
structType
.
updateSignatureHash
(
digester
,
this
);
byte
[]
digest
=
digester
.
digest
();
byte
[]
digest
=
digester
.
digest
();
return
MD5
Utils
.
toString
(
digest
);
return
SHA256
Utils
.
toString
(
digest
);
}
}
@Override
@Override
...
...
This diff is collapsed.
Click to expand it.
webapp/src/main/java/org/apache/atlas/web/filters/AtlasAuthenticationFilter.java
View file @
40d909ef
...
@@ -26,6 +26,7 @@ import org.apache.atlas.web.security.AtlasAuthenticationProvider;
...
@@ -26,6 +26,7 @@ import org.apache.atlas.web.security.AtlasAuthenticationProvider;
import
org.apache.atlas.web.util.Servlets
;
import
org.apache.atlas.web.util.Servlets
;
import
org.apache.commons.collections.iterators.IteratorEnumeration
;
import
org.apache.commons.collections.iterators.IteratorEnumeration
;
import
org.apache.commons.configuration.Configuration
;
import
org.apache.commons.configuration.Configuration
;
import
org.apache.commons.configuration.ConfigurationConverter
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.hadoop.security.SecurityUtil
;
import
org.apache.hadoop.security.SecurityUtil
;
import
org.apache.hadoop.security.UserGroupInformation
;
import
org.apache.hadoop.security.UserGroupInformation
;
...
@@ -74,6 +75,7 @@ import java.util.*;
...
@@ -74,6 +75,7 @@ import java.util.*;
import
java.util.regex.Matcher
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.regex.Pattern
;
/**
/**
* This enforces authentication as part of the filter before processing the request.
* This enforces authentication as part of the filter before processing the request.
* todo: Subclass of {@link org.apache.hadoop.security.authentication.server.AuthenticationFilter}.
* todo: Subclass of {@link org.apache.hadoop.security.authentication.server.AuthenticationFilter}.
...
@@ -90,7 +92,8 @@ public class AtlasAuthenticationFilter extends AuthenticationFilter {
...
@@ -90,7 +92,8 @@ public class AtlasAuthenticationFilter extends AuthenticationFilter {
private
boolean
isInitializedByTomcat
;
private
boolean
isInitializedByTomcat
;
private
Set
<
Pattern
>
browserUserAgents
;
private
Set
<
Pattern
>
browserUserAgents
;
private
boolean
supportKeyTabBrowserLogin
=
false
;
private
boolean
supportKeyTabBrowserLogin
=
false
;
private
Configuration
configuration
;
private
Properties
headerProperties
;
public
AtlasAuthenticationFilter
()
{
public
AtlasAuthenticationFilter
()
{
try
{
try
{
LOG
.
info
(
"AtlasAuthenticationFilter initialization started"
);
LOG
.
info
(
"AtlasAuthenticationFilter initialization started"
);
...
@@ -112,8 +115,16 @@ public class AtlasAuthenticationFilter extends AuthenticationFilter {
...
@@ -112,8 +115,16 @@ public class AtlasAuthenticationFilter extends AuthenticationFilter {
public
void
init
(
FilterConfig
filterConfig
)
throws
ServletException
{
public
void
init
(
FilterConfig
filterConfig
)
throws
ServletException
{
LOG
.
info
(
"AtlasAuthenticationFilter initialization started"
);
LOG
.
info
(
"AtlasAuthenticationFilter initialization started"
);
final
FilterConfig
globalConf
=
filterConfig
;
final
FilterConfig
globalConf
=
filterConfig
;
final
Map
<
String
,
String
>
params
=
new
HashMap
<>();
final
Map
<
String
,
String
>
params
=
new
HashMap
<>();
try
{
configuration
=
ApplicationProperties
.
get
();
}
catch
(
Exception
e
)
{
throw
new
ServletException
(
e
);
}
if
(
configuration
!=
null
)
{
headerProperties
=
ConfigurationConverter
.
getProperties
(
configuration
.
subset
(
"atlas.headers"
));
}
FilterConfig
filterConfig1
=
new
FilterConfig
()
{
FilterConfig
filterConfig1
=
new
FilterConfig
()
{
@Override
@Override
...
@@ -147,7 +158,6 @@ public class AtlasAuthenticationFilter extends AuthenticationFilter {
...
@@ -147,7 +158,6 @@ public class AtlasAuthenticationFilter extends AuthenticationFilter {
optionsServlet
=
new
HttpServlet
()
{
optionsServlet
=
new
HttpServlet
()
{
};
};
optionsServlet
.
init
();
optionsServlet
.
init
();
}
}
...
@@ -176,7 +186,6 @@ public class AtlasAuthenticationFilter extends AuthenticationFilter {
...
@@ -176,7 +186,6 @@ public class AtlasAuthenticationFilter extends AuthenticationFilter {
@Override
@Override
protected
Properties
getConfiguration
(
String
configPrefix
,
FilterConfig
filterConfig
)
throws
ServletException
{
protected
Properties
getConfiguration
(
String
configPrefix
,
FilterConfig
filterConfig
)
throws
ServletException
{
Configuration
configuration
;
try
{
try
{
configuration
=
ApplicationProperties
.
get
();
configuration
=
ApplicationProperties
.
get
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
@@ -308,10 +317,16 @@ public class AtlasAuthenticationFilter extends AuthenticationFilter {
...
@@ -308,10 +317,16 @@ public class AtlasAuthenticationFilter extends AuthenticationFilter {
try
{
try
{
Authentication
existingAuth
=
SecurityContextHolder
.
getContext
().
getAuthentication
();
Authentication
existingAuth
=
SecurityContextHolder
.
getContext
().
getAuthentication
();
HttpServletResponse
httpResponse
=
(
HttpServletResponse
)
response
;
HttpServletResponse
httpResponse
=
(
HttpServletResponse
)
response
;
AtlasResponseRequestWrapper
responseWrapper
=
new
AtlasResponseRequestWrapper
(
httpResponse
);
AtlasResponseRequestWrapper
responseWrapper
=
new
AtlasResponseRequestWrapper
(
httpResponse
);
responseWrapper
.
setHeader
(
"X-Frame-Options"
,
"DENY"
);
responseWrapper
.
setHeader
(
"X-Frame-Options"
,
"DENY"
);
if
(
headerProperties
!=
null
)
{
for
(
String
headerKey
:
headerProperties
.
stringPropertyNames
())
{
String
headerValue
=
headerProperties
.
getProperty
(
headerKey
);
responseWrapper
.
setHeader
(
headerKey
,
headerValue
);
}
}
if
(
existingAuth
==
null
)
{
if
(
existingAuth
==
null
)
{
String
authHeader
=
httpRequest
.
getHeader
(
"Authorization"
);
String
authHeader
=
httpRequest
.
getHeader
(
"Authorization"
);
if
(
authHeader
!=
null
&&
authHeader
.
startsWith
(
"Basic"
))
{
if
(
authHeader
!=
null
&&
authHeader
.
startsWith
(
"Basic"
))
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment