-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce universal/security library for AuthN and AuthZ (#1486)
commit-id:17aa4dbb
- Loading branch information
1 parent
d2cd33d
commit 3eda73e
Showing
37 changed files
with
2,224 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...iversal/src/main/java/com/pinterest/teletraan/universal/security/AnonymousAuthFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* Copyright (c) 2024 Pinterest, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.pinterest.teletraan.universal.security; | ||
|
||
import com.pinterest.teletraan.universal.security.bean.AnonymousUser; | ||
import java.io.IOException; | ||
import java.security.Principal; | ||
import javax.annotation.Priority; | ||
import javax.ws.rs.Priorities; | ||
import javax.ws.rs.container.ContainerRequestContext; | ||
import javax.ws.rs.container.ContainerRequestFilter; | ||
import javax.ws.rs.core.SecurityContext; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
/** | ||
* A filter for authenticating and authorizing any request as an anonymous user. For development use | ||
* only. | ||
*/ | ||
@Provider | ||
@Priority(Priorities.AUTHENTICATION) | ||
public class AnonymousAuthFilter implements ContainerRequestFilter { | ||
public static final AnonymousUser USER = new AnonymousUser(); | ||
private SecurityContext securityContext; | ||
|
||
public AnonymousAuthFilter() { | ||
securityContext = | ||
new SecurityContext() { | ||
|
||
@Override | ||
public Principal getUserPrincipal() { | ||
return AnonymousAuthFilter.USER; | ||
} | ||
|
||
@Override | ||
public boolean isUserInRole(String s) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isSecure() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public String getAuthenticationScheme() { | ||
return "Anonymous"; | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public void filter(ContainerRequestContext containerRequestContext) throws IOException { | ||
containerRequestContext.setSecurityContext(securityContext); | ||
} | ||
} |
Oops, something went wrong.